]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: fix error code propagation in run_generator()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 8 May 2023 10:47:17 +0000 (19:47 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 23 May 2023 23:23:22 +0000 (08:23 +0900)
Previously, some errors might be ignored.

src/fstab-generator/fstab-generator.c

index e88bc15a15b2a3233525d3341583d78b2f66f3ce..a2dc1a524d085cb67d9879d16caed89ac2ac6a8c 100644 (file)
@@ -1296,7 +1296,7 @@ static int determine_usr(void) {
  * with /sysroot/etc/fstab available, and then we can write additional units based
  * on that file. */
 static int run_generator(void) {
-        int r, r2 = 0, r3 = 0;
+        int r, ret = 0;
 
         r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
         if (r < 0)
@@ -1317,26 +1317,39 @@ static int run_generator(void) {
         /* Always honour root= and usr= in the kernel command line if we are in an initrd */
         if (in_initrd()) {
                 r = add_sysroot_mount();
+                if (r < 0 && ret >= 0)
+                        ret = r;
 
-                r2 = add_sysroot_usr_mount_or_fallback();
+                r = add_sysroot_usr_mount_or_fallback();
+                if (r < 0 && ret >= 0)
+                        ret = r;
 
-                r3 = add_volatile_root();
-        } else
+                r = add_volatile_root();
+                if (r < 0 && ret >= 0)
+                        ret = r;
+        } else {
                 r = add_volatile_var();
+                if (r < 0 && ret >= 0)
+                        ret = r;
+        }
 
         /* Honour /etc/fstab only when that's enabled */
         if (arg_fstab_enabled) {
                 /* Parse the local /etc/fstab, possibly from the initrd */
-                r2 = parse_fstab(false);
+                r = parse_fstab(false);
+                if (r < 0 && ret >= 0)
+                        ret = r;
 
                 /* If running in the initrd also parse the /etc/fstab from the host */
                 if (in_initrd())
-                        r3 = parse_fstab(true);
+                        r = parse_fstab(true);
                 else
-                        r3 = generator_enable_remount_fs_service(arg_dest);
+                        r = generator_enable_remount_fs_service(arg_dest);
+                if (r < 0 && ret >= 0)
+                        ret = r;
         }
 
-        return r < 0 ? r : r2 < 0 ? r2 : r3;
+        return ret;
 }
 
 static int run(int argc, char **argv) {