dcavalca / rpms / systemd

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