]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: unify initrd-root-device.target dependency handling code
authorLily Foster <lily@lily.flowers>
Thu, 6 Jul 2023 20:13:53 +0000 (16:13 -0400)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 7 Jul 2023 02:58:43 +0000 (11:58 +0900)
This fixes a bug from #26038 where it would actually write generator
stuff during sysroot check when it was only supposed to check for daemon
reload.

src/fstab-generator/fstab-generator.c

index cdcbb0deec8e266e954cc503fbc8127be032af06..b39d93195ab8ca80ab85728a2769a23a703576e3 100644 (file)
@@ -607,6 +607,12 @@ static int add_mount(
         if (r < 0)
                 return r;
 
+        if (in_initrd() && path_equal(where, "/sysroot") && is_device_path(what)) {
+                r = generator_write_initrd_root_device_deps(dest, what);
+                if (r < 0)
+                        return r;
+        }
+
         r = write_mount_timeout(f, where, opts);
         if (r < 0)
                 return r;
@@ -897,12 +903,6 @@ static int parse_fstab_one(
                         mount_is_network(fstype, options) ? SPECIAL_REMOTE_FS_TARGET :
                                                             SPECIAL_LOCAL_FS_TARGET;
 
-        if (is_sysroot && is_device_path(what)) {
-                r = generator_write_initrd_root_device_deps(arg_dest, what);
-                if (r < 0)
-                        return r;
-        }
-
         r = add_mount(source,
                       arg_dest,
                       what,
@@ -1090,12 +1090,6 @@ static int add_sysroot_mount(void) {
 
         log_debug("Found entry what=%s where=/sysroot type=%s opts=%s", what, strna(arg_root_fstype), strempty(opts));
 
-        if (is_device_path(what)) {
-                r = generator_write_initrd_root_device_deps(arg_dest, what);
-                if (r < 0)
-                        return r;
-        }
-
         makefs = fstab_test_option(opts, "x-systemd.makefs\0");
         flags = makefs * MOUNT_MAKEFS;