From: Yu Watanabe Date: Tue, 25 Jul 2023 19:25:57 +0000 (+0900) Subject: fstab-generator: read both credentials in initrd X-Git-Tag: v254~8^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfd10549ac5aec1379ee83d633aadd1296450dac;p=thirdparty%2Fsystemd.git fstab-generator: read both credentials in initrd 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. --- diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 4bb727c0bbe..e414529ed86 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -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; }