summaryrefslogtreecommitdiffstats
path: root/dund/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'dund/main.c')
-rw-r--r--dund/main.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/dund/main.c b/dund/main.c
index 249d6d7c..bb96d639 100644
--- a/dund/main.c
+++ b/dund/main.c
@@ -598,18 +598,9 @@ int main(int argc, char *argv[])
sa.sa_handler = sig_hup;
sigaction(SIGHUP, &sa, NULL);
- if (detach) {
- int fd;
-
- if (fork()) exit(0);
-
- /* Direct stdin,stdout,stderr to '/dev/null' */
- fd = open("/dev/null", O_RDWR);
- dup2(fd, 0); dup2(fd, 1); dup2(fd, 2);
- close(fd);
-
- setsid();
- chdir("/");
+ if (detach && daemon(0, 0)) {
+ perror("Can't start daemon");
+ exit(1);
}
openlog("dund", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON);