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