]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed dup2() filedescriptor conflicts. yuck.
authorwessels <>
Fri, 20 Nov 1998 13:08:01 +0000 (13:08 +0000)
committerwessels <>
Fri, 20 Nov 1998 13:08:01 +0000 (13:08 +0000)
src/defines.h
src/ipc.cc

index b2e3813455f2567f0444271eea98d3d9ecedbc8e..eac8d002ecfe3225235fe4c88f2b3eef795c9d00 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: defines.h,v 1.67 1998/10/14 21:12:00 wessels Exp $
+ * $Id: defines.h,v 1.68 1998/11/20 06:08:01 wessels Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
 #define URI_WHITESPACE_ALLOW 1
 #define URI_WHITESPACE_ENCODE 2
 #define URI_WHITESPACE_CHOP 3
+
+#ifndef _PATH_DEVNULL
+#define _PATH_DEVNULL "/dev/null"
+#endif
index 1ff117e60305c9d731eed606f603cac48796d34a..3d79039f582ca6426d9380c12cc347794c0969ff 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ipc.cc,v 1.14 1998/11/17 01:28:56 wessels Exp $
+ * $Id: ipc.cc,v 1.15 1998/11/20 06:08:01 wessels Exp $
  *
  * DEBUG: section 54    Interprocess Communication
  * AUTHOR: Duane Wessels
@@ -66,6 +66,7 @@ ipcCreate(int type, const char *prog, char *const args[], const char *name, int
     int cwfd = -1;
     int pwfd = -1;
     int fd;
+    int t1, t2, t3;
     socklen_t len;
     int tmp_s;
 #if HAVE_PUTENV
@@ -244,21 +245,27 @@ ipcCreate(int type, const char *prog, char *const args[], const char *name, int
     snprintf(env_str, tmp_s, "SQUID_DEBUG=%s", Config.debugOptions);
     putenv(env_str);
 #endif
-    dup2(fileno(debug_log), 2);
-    if (fileno(debug_log) > 2)
-       fclose(debug_log);
-    dup2(crfd, 0);
-    dup2(cwfd, 1);
     /*
-     * Solaris pthreads seems to close FD 0 upon fork(), so don't close
-     * this FD if its 0, 1, or 2.
-     * -- Michael O'Reilly <michael@metal.iinet.net.au>
+     * This double-dup stuff avoids problems when one of 
+     *  crfd, cwfd, or debug_log are in the rage 0-2.
      */
-    if (crfd > 2)
-       close(crfd);
-    if (cwfd != crfd)
-       if (cwfd > 2)
-           close(cwfd);
+    do {
+       x = open(_PATH_DEVNULL, 0, 0444);
+       commSetCloseOnExec(x);
+    } while (x < 3);
+    t1 = dup(crfd);
+    t2 = dup(cwfd);
+    t3 = dup(fileno(debug_log));
+    assert(t1 > 2 && t2 > 2 && t3 > 2);
+    close(crfd);
+    close(cwfd);
+    close(fileno(debug_log));
+    dup2(t1, 0);
+    dup2(t2, 1);
+    dup2(t3, 2);
+    close(t1);
+    close(t2);
+    close(t3);
 #if HAVE_SETSID
     setsid();
 #endif