summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2013-08-05 14:55:13 +1000
committerNeilBrown <neilb@suse.de>2013-08-05 14:55:13 +1000
commit9540cc244dfc56d40f686d8f63aa5b6d73663bcf (patch)
treed41a15af6b6cce11cad6dce23cab744d8df72f2a /util.c
parent4389b648bb9dc8ab61ce8777654d59634dafc737 (diff)
downloadmdadm-9540cc244dfc56d40f686d8f63aa5b6d73663bcf.tar.gz
test: ensure testing uses correct mdmon
When testing we want to run mdmon directly, not use systemctl to get systemd to run it. So allow an environment variable to make that choice. Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'util.c')
-rw-r--r--util.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/util.c b/util.c
index aa2c8be..e7e3d48 100644
--- a/util.c
+++ b/util.c
@@ -1711,36 +1711,39 @@ int start_mdmon(char *devnm)
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;
-
- /* Don't want to see error messages from systemctl.
- * If the service doesn't exist, we start mdmon ourselves.
- */
- close(2);
- open("/dev/null", O_WRONLY);
- snprintf(pathbuf, sizeof(pathbuf), "mdmon@%s.service",
- devnm);
- 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;
- }
+ if (!check_env("MDADM_NO_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;
+
+ /* Don't want to see error messages from
+ * systemctl. If the service doesn't exist,
+ * we start mdmon ourselves.
+ */
+ close(2);
+ open("/dev/null", O_WRONLY);
+ snprintf(pathbuf, sizeof(pathbuf), "mdmon@%s.service",
+ devnm);
+ 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()) {