diff options
| author | Roy Marples <roy@marples.name> | 2007-10-20 16:58:13 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2007-10-20 16:58:13 +0000 |
| commit | cfbd159f4963a70033562a1ac16c7d0d932497ab (patch) | |
| tree | 6cdf887e6464e3e12796c41797cf6b1ec28d07d3 /dhcpcd.c | |
| parent | 6b37baaad11ddf85817aaaea5aaac4259b77866f (diff) | |
| download | dhcpcd-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.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -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); } |
