From a156e55302d7ce35234b6075124d2b5ed4037c89 Mon Sep 17 00:00:00 2001 From: "/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org" Date: Thu, 17 Jan 2008 17:10:40 +0000 Subject: Max Kellerman : o always close stdin - even in non-daemon mode, it is of no use o chdir("/") to release the cwd inode o ignore setsid() failure, because there is only one possible and o fix harmless error condition --- ChangeLog | 4 ++++ src/main.c | 13 +++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6425e32..9fbfa71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -71,6 +71,10 @@ o add missing printf arguments o use timeradd() since manipulating tv_sec directly o fix lots of gcc warnings o don't call INIT_LIST_HEAD on list item when unneeded +o always close stdin - even in non-daemon mode, it is of no use +o chdir("/") to release the cwd inode +o ignore setsid() failure, because there is only one possible and +o fix harmless error condition version 0.9.5 (2007/07/29) ------------------------------ diff --git a/src/main.c b/src/main.c index a4ee307..b860982 100644 --- a/src/main.c +++ b/src/main.c @@ -284,9 +284,12 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } + chdir("/"); + close(STDIN_FILENO); + /* Daemonize conntrackd */ if (type == DAEMON) { - pid_t pid, sid; + pid_t pid; if ((pid = fork()) == -1) { perror("fork has failed: "); @@ -294,14 +297,8 @@ int main(int argc, char *argv[]) } else if (pid) exit(EXIT_SUCCESS); - sid = setsid(); - - if (sid < 0) { - perror("setsid has failed: "); - exit(EXIT_FAILURE); - } + setsid(); - close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); -- cgit v1.2.3