Add $SYSTEMD_IN_INITRD=yes|no override for debugging

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-09-26 07:15:55 +02:00
parent 12580bc3ed
commit 0307ea49c7
2 changed files with 16 additions and 3 deletions

View File

@ -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

View File

@ -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;
}