From: Anna Czarnowska Date: Wed, 15 Dec 2010 04:51:53 +0000 (+1100) Subject: fix: Monitor doesn't return after starting daemon X-Git-Tag: mdadm-3.2~183 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44d337f04d35321084b4e309b4d68cf828bf7ec8;p=thirdparty%2Fmdadm.git fix: Monitor doesn't return after starting daemon Signed-off-by: Anna Czarnowska Signed-off-by: NeilBrown --- diff --git a/Monitor.c b/Monitor.c index af701939..ce160f3e 100644 --- a/Monitor.c +++ b/Monitor.c @@ -152,9 +152,11 @@ int Monitor(struct mddev_dev *devlist, info.mailfrom = mailfrom; info.dosyslog = dosyslog; - if (daemonise) - if (make_daemon(pidfile)) - return 1; + if (daemonise) { + int rv = make_daemon(pidfile); + if (rv >= 0) + return rv; + } if (share) if (check_one_sharer(scan)) @@ -247,6 +249,12 @@ int Monitor(struct mddev_dev *devlist, static int make_daemon(char *pidfile) { + /* Return: + * -1 in the forked daemon + * 0 in the parent + * 1 on error + * so a none-negative becomes the exit code. + */ int pid = fork(); if (pid > 0) { if (!pidfile) @@ -272,7 +280,7 @@ static int make_daemon(char *pidfile) dup2(0,1); dup2(0,2); setsid(); - return 0; + return -1; } static int check_one_sharer(int scan)