chiark / gitweb /
util.c: add in_initrd()
authorHarald Hoyer <harald@redhat.com>
Wed, 16 May 2012 12:22:40 +0000 (14:22 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 21 May 2012 16:47:39 +0000 (18:47 +0200)
in_initrd() checks, if the stat() for the device for "/" is 1, which it
is for the initramfs.

src/shared/util.c
src/shared/util.h

index 53185403d62d8e762682d1f7b499e04904fd15c1..681484bc0f01591bbfd5a15db233a01c8837d0d2 100644 (file)
@@ -5639,3 +5639,18 @@ bool is_valid_documentation_url(const char *url) {
 
         return false;
 }
+
+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;
+                }
+        }
+
+        return is_in_initrd;
+}
index 0af0299dbb502f113806f175458c82564bf5a70e..4fccf96a6d3d9a8414c965ac17b762c7ecc4a525 100644 (file)
@@ -512,4 +512,5 @@ int can_sleep(const char *type);
 
 bool is_valid_documentation_url(const char *url);
 
+bool in_initrd(void);
 #endif