ryantimwilson / rpms / systemd

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