Skip to content

Instantly share code, notes, and snippets.

@scotchi
Created December 13, 2016 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scotchi/0027e2ff04c234f67e54ea98afd3e159 to your computer and use it in GitHub Desktop.
Save scotchi/0027e2ff04c234f67e54ea98afd3e159 to your computer and use it in GitHub Desktop.
Little tool to run setuid that can be called from ~/.xinitrc
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
int main(int argc, const char *argv[])
{
if(geteuid() != 0)
{
fprintf(stderr, "This program should be setuid or run as root.\n");
return 1;
}
if(argc != 2)
{
return 2;
}
int value = atoi(argv[1]);
if(value < 0 || value > 63)
{
fprintf(stderr, "Value is out of range.\n");
return 3;
}
FILE *param_file = fopen("/sys/module/hid_magicmouse/parameters/scroll_speed", "w");
if(!param_file)
{
fprintf(stderr, "Magic Mouse not connected.\n");
return 4;
}
if(fprintf(param_file, "%i\n", value) <= 0)
{
fprintf(stderr, "Couldn't write parameter.\n");
fclose(param_file);
return 5;
}
fclose(param_file);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment