summaryrefslogtreecommitdiff
path: root/src/backlight
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-04-01 10:19:07 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-04-01 12:01:58 +0200
commitc03916164d08f5eb8e24daa21a9e29871bdfe2ac (patch)
tree3f7751a8d96b9b8e82112167d4d52f38beb218b9 /src/backlight
parent0246f42980ed87dfca79fd4a8ec67a81d824e427 (diff)
downloadsystemd-c03916164d08f5eb8e24daa21a9e29871bdfe2ac.tar.gz
backlight: refactor get_max_brightness() to appease gcc
The old code was just fine, but gcc doesn't understand that max_brightness is initialized. Let's rework it a bit to move some logic to the main function. Now get_max_brightness() just retrieves and parses the attribute, and the main function decides what to do with it.
Diffstat (limited to 'src/backlight')
-rw-r--r--src/backlight/backlight.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c
index 86927be62e..7c0970a60c 100644
--- a/src/backlight/backlight.c
+++ b/src/backlight/backlight.c
@@ -226,26 +226,20 @@ static int validate_device(sd_device *device) {
}
static int get_max_brightness(sd_device *device, unsigned *ret) {
- const char *max_brightness_str;
- unsigned max_brightness;
+ const char *s;
int r;
assert(device);
assert(ret);
- r = sd_device_get_sysattr_value(device, "max_brightness", &max_brightness_str);
+ r = sd_device_get_sysattr_value(device, "max_brightness", &s);
if (r < 0)
return log_device_warning_errno(device, r, "Failed to read 'max_brightness' attribute: %m");
- r = safe_atou(max_brightness_str, &max_brightness);
+ r = safe_atou(s, ret);
if (r < 0)
- return log_device_warning_errno(device, r, "Failed to parse 'max_brightness' \"%s\": %m", max_brightness_str);
-
- if (max_brightness <= 0)
- return log_device_warning_errno(device, SYNTHETIC_ERRNO(EINVAL), "Maximum brightness is 0, ignoring device.");
+ return log_device_warning_errno(device, r, "Failed to parse 'max_brightness' \"%s\": %m", s);
- log_device_debug(device, "Maximum brightness is %u", max_brightness);
- *ret = max_brightness;
return 0;
}
@@ -409,6 +403,13 @@ static int run(int argc, char *argv[]) {
if (get_max_brightness(device, &max_brightness) < 0)
return 0;
+ if (max_brightness == 0) {
+ log_device_warning(device, "Maximum brightness is 0, ignoring device.");
+ return 0;
+ }
+
+ log_device_debug(device, "Maximum brightness is %u", max_brightness);
+
escaped_ss = cescape(ss);
if (!escaped_ss)
return log_oom();