From: Roy Marples Date: Tue, 4 Feb 2014 15:53:56 +0000 (+0000) Subject: Only return 0 from daemonise if we have forked successfully, otherwise the pid of... X-Git-Tag: v6.3.0~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cff708ad3bdc3245086cbe5a1a37d9e9afea1692;p=thirdparty%2Fdhcpcd.git Only return 0 from daemonise if we have forked successfully, otherwise the pid of the child. --- diff --git a/dhcpcd.c b/dhcpcd.c index e0640aa1..591dd029 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -186,12 +186,13 @@ handle_exit_timeout(__unused void *arg) eloop_timeout_add_sec(timeout, handle_exit_timeout, NULL); } +/* Returns the pid of the child, otherwise 0. */ pid_t daemonise(void) { #ifdef THERE_IS_NO_FORK errno = ENOSYS; - return -1; + return 0; #else pid_t pid; char buf = '\0'; @@ -200,18 +201,18 @@ daemonise(void) if (options & DHCPCD_DAEMONISE && !(options & DHCPCD_DAEMONISED)) { if (options & DHCPCD_WAITIP4 && !ipv4_addrexists(NULL)) - return -1; + return 0; if (options & DHCPCD_WAITIP6 && !ipv6nd_addrexists(NULL) && !dhcp6_addrexists(NULL)) - return -1; + return 0; if ((options & (DHCPCD_WAITIP | DHCPCD_WAITIP4 | DHCPCD_WAITIP6)) == DHCPCD_WAITIP && !ipv4_addrexists(NULL) && !ipv6nd_addrexists(NULL) && !dhcp6_addrexists(NULL)) - return -1; + return 0; } eloop_timeout_delete(handle_exit_timeout, NULL); @@ -220,14 +221,13 @@ daemonise(void) /* Setup a signal pipe so parent knows when to exit. */ if (pipe(sidpipe) == -1) { syslog(LOG_ERR, "pipe: %m"); - return -1; + return 0; } syslog(LOG_DEBUG, "forking to background"); switch (pid = fork()) { case -1: syslog(LOG_ERR, "fork: %m"); - exit(EXIT_FAILURE); - /* NOTREACHED */ + return 0; case 0: setsid(); /* Notify parent it's safe to exit as we've detached. */