|
|
ac3a84 |
From 94f9a80db599dcc298f3058e5cf2bb60c4972228 Mon Sep 17 00:00:00 2001
|
|
|
ac3a84 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
ac3a84 |
Date: Thu, 24 Nov 2022 13:58:39 +0100
|
|
|
ac3a84 |
Subject: [PATCH] Revert "initrd: extend SYSTEMD_IN_INITRD to accept non-ramfs
|
|
|
ac3a84 |
rootfs"
|
|
|
ac3a84 |
|
|
|
ac3a84 |
This reverts commit 1f22621ba33f8089d2ae5fbcaf8b3970dd68aaf0.
|
|
|
ac3a84 |
|
|
|
ac3a84 |
This is a replacement for b1fd5cd4eda02a323db93d7daa97f5138f89677d. See that
|
|
|
ac3a84 |
commit for details.
|
|
|
ac3a84 |
|
|
|
ac3a84 |
Related: #2138081
|
|
|
ac3a84 |
---
|
|
|
ac3a84 |
docs/ENVIRONMENT.md | 10 +++-------
|
|
|
ac3a84 |
src/basic/util.c | 47 ++++++++-------------------------------------
|
|
|
ac3a84 |
2 files changed, 11 insertions(+), 46 deletions(-)
|
|
|
ac3a84 |
|
|
|
ac3a84 |
diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md
|
|
|
ac3a84 |
index a840dd0c90..ab3add6031 100644
|
|
|
ac3a84 |
--- a/docs/ENVIRONMENT.md
|
|
|
ac3a84 |
+++ b/docs/ENVIRONMENT.md
|
|
|
ac3a84 |
@@ -73,13 +73,9 @@ All tools:
|
|
|
ac3a84 |
(relevant in particular for the system manager and `systemd-hostnamed`).
|
|
|
ac3a84 |
Must be a valid hostname (either a single label or a FQDN).
|
|
|
ac3a84 |
|
|
|
ac3a84 |
-* `$SYSTEMD_IN_INITRD=[auto|lenient|0|1]` — if set, specifies initrd detection
|
|
|
ac3a84 |
- method. Defaults to `auto`. Behavior is defined as follows:
|
|
|
ac3a84 |
- `auto`: Checks if `/etc/initrd-release` exists, and a temporary fs is mounted
|
|
|
ac3a84 |
- on `/`. If both conditions meet, then it's in initrd.
|
|
|
ac3a84 |
- `lenient`: Similar to `auto`, but the rootfs check is skipped.
|
|
|
ac3a84 |
- `0|1`: Simply overrides initrd detection. This is useful for debugging and
|
|
|
ac3a84 |
- testing initrd-only programs in the main system.
|
|
|
ac3a84 |
+* `$SYSTEMD_IN_INITRD` — takes a boolean. If set, overrides initrd detection.
|
|
|
ac3a84 |
+ This is useful for debugging and testing initrd-only programs in the main
|
|
|
ac3a84 |
+ system.
|
|
|
ac3a84 |
|
|
|
ac3a84 |
* `$SYSTEMD_BUS_TIMEOUT=SECS` — specifies the maximum time to wait for method call
|
|
|
ac3a84 |
completion. If no time unit is specified, assumes seconds. The usual other units
|
|
|
ac3a84 |
diff --git a/src/basic/util.c b/src/basic/util.c
|
|
|
ac3a84 |
index d7ef382737..981f917fab 100644
|
|
|
ac3a84 |
--- a/src/basic/util.c
|
|
|
ac3a84 |
+++ b/src/basic/util.c
|
|
|
ac3a84 |
@@ -52,13 +52,11 @@ int prot_from_flags(int flags) {
|
|
|
ac3a84 |
|
|
|
ac3a84 |
bool in_initrd(void) {
|
|
|
ac3a84 |
int r;
|
|
|
ac3a84 |
- const char *e;
|
|
|
ac3a84 |
- bool lenient = false;
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (saved_in_initrd >= 0)
|
|
|
ac3a84 |
return saved_in_initrd;
|
|
|
ac3a84 |
|
|
|
ac3a84 |
- /* We have two checks here:
|
|
|
ac3a84 |
+ /* We make two checks here:
|
|
|
ac3a84 |
*
|
|
|
ac3a84 |
* 1. the flag file /etc/initrd-release must exist
|
|
|
ac3a84 |
* 2. the root file system must be a memory file system
|
|
|
ac3a84 |
@@ -66,46 +64,17 @@ bool in_initrd(void) {
|
|
|
ac3a84 |
* The second check is extra paranoia, since misdetecting an
|
|
|
ac3a84 |
* initrd can have bad consequences due the initrd
|
|
|
ac3a84 |
* emptying when transititioning to the main systemd.
|
|
|
ac3a84 |
- *
|
|
|
ac3a84 |
- * If env var $SYSTEMD_IN_INITRD is not set or set to "auto",
|
|
|
ac3a84 |
- * both checks are used. If it's set to "lenient", only check
|
|
|
ac3a84 |
- * 1 is used. If set to a boolean value, then the boolean
|
|
|
ac3a84 |
- * value is returned.
|
|
|
ac3a84 |
*/
|
|
|
ac3a84 |
|
|
|
ac3a84 |
- e = secure_getenv("SYSTEMD_IN_INITRD");
|
|
|
ac3a84 |
- if (e) {
|
|
|
ac3a84 |
- if (streq(e, "lenient"))
|
|
|
ac3a84 |
- lenient = true;
|
|
|
ac3a84 |
- else if (!streq(e, "auto")) {
|
|
|
ac3a84 |
- r = parse_boolean(e);
|
|
|
ac3a84 |
- if (r >= 0) {
|
|
|
ac3a84 |
- saved_in_initrd = r > 0;
|
|
|
ac3a84 |
- return saved_in_initrd;
|
|
|
ac3a84 |
- }
|
|
|
ac3a84 |
- log_debug_errno(r, "Failed to parse $SYSTEMD_IN_INITRD, ignoring: %m");
|
|
|
ac3a84 |
- }
|
|
|
ac3a84 |
- }
|
|
|
ac3a84 |
-
|
|
|
ac3a84 |
- if (!lenient) {
|
|
|
ac3a84 |
- r = path_is_temporary_fs("/");
|
|
|
ac3a84 |
- if (r < 0)
|
|
|
ac3a84 |
- log_debug_errno(r, "Couldn't determine if / is a temporary file system: %m");
|
|
|
ac3a84 |
+ r = getenv_bool_secure("SYSTEMD_IN_INITRD");
|
|
|
ac3a84 |
+ if (r < 0 && r != -ENXIO)
|
|
|
ac3a84 |
+ log_debug_errno(r, "Failed to parse $SYSTEMD_IN_INITRD, ignoring: %m");
|
|
|
ac3a84 |
|
|
|
ac3a84 |
+ if (r >= 0)
|
|
|
ac3a84 |
saved_in_initrd = r > 0;
|
|
|
ac3a84 |
- }
|
|
|
ac3a84 |
-
|
|
|
ac3a84 |
- r = access("/etc/initrd-release", F_OK);
|
|
|
ac3a84 |
- if (r >= 0) {
|
|
|
ac3a84 |
- if (saved_in_initrd == 0)
|
|
|
ac3a84 |
- log_debug("/etc/initrd-release exists, but it's not an initrd.");
|
|
|
ac3a84 |
- else
|
|
|
ac3a84 |
- saved_in_initrd = 1;
|
|
|
ac3a84 |
- } else {
|
|
|
ac3a84 |
- if (errno != ENOENT)
|
|
|
ac3a84 |
- log_debug_errno(errno, "Failed to test if /etc/initrd-release exists: %m");
|
|
|
ac3a84 |
- saved_in_initrd = 0;
|
|
|
ac3a84 |
- }
|
|
|
ac3a84 |
+ else
|
|
|
ac3a84 |
+ saved_in_initrd = access("/etc/initrd-release", F_OK) >= 0 &&
|
|
|
ac3a84 |
+ path_is_temporary_fs("/") > 0;
|
|
|
ac3a84 |
|
|
|
ac3a84 |
return saved_in_initrd;
|
|
|
ac3a84 |
}
|