]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Make sure the standard filedescriptors (0,1,2) are connected to
authorhno <>
Sun, 16 Jul 2000 07:11:49 +0000 (07:11 +0000)
committerhno <>
Sun, 16 Jul 2000 07:11:49 +0000 (07:11 +0000)
/dev/null when running in daemon mode.

src/main.cc

index bb31811ac800dcb54b2dd1ae552f00e6b62e36d2..27fcc4bd4d0a4a4539eeddf54e02455fe54ab462 100644 (file)
@@ -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]);