Commit a7a9ddbb authored by Mike Frysinger's avatar Mike Frysinger Committed by Stephen Hemminger

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: default avatarMike Frysinger <vapier@gentoo.org>
parent 7f03191f
...@@ -775,27 +775,9 @@ int main(int argc, char **argv) ...@@ -775,27 +775,9 @@ int main(int argc, char **argv)
load_initial_table(); load_initial_table();
if (1) { if (daemon(0, 0)) {
int fd; perror("arpd: daemon");
pid_t pid = fork(); goto do_abort;
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();
} }
openlog("arpd", LOG_PID | LOG_CONS, LOG_DAEMON); openlog("arpd", LOG_PID | LOG_CONS, LOG_DAEMON);
......
...@@ -663,10 +663,10 @@ int main(int argc, char *argv[]) ...@@ -663,10 +663,10 @@ int main(int argc, char *argv[])
perror("ifstat: listen"); perror("ifstat: listen");
exit(-1); exit(-1);
} }
if (fork()) if (daemon(0, 0)) {
exit(0); perror("ifstat: daemon");
chdir("/"); exit(-1);
close(0); close(1); close(2); setsid(); }
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
signal(SIGCHLD, sigchild); signal(SIGCHLD, sigchild);
server_loop(fd); server_loop(fd);
......
...@@ -513,10 +513,10 @@ int main(int argc, char *argv[]) ...@@ -513,10 +513,10 @@ int main(int argc, char *argv[])
perror("nstat: listen"); perror("nstat: listen");
exit(-1); exit(-1);
} }
if (fork()) if (daemon(0, 0)) {
exit(0); perror("nstat: daemon");
chdir("/"); exit(-1);
close(0); close(1); close(2); setsid(); }
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
signal(SIGCHLD, sigchild); signal(SIGCHLD, sigchild);
server_loop(fd); server_loop(fd);
......
...@@ -524,10 +524,10 @@ int main(int argc, char *argv[]) ...@@ -524,10 +524,10 @@ int main(int argc, char *argv[])
perror("rtacct: listen"); perror("rtacct: listen");
exit(-1); exit(-1);
} }
if (fork()) if (daemon(0, 0)) {
exit(0); perror("rtacct: daemon");
chdir("/"); exit(-1);
close(0); close(1); close(2); setsid(); }
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
signal(SIGCHLD, sigchild); signal(SIGCHLD, sigchild);
server_loop(fd); server_loop(fd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment