[systemd-devel] [PATCH] util.c: add in_initrd()
harald at redhat.com
harald at redhat.com
Wed May 16 05:22:40 PDT 2012
From: Harald Hoyer <harald at redhat.com>
in_initrd() checks, if the stat() for the device for "/" is 1, which it
is for the initramfs.
---
src/shared/util.c | 15 +++++++++++++++
src/shared/util.h | 1 +
2 files changed, 16 insertions(+)
diff --git a/src/shared/util.c b/src/shared/util.c
index a8c361c..bfa9509 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5610,3 +5610,18 @@ int can_sleep(const char *type) {
free(p);
return found;
}
+
+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;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index a7ddb6c..58db27f 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -509,4 +509,5 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value);
int can_sleep(const char *type);
+bool in_initrd(void);
#endif
--
1.7.10.1
More information about the systemd-devel
mailing list