From b287e2315f14446bfac5cb03510a566e78af21f1 Mon Sep 17 00:00:00 2001 From: Mykyta Holubakha Date: Tue, 17 Jan 2017 01:30:15 +0200 Subject: No longer require root privileges --- brightnessctl.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'brightnessctl.c') 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); -- cgit v1.2.3