]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: read both credentials in initrd
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 Jul 2023 19:25:57 +0000 (04:25 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 26 Jul 2023 15:50:15 +0000 (00:50 +0900)
This makes the behavior consistent with the way we already do for
fstab and command line options.
In initrd, entries read from fstab.extra are mounted under /sysroot.

src/fstab-generator/fstab-generator.c

index 4bb727c0bbe961b3627b07343ef63904da978d5c..e414529ed8664b66c898a655c782967c5f6bfb6d 100644 (file)
@@ -1309,14 +1309,16 @@ static int add_mounts_from_cmdline(void) {
         return ret;
 }
 
-static int add_mounts_from_creds(void) {
+static int add_mounts_from_creds(bool prefix_sysroot) {
         _cleanup_free_ void *b = NULL;
         struct mntent *me;
         int r, ret = 0;
         size_t bs;
 
+        assert(in_initrd() || !prefix_sysroot);
+
         r = read_credential_with_decryption(
-                        in_initrd() ? "fstab.extra.initrd" : "fstab.extra",
+                        in_initrd() && !prefix_sysroot ? "fstab.extra.initrd" : "fstab.extra",
                         &b, &bs);
         if (r <= 0)
                 return r;
@@ -1334,7 +1336,7 @@ static int add_mounts_from_creds(void) {
                                 me->mnt_type,
                                 me->mnt_opts,
                                 me->mnt_passno,
-                                /* prefix_sysroot = */ false,
+                                /* prefix_sysroot = */ prefix_sysroot,
                                 /* use_swap_enabled = */ true);
                 if (r < 0 && ret >= 0)
                         ret = r;
@@ -1575,10 +1577,16 @@ static int run_generator(void) {
         if (r < 0 && ret >= 0)
                 ret = r;
 
-        r = add_mounts_from_creds();
+        r = add_mounts_from_creds(/* prefix_sysroot = */ false);
         if (r < 0 && ret >= 0)
                 ret = r;
 
+        if (in_initrd()) {
+                r = add_mounts_from_creds(/* prefix_sysroot = */ true);
+                if (r < 0 && ret >= 0)
+                        ret = r;
+        }
+
         return ret;
 }