]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
arpd/ifstat/nstat/rtacct: use daemon()
authorMike Frysinger <vapier@gentoo.org>
Fri, 6 Nov 2009 11:04:39 +0000 (06:04 -0500)
committerStephen Hemminger <stephen.hemminger@vyatta.com>
Tue, 10 Nov 2009 18:41:44 +0000 (10:41 -0800)
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>
misc/arpd.c
misc/ifstat.c
misc/nstat.c
misc/rtacct.c

index 71cd082e6856330a21d059c70e8dc00513d09b68..128c49d72d64fd628b39740a1fbdedd38545f2b2 100644 (file)
@@ -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);
index 68dfdeeedb777c504c82f206a91f49164b8c4149..0ce8c928d3831a26d3b621447f9d3dc3060040d0 100644 (file)
@@ -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);
index 80e695fca9c50b502e9c6a6ad6fd9d78a4120fed..2e44ed25313d6ce0ecbc283e6f39f1b4c62e96a6 100644 (file)
@@ -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);
index eb3ea9ecf9edbbdc02b9faed9ac3e34116e96067..a247dfd2ca4556c73a6ff6f1305052cb01b30b46 100644 (file)
@@ -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);