[systemd-devel] [PATCH 2/3] Allow $SYSTEMD_PRETEND_INITRD to override initramfs detection
Zbigniew Jędrzejewski-Szmek
zbyszek at in.waw.pl
Sat May 2 10:16:58 PDT 2015
When testing generators and other utilities, it is extremely useful
to be able to trigger initramfs behaviour.
We already allow $SYSTEMD_UNIT_PATH to modify systemd behaviour, this
follows the same principle.
---
src/shared/util.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/shared/util.c b/src/shared/util.c
index 2c7254eeda..b110909e30 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3734,23 +3734,29 @@ bool documentation_url_is_valid(const char *url) {
bool in_initrd(void) {
static int saved = -1;
struct statfs s;
+ const char *e;
if (saved >= 0)
return saved;
- /* We make two checks here:
+ /* We make three checks here:
*
- * 1. the flag file /etc/initrd-release must exist
- * 2. the root file system must be a memory file system
+ * 0. First check for SYSTEMD_PRETEND_INITRD.
+ * 1. The flag file /etc/initrd-release must exist
+ * 2. The root file system must be a memory file system
*
* The second check is extra paranoia, since misdetecting an
* initrd can have bad bad consequences due the initrd
* emptying when transititioning to the main systemd.
*/
- saved = access("/etc/initrd-release", F_OK) >= 0 &&
- statfs("/", &s) >= 0 &&
- is_temporary_fs(&s);
+ e = getenv("SYSTEMD_PRETEND_INITRD");
+ if (e && parse_boolean(e) > 0)
+ saved = true;
+ else
+ saved = access("/etc/initrd-release", F_OK) >= 0 &&
+ statfs("/", &s) >= 0 &&
+ is_temporary_fs(&s);
return saved;
}
--
2.3.5
More information about the systemd-devel
mailing list