diff options
author | Jes Sorensen <Jes.Sorensen@redhat.com> | 2013-02-01 16:15:18 +0100 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2013-02-05 05:40:38 +0100 |
commit | 0f7bdf8946316548500858303549e396655450c5 (patch) | |
tree | 9b298539d6e33df2496382afcc3acab9d1e4dc6d /util.c | |
parent | Remove --offroot argument and default to always setting argv[0] to @ (diff) | |
download | mdadm-0f7bdf8946316548500858303549e396655450c5.tar.xz mdadm-0f7bdf8946316548500858303549e396655450c5.zip |
Add support for launching mdmon via systemctl instead of fork/exec
If launching mdmon via systemctl fails, we fall back to the old method
of fork/exec. This allows for having mdmon launched via systemctl
which avoids problems with it getting killed by systemd due to it
ending up in the parent's cgroup (udev).
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -1660,6 +1660,34 @@ int start_mdmon(int devnum) } else pathbuf[0] = '\0'; + /* First try to run systemctl */ + switch(fork()) { + case 0: + /* FIXME yuk. CLOSE_EXEC?? */ + skipped = 0; + for (i = 3; skipped < 20; i++) + if (close(i) < 0) + skipped++; + else + skipped = 0; + + snprintf(pathbuf, sizeof(pathbuf), "mdmon@%s.service", + devnum2devname(devnum)); + status = execl("/usr/bin/systemctl", "systemctl", "start", + pathbuf, NULL); + status = execl("/bin/systemctl", "systemctl", "start", + pathbuf, NULL); + exit(1); + case -1: pr_err("cannot run mdmon. " + "Array remains readonly\n"); + return -1; + default: /* parent - good */ + pid = wait(&status); + if (pid >= 0 && status == 0) + return 0; + } + + /* That failed, try running mdmon directly */ switch(fork()) { case 0: /* FIXME yuk. CLOSE_EXEC?? */ |