summaryrefslogtreecommitdiffstats
path: root/dhcpcd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2014-02-04 15:53:56 +0000
committerRoy Marples <roy@marples.name>2014-02-04 15:53:56 +0000
commitcff708ad3bdc3245086cbe5a1a37d9e9afea1692 (patch)
tree2a0fa04611bb3818a83297c41ee2a3e7a6a6c196 /dhcpcd.c
parentb5b066a566d6f1882c1a08dfe041c71a8c93be02 (diff)
downloaddhcpcd-cff708ad3bdc3245086cbe5a1a37d9e9afea1692.tar.xz
Only return 0 from daemonise if we have forked successfully, otherwise the pid of the child.
Diffstat (limited to 'dhcpcd.c')
-rw-r--r--dhcpcd.c14
1 files changed, 7 insertions, 7 deletions
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. */