]> err.no Git - systemd/commitdiff
util: rework in_initrd() logic
authorLennart Poettering <lennart@poettering.net>
Mon, 21 May 2012 18:00:58 +0000 (20:00 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 21 May 2012 18:00:58 +0000 (20:00 +0200)
Checking the device major/minor is not a good idea. Let's replace this
with an explicit flag file, which we model after /etc/os-release and
call /etc/initrd-release.

TODO
src/shared/util.c

diff --git a/TODO b/TODO
index b147d3aefe24ecdd2ef23a5fbb4da7cc3d083c5e..da8bef6548ff396aa096a6f6130f3f1af2b33c8a 100644 (file)
--- a/TODO
+++ b/TODO
@@ -53,8 +53,6 @@ Features:
 
 * actually queue the new default unit after switch-root
 
-* remove old root in switch-root logic
-
 * improve !/proc/*/loginuid situation: make /proc/*/loginuid less dependent on CONFIG_AUDIT,
   or use the users cgroup information when /proc/*/loginuid is not available.
 
index 5acddd3e0f9250c61a6bfc0a5be4d19c3fca5a53..4b841491aa2a73e4d9ea79bca62d31ce0bc44bae 100644 (file)
@@ -5654,16 +5654,10 @@ bool is_valid_documentation_url(const char *url) {
 }
 
 bool in_initrd(void) {
-        static bool checked=false;
-        static bool is_in_initrd=false;
-
-        if (!checked) {
-                struct stat sb;
-                if (stat("/", &sb) == 0) {
-                        is_in_initrd = (sb.st_dev == 1);
-                        checked = true;
-                }
-        }
+        static int saved = -1;
+
+        if (saved < 0)
+                saved = access("/etc/initrd-release", F_OK) >= 0;
 
-        return is_in_initrd;
+        return saved;
 }