1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-26 09:57:26 +03:00

util.c: add in_initrd()

in_initrd() checks, if the stat() for the device for "/" is 1, which it
is for the initramfs.
This commit is contained in:
Harald Hoyer 2012-05-16 14:22:40 +02:00 committed by Lennart Poettering
parent f67cc036ba
commit 9be346c94e
2 changed files with 16 additions and 0 deletions

View 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;
}

View File

@ -512,4 +512,5 @@ int can_sleep(const char *type);
bool is_valid_documentation_url(const char *url);
bool in_initrd(void);
#endif