]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdmon: don't lie to systemd.
authorNeilBrown <neilb@suse.de>
Thu, 1 Aug 2013 05:59:24 +0000 (15:59 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 1 Aug 2013 05:59:24 +0000 (15:59 +1000)
Now that mdmon responds fairly well to SIGTERM, stop lying to
systemd about being started on the initrd.

Note that if mdmon is rerun (--takeover) for some reason, and systemd
chooses to kill processes before remounting / readonly, then the
unmount will hang.

If systemd ever lets us tell it that we don't want to be killed until
root is readonly, then we should do that.

Signed-off-by: NeilBrown <neilb@suse.de>
mdadm.h
mdmon.c
util.c

diff --git a/mdadm.h b/mdadm.h
index c5d9c3010aab8a18f9766ea2402488e8389f71b9..43f3a57dd058f3f02071a3a32d27af9d5726b4bc 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1390,6 +1390,8 @@ extern void fmt_devname(char *name, int num);
 extern char *stat2devnm(struct stat *st);
 extern char *fd2devnm(int fd);
 
+extern int in_initrd(void);
+
 #define _ROUND_UP(val, base)   (((val) + (base) - 1) & ~(base - 1))
 #define ROUND_UP(val, base)    _ROUND_UP(val, (typeof(val))(base))
 #define ROUND_UP_PTR(ptr, base)        ((typeof(ptr)) \
diff --git a/mdmon.c b/mdmon.c
index 13f951096cfeaa354586f65931e84471fe73d16b..f0b062372b13f62587a17dd0f05636f78a2b0589 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -298,10 +298,14 @@ int main(int argc, char *argv[])
                {NULL, 0, NULL, 0}
        };
 
-       /*
-        * Always change process name to @dmon to avoid systemd killing it
-        */
-       argv[0][0] = '@';
+       if (in_initrd()) {
+               /*
+                * set first char of argv[0] to @. This is used by
+                * systemd to signal that the task was launched from
+                * initrd/initramfs and should be preserved during shutdown
+                */
+               argv[0][0] = '@';
+       }
 
        while ((opt = getopt_long(argc, argv, "thaF", options, NULL)) != -1) {
                switch (opt) {
diff --git a/util.c b/util.c
index 3965f437a895b63a22917a759f57746fbc3ad3ff..aa2c8be87dfbf17763633513e6087052b72bc9e8 100644 (file)
--- a/util.c
+++ b/util.c
@@ -29,6 +29,8 @@
 #include       <sys/wait.h>
 #include       <sys/un.h>
 #include       <sys/resource.h>
+#include       <sys/vfs.h>
+#include       <linux/magic.h>
 #include       <ctype.h>
 #include       <dirent.h>
 #include       <signal.h>
@@ -1937,3 +1939,12 @@ void enable_fds(int devices)
        lim.rlim_cur = fds;
        setrlimit(RLIMIT_NOFILE, &lim);
 }
+
+int in_initrd(void)
+{
+       /* This is based on similar function in systemd. */
+       struct statfs s;
+       return  statfs("/", &s) >= 0 &&
+               (s.f_type == TMPFS_MAGIC ||
+                s.f_type == RAMFS_MAGIC);
+}