diff options
author | Mike Frysinger <vapier@gentoo.org> | 2009-11-06 06:04:39 -0500 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-11-10 10:41:44 -0800 |
commit | a7a9ddbb675b7fbd184c3ab40817265b0b207a23 (patch) | |
tree | c5753b69dfbf254a2a9f0c219e8049c6867b9073 | |
parent | 7f03191fda39ff09640f093b7ad84f461ffd65b2 (diff) |
arpd/ifstat/nstat/rtacct: use daemon()
A bunch of misc utils basically reimplement the daemon() function (the
whole fork/close/chdir/etc...). Rather than do that, use daemon() as
that will work under nommu Linux systems that lack fork().
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r-- | misc/arpd.c | 24 | ||||
-rw-r--r-- | misc/ifstat.c | 8 | ||||
-rw-r--r-- | misc/nstat.c | 8 | ||||
-rw-r--r-- | misc/rtacct.c | 8 |
4 files changed, 15 insertions, 33 deletions
diff --git a/misc/arpd.c b/misc/arpd.c index 71cd082e..128c49d7 100644 --- a/misc/arpd.c +++ b/misc/arpd.c @@ -775,27 +775,9 @@ int main(int argc, char **argv) load_initial_table(); - if (1) { - int fd; - pid_t pid = fork(); - - if (pid > 0) - _exit(0); - if (pid < 0) { - perror("arpd: fork"); - goto do_abort; - } - - chdir("/"); - fd = open("/dev/null", O_RDWR); - if (fd >= 0) { - dup2(fd, 0); - dup2(fd, 1); - dup2(fd, 2); - if (fd > 2) - close(fd); - } - setsid(); + if (daemon(0, 0)) { + perror("arpd: daemon"); + goto do_abort; } openlog("arpd", LOG_PID | LOG_CONS, LOG_DAEMON); diff --git a/misc/ifstat.c b/misc/ifstat.c index 68dfdeee..0ce8c928 100644 --- a/misc/ifstat.c +++ b/misc/ifstat.c @@ -663,10 +663,10 @@ int main(int argc, char *argv[]) perror("ifstat: listen"); exit(-1); } - if (fork()) - exit(0); - chdir("/"); - close(0); close(1); close(2); setsid(); + if (daemon(0, 0)) { + perror("ifstat: daemon"); + exit(-1); + } signal(SIGPIPE, SIG_IGN); signal(SIGCHLD, sigchild); server_loop(fd); diff --git a/misc/nstat.c b/misc/nstat.c index 80e695fc..2e44ed25 100644 --- a/misc/nstat.c +++ b/misc/nstat.c @@ -513,10 +513,10 @@ int main(int argc, char *argv[]) perror("nstat: listen"); exit(-1); } - if (fork()) - exit(0); - chdir("/"); - close(0); close(1); close(2); setsid(); + if (daemon(0, 0)) { + perror("nstat: daemon"); + exit(-1); + } signal(SIGPIPE, SIG_IGN); signal(SIGCHLD, sigchild); server_loop(fd); diff --git a/misc/rtacct.c b/misc/rtacct.c index eb3ea9ec..a247dfd2 100644 --- a/misc/rtacct.c +++ b/misc/rtacct.c @@ -524,10 +524,10 @@ int main(int argc, char *argv[]) perror("rtacct: listen"); exit(-1); } - if (fork()) - exit(0); - chdir("/"); - close(0); close(1); close(2); setsid(); + if (daemon(0, 0)) { + perror("rtacct: daemon"); + exit(-1); + } signal(SIGPIPE, SIG_IGN); signal(SIGCHLD, sigchild); server_loop(fd); |