From caf20af422a7fc14c0d6eaa9cc330066b447a968 Mon Sep 17 00:00:00 2001 From: Miciah Masters Date: Sat, 24 Dec 2016 03:08:17 -0500 Subject: Set dev_name to default device name If no device is specified with the --device flag, set dev_name to the id of the first device. Before, if the --device flag is not used to specify the default device, the dev pointer was set to first device found (see commit c9140d1e5070dae2746d3b70c0390075bd5380f6), but the dev_name pointer was left set to NULL. As a result, some error messages did not print the name of the default device: % brightnessctl -s Error saving device data: No such file or directory Could not save data for device '(null)'. Device 'intel_backlight' of class 'backlight': Current brightness: 1000 (20%) Max brightness: 4794 % brightnessctl -s -m Error saving device data: No such file or directory Could not save data for device '(null)'. intel_backlight,backlight,1000,20%,4794 % After this commit, all error messages have the correct name: % brightnessctl -s Error saving device data: No such file or directory Could not save data for device 'intel_backlight'. Device 'intel_backlight' of class 'backlight': Current brightness: 1000 (20%) Max brightness: 4794 % brightnessctl -s -m Error saving device data: No such file or directory Could not save data for device 'intel_backlight'. intel_backlight,backlight,1000,20%,4794 % --- brightnessctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'brightnessctl.c') diff --git a/brightnessctl.c b/brightnessctl.c index 60ca3a4..d6170e9 100644 --- a/brightnessctl.c +++ b/brightnessctl.c @@ -151,6 +151,8 @@ int main(int argc, char **argv) { return list_devices(devs); } dev_name = p.device; + if (!dev_name) + dev_name = devs[0]->id; if (argc == 0) p.operation = GET; else switch (argv[0][0]) { @@ -242,8 +244,6 @@ int parse_value(struct value *val, char *str) { struct device *find_device(struct device **devs, char *name) { struct device *dev; - if (!name) - return *devs; while ((dev = *(devs++))) if (!strcmp(dev->id, name)) return dev; -- cgit v1.2.3