[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1257344795-8665-3-git-send-email-vapier@gentoo.org>
Date: Wed, 4 Nov 2009 09:26:35 -0500
From: Mike Frysinger <vapier@...too.org>
To: stephen.hemminger@...tta.com, netdev@...r.kernel.org
Subject: [PATCH] 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@...too.org>
---
misc/ifstat.c | 8 ++++----
misc/nstat.c | 8 ++++----
misc/rtacct.c | 8 ++++----
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/misc/ifstat.c b/misc/ifstat.c
index 68dfdee..0ce8c92 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 80e695f..2e44ed2 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 eb3ea9e..a247dfd 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);
--
1.6.5.1
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists