From 44d337f04d35321084b4e309b4d68cf828bf7ec8 Mon Sep 17 00:00:00 2001 From: Anna Czarnowska Date: Wed, 15 Dec 2010 15:51:53 +1100 Subject: [PATCH] fix: Monitor doesn't return after starting daemon Signed-off-by: Anna Czarnowska Signed-off-by: NeilBrown --- Monitor.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Monitor.c b/Monitor.c index af70193..ce160f3 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)