From: wessels <> Date: Fri, 20 Nov 1998 13:08:01 +0000 (+0000) Subject: Fixed dup2() filedescriptor conflicts. yuck. X-Git-Tag: SQUID_3_0_PRE1~2511 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=86ed3fd2c950bcd9693dd476de0052ba5d6f0181;p=thirdparty%2Fsquid.git Fixed dup2() filedescriptor conflicts. yuck. --- diff --git a/src/defines.h b/src/defines.h index b2e3813455..eac8d002ec 100644 --- a/src/defines.h +++ b/src/defines.h @@ -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/ @@ -263,3 +263,7 @@ #define URI_WHITESPACE_ALLOW 1 #define URI_WHITESPACE_ENCODE 2 #define URI_WHITESPACE_CHOP 3 + +#ifndef _PATH_DEVNULL +#define _PATH_DEVNULL "/dev/null" +#endif diff --git a/src/ipc.cc b/src/ipc.cc index 1ff117e603..3d79039f58 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -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 + * 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