From 742724a46ac30738d277859e184bf57fb7cfb7b8 Mon Sep 17 00:00:00 2001 From: hno <> Date: Sun, 16 Jul 2000 07:11:49 +0000 Subject: [PATCH] Make sure the standard filedescriptors (0,1,2) are connected to /dev/null when running in daemon mode. --- src/main.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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]); -- 2.47.3