diff --git a/TODO b/TODO index 6fec1b4..7c300f0 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,4 @@ Individual device control +List devices Query backlight percentage (get) allow fade in and fade out diff --git a/makefile b/makefile index f1706cf..3e6aebe 100644 --- a/makefile +++ b/makefile @@ -1,16 +1,21 @@ .PHONY: all all: rexbacklight -rexbacklight: rexbacklight.c - gcc -std=c11 -O2 -Wall -Wextra -pedantic rexbacklight.c -o rexbacklight +rexbacklight: src/rexbacklight.c + gcc -std=c11 -O2 -Wall -Wextra -pedantic src/rexbacklight.c -o rexbacklight strip --strip-all rexbacklight .PHONY: install install: - install -m4711 -o root -g root -s rexbacklight /usr/bin/rexbacklight + install -m755 -o root -g root -s rexbacklight /usr/bin/rexbacklight + install -m600 -o root -g root rules/91-backlight.rules /etc/udev/rules.d/91-backlight.rules + install -m755 -o root -g root rules/backlight /etc/init.d/backlight .PHONY: uninstall +uninstall: rm /usr/bin/rexbacklight + rm /etc/udev/rules.d/91-backlight.rules + rm /etc/init.d/backlight .PHONY: clean clean: rm rexbacklight diff --git a/rules/91-backlight.rules b/rules/91-backlight.rules new file mode 100644 index 0000000..ce2044b --- /dev/null +++ b/rules/91-backlight.rules @@ -0,0 +1,3 @@ +SUBSYSTEM=="backlight", ACTION=="add", \ + RUN+="/bin/chgrp video %S%p/brightness", \ + RUN+="/bin/chmod g+w %S%p/brightness" diff --git a/rules/backlight b/rules/backlight new file mode 100755 index 0000000..537bfc6 --- /dev/null +++ b/rules/backlight @@ -0,0 +1,13 @@ +#!/sbin/openrc-run +#Copyright (C) 2018 rexy712 + +start() { + ebegin "Forcing intel_backlight to work correctly" + /bin/chgrp video /sys/class/backlight/intel_backlight/brightness + /bin/chmod g+w /sys/class/backlight/intel_backlight/brightness + eend $? +} + +stop() { + eend ${ret} +} diff --git a/rexbacklight.c b/src/rexbacklight.c similarity index 84% rename from rexbacklight.c rename to src/rexbacklight.c index 83f28db..4bde55f 100644 --- a/rexbacklight.c +++ b/src/rexbacklight.c @@ -48,27 +48,6 @@ void usage(int exit_val){ exit(exit_val); } -int check_valid_files(const char* f1, const char* f2){ - struct stat file1, file2; - if(stat(f1, &file1)){ - printf("failed to open '%s'\n", f1); - return -1; - } - if(stat(f2, &file2)){ - printf("failed to open '%s'\n", f2); - return -1; - } - //Same device and same inode means same file - - //device id - if(file1.st_dev != file2.st_dev) - return -2; - //inode number - if(file1.st_ino != file2.st_ino) - return -2; - return 0; -} - struct string_array{ char** list; int size; @@ -185,21 +164,6 @@ int main(int argc, char** argv){ else if(strlen(argv[1]) < 2) usage(-1); - //Gain access to sysfs files - if(setuid(0)){ - fprintf(stderr, "Unable to setuid to 0!\n"); - return -3; - } - - //Make sure we aren't in a chroot environment (prevents writing to a file we don't want to!) - if(check_valid_files("/", "/proc/1/root")){ - fprintf(stderr, "No chroot today\n"); - return -4; - } - - //Now that we've verified we're in a safe environment to do the work, - //Let's get everything set up! - //Acquire a list of backlight devices in sysfs struct string_array backlight_names = get_backlight_sources(); if(backlight_names.size == 0){ @@ -226,7 +190,7 @@ int main(int argc, char** argv){ int out = process_arg(argv[1], 0, get_brightness(backlight_file), get_brightness(max_backlight_file)); FILE* bright = fopen(backlight_file, "w+"); if(!bright){ - fprintf(stderr, "Unable to open brightness file \"%s\" for writing!\n", backlight_file); + fprintf(stderr, "Unable to open brightness file \"%s%s\" for writing!\n", backlight_dir, backlight_file); continue; } fprintf(bright, "%d", out);