From: Mike Frysinger <vapier@gentoo.org>
To: stephen.hemminger@vyatta.com, netdev@vger.kernel.org
Subject: [PATCH] ifstat/nstat/rtacct: use daemon()
Date: Wed, 4 Nov 2009 09:26:35 -0500 [thread overview]
Message-ID: <1257344795-8665-3-git-send-email-vapier@gentoo.org> (raw)
In-Reply-To: <1257344795-8665-1-git-send-email-vapier@gentoo.org>
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/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
next prev parent reply other threads:[~2009-11-04 14:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-04 14:26 [PATCH] ignore gdb/patch related files Mike Frysinger
2009-11-04 14:26 ` [PATCH] tc: remove dlfcn.h from files that dont need it Mike Frysinger
2009-11-04 14:26 ` Mike Frysinger [this message]
2009-11-06 11:04 ` [PATCH v2] arpd/ifstat/nstat/rtacct: use daemon() Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1257344795-8665-3-git-send-email-vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=netdev@vger.kernel.org \
--cc=stephen.hemminger@vyatta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox