Skip to content

Commit

Permalink
Add $SYSTEMD_IN_INITRD=yes|no override for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
keszybz committed Oct 8, 2018
1 parent 12580bc commit 0307ea4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/basic/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 0307ea4

Please sign in to comment.