From 70d1f229a46565c48cfaa6412e865ddd4bc5c585 Mon Sep 17 00:00:00 2001 From: "/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org" Date: Sat, 5 Jan 2008 12:37:21 +0000 Subject: Ben Lentz : Detach daemon from its terminal --- src/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/main.c') 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 --"); -- cgit v1.2.3