From: hno <> Date: Sun, 16 Jul 2000 07:11:49 +0000 (+0000) Subject: Make sure the standard filedescriptors (0,1,2) are connected to X-Git-Tag: SQUID_3_0_PRE1~1896 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=742724a46ac30738d277859e184bf57fb7cfb7b8;p=thirdparty%2Fsquid.git Make sure the standard filedescriptors (0,1,2) are connected to /dev/null when running in daemon mode. --- diff --git a/src/main.cc b/src/main.cc index bb31811ac8..27fcc4bd4d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.316 2000/07/13 06:13:42 wessels Exp $ + * $Id: main.cc,v 1.317 2000/07/16 01:11:49 hno Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -829,6 +829,7 @@ watch_child(char *argv[]) #endif pid_t pid; int i; + int nullfd; if (*(argv[0]) == '(') return; openlog(appname, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4); @@ -845,7 +846,15 @@ watch_child(char *argv[]) close(i); } #endif - for (i = 0; i < Squid_MaxFD; i++) + /* Connect stdio to /dev/null in daemon mode */ + nullfd = open("/dev/null", O_RDWR); + dup2(nullfd, 0); + if (opt_debug_stderr < 0) { + dup2(nullfd, 1); + dup2(nullfd, 2); + } + /* Close all else */ + for (i = 3; i < Squid_MaxFD; i++) close(i); for (;;) { mainStartScript(argv[0]);