ryantimwilson / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
698723
From a1417c121d19272b1389098648132106a5ffc661 Mon Sep 17 00:00:00 2001
698723
From: Kairui Song <kasong@redhat.com>
698723
Date: Thu, 14 Jan 2021 01:25:20 +0800
698723
Subject: [PATCH] initrd: do a debug log if /etc/initrd-release doesn't take
698723
 effect
698723
698723
Signed-off-by: Kairui Song <kasong@redhat.com>
698723
698723
(cherry picked from commit 4a60d8cbcae574896a28f9f1f6204a1bddca8e99)
698723
698723
Related: #1959339
698723
---
698723
 src/basic/util.c | 13 +++++++++++--
698723
 1 file changed, 11 insertions(+), 2 deletions(-)
698723
698723
diff --git a/src/basic/util.c b/src/basic/util.c
698723
index fef52ad5ff..609f8c2f33 100644
698723
--- a/src/basic/util.c
698723
+++ b/src/basic/util.c
698723
@@ -174,8 +174,17 @@ bool in_initrd(void) {
698723
                 saved_in_initrd = r > 0;
698723
         }
698723
 
698723
-        if (saved_in_initrd != 0)
698723
-                saved_in_initrd = access("/etc/initrd-release", F_OK) >= 0;
698723
+        r = access("/etc/initrd-release", F_OK);
698723
+        if (r >= 0) {
698723
+                if (saved_in_initrd == 0)
698723
+                        log_debug("/etc/initrd-release exists, but it's not an initrd.");
698723
+                else
698723
+                        saved_in_initrd = 1;
698723
+        } else {
698723
+                if (errno != ENOENT)
698723
+                        log_debug_errno(errno, "Failed to test if /etc/initrd-release exists: %m");
698723
+                saved_in_initrd = 0;
698723
+        }
698723
 
698723
         return saved_in_initrd;
698723
 }