]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: simplify return code generation
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 20 Dec 2018 11:18:29 +0000 (12:18 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 3 Jan 2019 14:30:28 +0000 (15:30 +0100)
We just do a bunch of operations, and want to return the first failing error
code. Let's do this in the most straightforward way.

src/fstab-generator/fstab-generator.c

index 9318d1e59198ded5784959216d6e7cab549ced06..cebfed25cb290fe6028121d4f6d456f5b151d7c5 100644 (file)
@@ -861,7 +861,7 @@ static int determine_root(void) {
 }
 
 static int run(const char *dest, const char *dest_early, const char *dest_late) {
-        int r;
+        int r, r2 = 0, r3 = 0;
 
         assert_se(arg_dest = dest);
         assert_se(arg_dest_late = dest_late);
@@ -874,38 +874,25 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
 
         /* Always honour root= and usr= in the kernel command line if we are in an initrd */
         if (in_initrd()) {
-                int k;
-
                 r = add_sysroot_mount();
 
-                k = add_sysroot_usr_mount();
-                if (k < 0)
-                        r = k;
+                r2 = add_sysroot_usr_mount();
 
-                k = add_volatile_root();
-                if (k < 0)
-                        r = k;
+                r3 = add_volatile_root();
         } else
                 r = add_volatile_var();
 
         /* Honour /etc/fstab only when that's enabled */
         if (arg_fstab_enabled) {
-                int k;
-
                 /* Parse the local /etc/fstab, possibly from the initrd */
-                k = parse_fstab(false);
-                if (k < 0)
-                        r = k;
+                r2 = parse_fstab(false);
 
                 /* If running in the initrd also parse the /etc/fstab from the host */
-                if (in_initrd()) {
-                        k = parse_fstab(true);
-                        if (k < 0)
-                                r = k;
-                }
+                if (in_initrd())
+                        r3 = parse_fstab(true);
         }
 
-        return r;
+        return r < 0 ? r : r2 < 0 ? r2 : r3;
 }
 
 DEFINE_MAIN_GENERATOR_FUNCTION(run);