summaryrefslogtreecommitdiff
path: root/src/backlight
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-03-23 15:20:34 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-03-23 15:20:34 +0100
commit3e44d24d3b5e7041ce3961b7f159e3ebb27569eb (patch)
tree5e3ab67e1e0cb714d0f3059c080a3d2866ff882e /src/backlight
parent4ddc526ce870db89b4c06781efbb820e6da402ff (diff)
downloadsystemd-3e44d24d3b5e7041ce3961b7f159e3ebb27569eb.tar.gz
backlight: minor modernizations (#8528)
Use strjoina() and STR_IN_SET()
Diffstat (limited to 'src/backlight')
-rw-r--r--src/backlight/backlight.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c
index 8fedf8ebbc..2b19bfe0a0 100644
--- a/src/backlight/backlight.c
+++ b/src/backlight/backlight.c
@@ -234,9 +234,9 @@ static unsigned get_max_brightness(struct udev_device *device) {
* an unreadably dim screen, which would otherwise force the user to
* disable state restoration. */
static void clamp_brightness(struct udev_device *device, char **value, unsigned max_brightness) {
- int r;
unsigned brightness, new_brightness, min_brightness;
const char *subsystem;
+ int r;
r = safe_atou(*value, &brightness);
if (r < 0) {
@@ -272,8 +272,8 @@ static void clamp_brightness(struct udev_device *device, char **value, unsigned
int main(int argc, char *argv[]) {
_cleanup_udev_unref_ struct udev *udev = NULL;
_cleanup_udev_device_unref_ struct udev_device *device = NULL;
- _cleanup_free_ char *saved = NULL, *ss = NULL, *escaped_ss = NULL, *escaped_sysname = NULL, *escaped_path_id = NULL;
- const char *sysname, *path_id;
+ _cleanup_free_ char *escaped_ss = NULL, *escaped_sysname = NULL, *escaped_path_id = NULL;
+ const char *sysname, *path_id, *ss, *saved;
unsigned max_brightness;
int r;
@@ -306,15 +306,11 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
- ss = strndup(argv[2], sysname - argv[2]);
- if (!ss) {
- log_oom();
- return EXIT_FAILURE;
- }
+ ss = strndupa(argv[2], sysname - argv[2]);
sysname++;
- if (!streq(ss, "backlight") && !streq(ss, "leds")) {
+ if (!STR_IN_SET(ss, "backlight", "leds")) {
log_error("Not a backlight or LED device: '%s:%s'", ss, sysname);
return EXIT_FAILURE;
}
@@ -358,14 +354,9 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
- saved = strjoin("/var/lib/systemd/backlight/", escaped_path_id, ":", escaped_ss, ":", escaped_sysname);
+ saved = strjoina("/var/lib/systemd/backlight/", escaped_path_id, ":", escaped_ss, ":", escaped_sysname);
} else
- saved = strjoin("/var/lib/systemd/backlight/", escaped_ss, ":", escaped_sysname);
-
- if (!saved) {
- log_oom();
- return EXIT_FAILURE;
- }
+ saved = strjoina("/var/lib/systemd/backlight/", escaped_ss, ":", escaped_sysname);
/* If there are multiple conflicting backlight devices, then
* their probing at boot-time might happen in any order. This