From: Zbigniew Jędrzejewski-Szmek Date: Wed, 26 Sep 2018 05:15:55 +0000 (+0200) Subject: Add $SYSTEMD_IN_INITRD=yes|no override for debugging X-Git-Tag: v240~611^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0307ea49c70b1ed4f3af3c80566c8c098dc080bb;p=thirdparty%2Fsystemd.git Add $SYSTEMD_IN_INITRD=yes|no override for debugging --- diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md index 9d598a66931..ec804c9c858 100644 --- a/docs/ENVIRONMENT.md +++ b/docs/ENVIRONMENT.md @@ -37,6 +37,10 @@ All tools: useful for debugging, in order to test generators and other code against specific kernel command lines. +* `$SYSTEMD_IN_INITRD` — takes a boolean. If set, overrides initrd detection. + This is useful for debugging and testing initrd-only programs in the main + system. + * `$SYSTEMD_BUS_TIMEOUT=SECS` — specifies the maximum time to wait for method call completion. If no time unit is specified, assumes seconds. The usual other units are understood, too (us, ms, s, min, h, d, w, month, y). If it is not set or set diff --git a/src/basic/util.c b/src/basic/util.c index 081c63c898c..0da963f4af8 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -23,6 +23,7 @@ #include "def.h" #include "device-nodes.h" #include "dirent-util.h" +#include "env-util.h" #include "fd-util.h" #include "fileio.h" #include "format-util.h" @@ -106,6 +107,7 @@ int prot_from_flags(int flags) { bool in_initrd(void) { struct statfs s; + int r; if (saved_in_initrd >= 0) return saved_in_initrd; @@ -120,9 +122,16 @@ bool in_initrd(void) { * emptying when transititioning to the main systemd. */ - saved_in_initrd = access("/etc/initrd-release", F_OK) >= 0 && - statfs("/", &s) >= 0 && - is_temporary_fs(&s); + r = getenv_bool_secure("SYSTEMD_IN_INITRD"); + if (r < 0 && r != -ENXIO) + log_debug_errno(r, "Failed to parse $SYSTEMD_IN_INITRD, ignoring: %m"); + + if (r >= 0) + saved_in_initrd = r > 0; + else + saved_in_initrd = access("/etc/initrd-release", F_OK) >= 0 && + statfs("/", &s) >= 0 && + is_temporary_fs(&s); return saved_in_initrd; }