summaryrefslogtreecommitdiffstats
path: root/dhcpcd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-10-20 16:58:13 +0000
committerRoy Marples <roy@marples.name>2007-10-20 16:58:13 +0000
commitcfbd159f4963a70033562a1ac16c7d0d932497ab (patch)
tree6cdf887e6464e3e12796c41797cf6b1ec28d07d3 /dhcpcd.c
parent6b37baaad11ddf85817aaaea5aaac4259b77866f (diff)
downloaddhcpcd-cfbd159f4963a70033562a1ac16c7d0d932497ab.tar.xz
Write the pidfile before we fork so we can easily be stopped by other processes.
Diffstat (limited to 'dhcpcd.c')
-rw-r--r--dhcpcd.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/dhcpcd.c b/dhcpcd.c
index 55641b2a..ac4de084 100644
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -531,6 +531,7 @@ int main(int argc, char **argv)
fcntl (pidfd, F_SETFD, i | FD_CLOEXEC) == -1)
logger (LOG_ERR, "fcntl: %s", strerror (errno));
+ writepid (pidfd, getpid ());
logger (LOG_INFO, PACKAGE " " VERSION " starting");
}
@@ -541,6 +542,12 @@ int main(int argc, char **argv)
if (dhcp_run (options, &pidfd) == 0)
i = EXIT_SUCCESS;
+ /* If we didn't daemonise then we need to punt the pidfile now */
+ if (pidfd > -1) {
+ close (pidfd);
+ unlink (options->pidfile);
+ }
+
free (options);
#ifdef THERE_IS_NO_FORK
@@ -551,8 +558,5 @@ int main(int argc, char **argv)
logger (LOG_INFO, "exiting");
- if (pidfd > -1)
- close (pidfd);
-
exit (i);
}