Added udev rule and init.d script for allowing users of video group to control backlight
This commit is contained in:
parent
3cb653fdd2
commit
33cf717cd3
1
TODO
1
TODO
@ -1,3 +1,4 @@
|
|||||||
Individual device control
|
Individual device control
|
||||||
|
List devices
|
||||||
Query backlight percentage (get)
|
Query backlight percentage (get)
|
||||||
allow fade in and fade out
|
allow fade in and fade out
|
||||||
|
|||||||
11
makefile
11
makefile
@ -1,16 +1,21 @@
|
|||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: rexbacklight
|
all: rexbacklight
|
||||||
|
|
||||||
rexbacklight: rexbacklight.c
|
rexbacklight: src/rexbacklight.c
|
||||||
gcc -std=c11 -O2 -Wall -Wextra -pedantic rexbacklight.c -o rexbacklight
|
gcc -std=c11 -O2 -Wall -Wextra -pedantic src/rexbacklight.c -o rexbacklight
|
||||||
strip --strip-all rexbacklight
|
strip --strip-all rexbacklight
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
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
|
.PHONY: uninstall
|
||||||
|
uninstall:
|
||||||
rm /usr/bin/rexbacklight
|
rm /usr/bin/rexbacklight
|
||||||
|
rm /etc/udev/rules.d/91-backlight.rules
|
||||||
|
rm /etc/init.d/backlight
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm rexbacklight
|
rm rexbacklight
|
||||||
|
|||||||
3
rules/91-backlight.rules
Normal file
3
rules/91-backlight.rules
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
SUBSYSTEM=="backlight", ACTION=="add", \
|
||||||
|
RUN+="/bin/chgrp video %S%p/brightness", \
|
||||||
|
RUN+="/bin/chmod g+w %S%p/brightness"
|
||||||
13
rules/backlight
Executable file
13
rules/backlight
Executable file
@ -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}
|
||||||
|
}
|
||||||
@ -48,27 +48,6 @@ void usage(int exit_val){
|
|||||||
exit(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{
|
struct string_array{
|
||||||
char** list;
|
char** list;
|
||||||
int size;
|
int size;
|
||||||
@ -185,21 +164,6 @@ int main(int argc, char** argv){
|
|||||||
else if(strlen(argv[1]) < 2)
|
else if(strlen(argv[1]) < 2)
|
||||||
usage(-1);
|
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
|
//Acquire a list of backlight devices in sysfs
|
||||||
struct string_array backlight_names = get_backlight_sources();
|
struct string_array backlight_names = get_backlight_sources();
|
||||||
if(backlight_names.size == 0){
|
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));
|
int out = process_arg(argv[1], 0, get_brightness(backlight_file), get_brightness(max_backlight_file));
|
||||||
FILE* bright = fopen(backlight_file, "w+");
|
FILE* bright = fopen(backlight_file, "w+");
|
||||||
if(!bright){
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
fprintf(bright, "%d", out);
|
fprintf(bright, "%d", out);
|
||||||
Loading…
x
Reference in New Issue
Block a user