eeb2ead
From 1f5ddedec35efb92c30a86ae300ce6bc11050044 Mon Sep 17 00:00:00 2001
eeb2ead
From: Harald Hoyer <harald@redhat.com>
eeb2ead
Date: Wed, 16 May 2012 14:22:40 +0200
eeb2ead
Subject: [PATCH] util.c: add in_initrd()
eeb2ead
eeb2ead
in_initrd() checks, if the stat() for the device for "/" is 1, which it
eeb2ead
is for the initramfs.
eeb2ead
(cherry picked from commit 9be346c94eab9de0edc30f08b6c6d070c3a17c79)
eeb2ead
---
eeb2ead
 src/shared/util.c |   15 +++++++++++++++
eeb2ead
 src/shared/util.h |    1 +
eeb2ead
 2 files changed, 16 insertions(+)
eeb2ead
eeb2ead
diff --git a/src/shared/util.c b/src/shared/util.c
eeb2ead
index 61a6ad9..1254017 100644
eeb2ead
--- a/src/shared/util.c
eeb2ead
+++ b/src/shared/util.c
eeb2ead
@@ -5639,3 +5639,18 @@ bool is_valid_documentation_url(const char *url) {
eeb2ead
 
eeb2ead
         return false;
eeb2ead
 }
eeb2ead
+
eeb2ead
+bool in_initrd(void) {
eeb2ead
+        static bool checked=false;
eeb2ead
+        static bool is_in_initrd=false;
eeb2ead
+
eeb2ead
+        if (!checked) {
eeb2ead
+                struct stat sb;
eeb2ead
+                if (stat("/", &sb) == 0) {
eeb2ead
+                        is_in_initrd = (sb.st_dev == 1);
eeb2ead
+                        checked = true;
eeb2ead
+                }
eeb2ead
+        }
eeb2ead
+
eeb2ead
+        return is_in_initrd;
eeb2ead
+}
eeb2ead
diff --git a/src/shared/util.h b/src/shared/util.h
eeb2ead
index d338b08..a47f0b1 100644
eeb2ead
--- a/src/shared/util.h
eeb2ead
+++ b/src/shared/util.h
eeb2ead
@@ -512,4 +512,5 @@ int can_sleep(const char *type);
eeb2ead
 
eeb2ead
 bool is_valid_documentation_url(const char *url);
eeb2ead
 
eeb2ead
+bool in_initrd(void);
eeb2ead
 #endif