aboutsummaryrefslogtreecommitdiff
path: root/brightnessctl.c
diff options
context:
space:
mode:
authorGravatar Mykyta Holubakha <hilobakho@gmail.com>2017-01-17 01:30:15 +0200
committerGravatar Mykyta Holubakha <hilobakho@gmail.com>2017-01-17 01:30:15 +0200
commitb287e2315f14446bfac5cb03510a566e78af21f1 (patch)
tree63a7908e3cf20d615853ce209b9b425b8d752a44 /brightnessctl.c
parentfdb444e33ab2b731ae791192bac7a61a93d042f6 (diff)
No longer require root privileges
Diffstat (limited to 'brightnessctl.c')
-rw-r--r--brightnessctl.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/brightnessctl.c b/brightnessctl.c
index 1d43a2a..49834f7 100644
--- a/brightnessctl.c
+++ b/brightnessctl.c
@@ -93,7 +93,7 @@ int main(int argc, char **argv) {
struct device *devs[255];
struct device *dev;
struct utsname name;
- char *dev_name;
+ char *dev_name, *file_path;
int n, c, phelp = 0;
if (uname(&name))
fail("Unable to determine current OS. Exiting!\n");
@@ -173,8 +173,16 @@ int main(int argc, char **argv) {
fail("Invalid value given");
if (!(dev = find_device(devs, dev_name)))
fail("Device '%s' not found.\n", dev_name);
- if ((p.operation == SET || p.restore) && !p.pretend && geteuid())
- fail("You need to run this program as root to be able to modify values!\n");
+ if ((p.operation == SET || p.restore) && !p.pretend && geteuid()) {
+ errno = 0;
+ file_path = cat_with('/', path, dev->class, dev->id, "brightness");
+ if (access(file_path, W_OK)) {
+ perror("Can't modify brightness");
+ fail("\nYou should run this program with root privileges.\n"
+ "Alternatively, get write permissions for device files.\n");
+ }
+ free(file_path);
+ }
if (p.save)
if (save_device_data(dev))
fprintf(stderr, "Could not save data for device '%s'.\n", dev_name);