summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2008-01-05 12:37:21 +0000
committer/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2008-01-05 12:37:21 +0000
commit70d1f229a46565c48cfaa6412e865ddd4bc5c585 (patch)
treedf7b6a22be1ef748866e10fb74176875964bfe2d
parentcf36ca8cc146f0bc2052f078e6aae3479822ca54 (diff)
downloadconntrack-tools-70d1f229a46565c48cfaa6412e865ddd4bc5c585.tar.gz
conntrack-tools-70d1f229a46565c48cfaa6412e865ddd4bc5c585.zip
Ben Lentz <BLentz@channing-bete.com>:
Detach daemon from its terminal
-rw-r--r--ChangeLog1
-rw-r--r--src/main.c9
2 files changed, 9 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 83e1524..78e3034 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -27,6 +27,7 @@ o show error and warning messages to stderr
o hash lookup speedups based on comments from netdev's discussions
o add support for connection logging to the statistics mode via Logfile
o minor irrelevant fixes for uncommon error paths and fix several typos
+o detach daemon from its terminal (Ben Lenitz <BLentz@channing-bete.com>)
version 0.9.5 (2007/07/29)
------------------------------
diff --git a/src/main.c b/src/main.c
index e0ca46d..ee6abf3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -272,7 +272,7 @@ int main(int argc, char *argv[])
/* Daemonize conntrackd */
if (type == DAEMON) {
- pid_t pid;
+ pid_t pid, sid;
if ((pid = fork()) == -1) {
perror("fork has failed: ");
@@ -280,6 +280,13 @@ int main(int argc, char *argv[])
} else if (pid)
exit(EXIT_SUCCESS);
+ sid = setsid();
+
+ if (sid < 0) {
+ perror("setsid has failed: ");
+ exit(EXIT_FAILURE);
+ }
+
dlog(STATE(log), LOG_NOTICE, "-- starting in daemon mode --");
} else
dlog(STATE(log), LOG_NOTICE, "-- starting in console mode --");