]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Use existence of /etc/initrd-release to detect initrd.
authorNeilBrown <neilb@suse.de>
Mon, 13 Mar 2023 03:42:58 +0000 (14:42 +1100)
committerJes Sorensen <jes@trained-monkey.org>
Sun, 19 Mar 2023 16:33:16 +0000 (12:33 -0400)
Since v183, systemd has used the existence of /etc/initrd-release to
detect if it is running in an initrd, rather than looking at the magic
number of the root filesystem's device.  It is time for mdadm to do the
same.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
util.c

diff --git a/util.c b/util.c
index 9f1e1f7c1279f87ee01edd1da2656d5c45cc5244..509fb43ea906f38527b191f27a89a7af752a42b8 100644 (file)
--- a/util.c
+++ b/util.c
@@ -2227,15 +2227,7 @@ int continue_via_systemd(char *devnm, char *service_name)
 
 int in_initrd(void)
 {
-       /* This is based on similar function in systemd. */
-       struct statfs s;
-       /* statfs.f_type is signed long on s390x and MIPS, causing all
-          sorts of sign extension problems with RAMFS_MAGIC being
-          defined as 0x858458f6 */
-       return  statfs("/", &s) >= 0 &&
-               ((unsigned long)s.f_type == TMPFS_MAGIC ||
-                ((unsigned long)s.f_type & 0xFFFFFFFFUL) ==
-                ((unsigned long)RAMFS_MAGIC & 0xFFFFFFFFUL));
+       return access("/etc/initrd-release", F_OK) >= 0;
 }
 
 void reopen_mddev(int mdfd)