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:
parent
f67cc036ba
commit
9be346c94e
@ -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;
|
||||
}
|
||||
|
@ -512,4 +512,5 @@ int can_sleep(const char *type);
|
||||
|
||||
bool is_valid_documentation_url(const char *url);
|
||||
|
||||
bool in_initrd(void);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user