]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
various: make parse_env_file error handling the same in various places
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Mar 2022 17:45:52 +0000 (18:45 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 18 Mar 2022 22:26:59 +0000 (23:26 +0100)
No big reason to do this, except that I was looking at all call sites
and it's nicer if the same style is used accross the codebase.

src/libsystemd/sd-login/sd-login.c
src/locale/keymap-util.c
src/login/logind-session.c
src/machine/machine.c

index 00129ff77dacb9d679893d7e47a69bdd73344981..f134f0a8c98aadf94de69f3fda475282690e41a9 100644 (file)
@@ -269,13 +269,11 @@ _public_ int sd_uid_get_state(uid_t uid, char**state) {
                 return r;
 
         r = parse_env_file(NULL, p, "STATE", &s);
-        if (r == -ENOENT) {
+        if (r == -ENOENT)
                 r = free_and_strdup(&s, "offline");
-                if (r < 0)
-                        return r;
-        } else if (r < 0)
+        if (r < 0)
                 return r;
-        else if (isempty(s))
+        if (isempty(s))
                 return -EIO;
 
         *state = TAKE_PTR(s);
index 10d2ed7aece239295cd01ec72c6754bc38798646..9759f461631e8c6114e440a18d8ffca1b804dcc3 100644 (file)
@@ -157,7 +157,6 @@ int locale_read_data(Context *c, sd_bus_message *m) {
 int vconsole_read_data(Context *c, sd_bus_message *m) {
         struct stat st;
         usec_t t;
-        int r;
 
         /* Do not try to re-read the file within single bus operation. */
         if (m) {
@@ -185,13 +184,9 @@ int vconsole_read_data(Context *c, sd_bus_message *m) {
         c->vc_mtime = t;
         context_free_vconsole(c);
 
-        r = parse_env_file(NULL, "/etc/vconsole.conf",
-                           "KEYMAP",        &c->vc_keymap,
-                           "KEYMAP_TOGGLE", &c->vc_keymap_toggle);
-        if (r < 0)
-                return r;
-
-        return 0;
+        return parse_env_file(NULL, "/etc/vconsole.conf",
+                              "KEYMAP",        &c->vc_keymap,
+                              "KEYMAP_TOGGLE", &c->vc_keymap_toggle);
 }
 
 int x11_read_data(Context *c, sd_bus_message *m) {
index ab98a5055df017be37e70957845e32d228cbfbb2..eef48c252753bd2d5c8ed7b81421df59366b9f0d 100644 (file)
@@ -445,7 +445,6 @@ int session_load(Session *s) {
                            "ACTIVE",         &active,
                            "DEVICES",        &devices,
                            "IS_DISPLAY",     &is_display);
-
         if (r < 0)
                 return log_error_errno(r, "Failed to read %s: %m", s->state_file);
 
index 80f73da94a8bb496d60ea9d0f0b6c9dd8e740046..b202220b87937f81322375231b09968935e2426f 100644 (file)
@@ -265,12 +265,10 @@ int machine_load(Machine *m) {
                            "REALTIME",  &realtime,
                            "MONOTONIC", &monotonic,
                            "NETIF",     &netif);
-        if (r < 0) {
-                if (r == -ENOENT)
-                        return 0;
-
+        if (r == -ENOENT)
+                return 0;
+        if (r < 0)
                 return log_error_errno(r, "Failed to read %s: %m", m->state_file);
-        }
 
         if (id)
                 sd_id128_from_string(id, &m->id);