--------------------- PatchSet 2758 Date: 2001/08/14 09:02:04 Author: rbcollins Branch: external_logger Tag: (none) Log: updated to correctly never close the log pipe Members: src/ipc.c:1.4.54.3->1.4.54.4 src/logfile.c:1.5.22.3->1.5.22.4 src/protos.h:1.30.2.4->1.30.2.5 src/structs.h:1.37.2.3->1.37.2.4 src/typedefs.h:1.22.2.2->1.22.2.3 Index: squid/src/ipc.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ipc.c,v retrieving revision 1.4.54.3 retrieving revision 1.4.54.4 diff -u -r1.4.54.3 -r1.4.54.4 --- squid/src/ipc.c 4 Aug 2001 04:19:10 -0000 1.4.54.3 +++ squid/src/ipc.c 14 Aug 2001 09:02:04 -0000 1.4.54.4 @@ -1,6 +1,6 @@ /* - * $Id: ipc.c,v 1.4.54.3 2001/08/04 04:19:10 rbcollins Exp $ + * $Id: ipc.c,v 1.4.54.4 2001/08/14 09:02:04 rbcollins Exp $ * * DEBUG: section 54 Interprocess Communication * AUTHOR: Duane Wessels @@ -286,9 +286,11 @@ return 0; } -/* create a oneway ipc, used for logging. ipcout becomes the child process stdout */ +/* create a oneway ipc, used for logging. ipcout becomes the child process stdout + * And wfd is not reset once it has been created. + */ int -ipcCreateOneWay(int type, const char *prog, char *const args[], const char *name, int ipcout, int *wfd) +ipcCreateOneWay(int type, const char *prog, char *const args[], const char *name, int ipcout, ipc_comm *ipccomm) { pid_t pid; struct sockaddr_in CS; @@ -311,8 +313,8 @@ #endif assert (ipcout > 0); - if (wfd) - *wfd = -1; + assert (ipccomm); + if (ipccomm->crfd == -1) { if (type == IPC_TCP_SOCKET) { crfd = cwfd = comm_open(SOCK_STREAM, 0, @@ -357,6 +359,16 @@ } else { assert(IPC_NONE); } + ipccomm->prfd = prfd; + ipccomm->pwfd = pwfd; + ipccomm->crfd = crfd; + ipccomm->cwfd = cwfd; + } else { + prfd=ipccomm->prfd; + pwfd=ipccomm->pwfd; + crfd=ipccomm->crfd; + cwfd=ipccomm->cwfd; + } debug(54, 3) ("ipcCreate: prfd FD %d\n", prfd); debug(54, 3) ("ipcCreate: pwfd FD %d\n", pwfd); debug(54, 3) ("ipcCreate: crfd FD %d\n", crfd); @@ -364,10 +376,12 @@ if (crfd < 0) { debug(54, 0) ("ipcCreate: Failed to create child FD.\n"); + memset (ipccomm, -1, sizeof(ipc_comm)); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } if (pwfd < 0) { debug(54, 0) ("ipcCreate: Failed to create server FD.\n"); + memset (ipccomm, -1, sizeof(ipc_comm)); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } if (type == IPC_TCP_SOCKET || type == IPC_UDP_SOCKET) { @@ -375,6 +389,7 @@ memset(&PS, '\0', len); if (getsockname(pwfd, (struct sockaddr *) &PS, &len) < 0) { debug(50, 0) ("ipcCreate: getsockname: %s\n", xstrerror()); + memset (ipccomm, -1, sizeof(ipc_comm)); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } debug(54, 3) ("ipcCreate: FD %d sockaddr %s:%d\n", @@ -383,6 +398,7 @@ memset(&CS, '\0', len); if (getsockname(crfd, (struct sockaddr *) &CS, &len) < 0) { debug(50, 0) ("ipcCreate: getsockname: %s\n", xstrerror()); + memset (ipccomm, -1, sizeof(ipc_comm)); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } debug(54, 3) ("ipcCreate: FD %d sockaddr %s:%d\n", @@ -391,6 +407,7 @@ if (type == IPC_TCP_SOCKET) { if (listen(crfd, 1) < 0) { debug(50, 1) ("ipcCreate: listen FD %d: %s\n", crfd, xstrerror()); + memset (ipccomm, -1, sizeof(ipc_comm)); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } debug(54, 3) ("ipcCreate: FD %d listening...\n", crfd); @@ -399,17 +416,19 @@ logsFlush(); if ((pid = fork()) < 0) { debug(50, 1) ("ipcCreate: fork: %s\n", xstrerror()); + memset (ipccomm, -1, sizeof(ipc_comm)); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } if (pid > 0) { /* parent */ - /* close shared socket with child */ - comm_close(crfd); - if (cwfd != crfd) - comm_close(cwfd); - cwfd = crfd = -1; + /* don't close shared child sockets as we need them the next time around */ + /* force blocking */ + commUnsetNonBlocking(pwfd); + commUnsetNonBlocking(prfd); if (type == IPC_TCP_SOCKET || type == IPC_UDP_SOCKET) { - if (comm_connect_addr(pwfd, &CS) == COMM_ERROR) + if (comm_connect_addr(pwfd, &CS) == COMM_ERROR) { + memset (ipccomm, -1, sizeof(ipc_comm)); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); + } } memset(hello_buf, '\0', HELLO_BUF_SZ); if (type == IPC_UDP_SOCKET) @@ -419,20 +438,22 @@ if (x < 0) { debug(50, 0) ("ipcCreate: PARENT: hello read test failed\n"); debug(50, 0) ("--> read: %s\n", xstrerror()); + memset (ipccomm, -1, sizeof(ipc_comm)); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } else if (strcmp(hello_buf, hello_string)) { debug(54, 0) ("ipcCreate: PARENT: hello read test failed\n"); debug(54, 0) ("--> read returned %d\n", x); debug(54, 0) ("--> got '%s'\n", rfc1738_escape(hello_buf)); + memset (ipccomm, -1, sizeof(ipc_comm)); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } commSetTimeout(prfd, -1, NULL, NULL); commSetNonBlocking(prfd); commSetNonBlocking(pwfd); - if (wfd) - *wfd = pwfd; fd_table[prfd].flags.ipc = 1; fd_table[pwfd].flags.ipc = 1; + fd_table[crfd].flags.ipc = 1; + fd_table[cwfd].flags.ipc = 1; return pid; } /* child */ @@ -442,7 +463,9 @@ if (pwfd != prfd) close(pwfd); pwfd = prfd = -1; - + /* force blocking */ + commUnsetNonBlocking(crfd); + commUnsetNonBlocking(cwfd); if (type == IPC_TCP_SOCKET) { debug(54, 3) ("ipcCreate: calling accept on FD %d\n", crfd); if ((fd = accept(crfd, NULL, NULL)) < 0) { @@ -453,8 +476,10 @@ close(crfd); cwfd = crfd = fd; } else if (type == IPC_UDP_SOCKET) { - if (comm_connect_addr(crfd, &PS) == COMM_ERROR) + if (comm_connect_addr(crfd, &PS) == COMM_ERROR) { + memset (ipccomm, -1, sizeof(ipc_comm)); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); + } } if (type == IPC_UDP_SOCKET) { x = send(cwfd, hello_string, strlen(hello_string) + 1, 0); @@ -490,6 +515,7 @@ t3 = dup(fileno(debug_log)); else t3 = dup(cachelog->logfd); + debug(1,1)("cachelog is %x t1 %d t2 %d t3 %d\n",cachelog, t1,t2,t3); assert(t1 > 2 && t2 > 2 && t3 > 2); close(crfd); close(cwfd); Index: squid/src/logfile.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/logfile.c,v retrieving revision 1.5.22.3 retrieving revision 1.5.22.4 diff -u -r1.5.22.3 -r1.5.22.4 --- squid/src/logfile.c 9 Aug 2001 23:08:18 -0000 1.5.22.3 +++ squid/src/logfile.c 14 Aug 2001 09:02:04 -0000 1.5.22.4 @@ -68,6 +68,8 @@ lf->bufsz = bufsz; } lf->filefd = fd; + lf->logfd = -1; + lf->ipccomm.crfd = -1; x = ipcCreateOneWay( #if HAVE_POLL && defined(_SQUID_OSF_) /* pipes and poll() don't get along on DUNIX -DW */ @@ -79,10 +81,11 @@ NULL, "logd", lf->filefd, - &lf->logfd); + &lf->ipccomm); if (x < 0) fatalf("execl %s failed!\n", Config.Program.logd); lf->pid = x; + lf->logfd = lf->ipccomm.pwfd; commUnsetNonBlocking(lf->logfd); add_ipc_quit_handler(x, logfileHelperQuit, lf); return lf; @@ -126,7 +129,6 @@ remove_ipc_quit_handler(lf->pid, logfileHelperQuit, lf); /* always close */ file_close(lf->filefd); - comm_close(lf->logfd); if (Config.Log.rotateNumber > 0) { snprintf(to, MAXPATHLEN, "%s.%d", lf->path, 0); xrename(lf->path, to); @@ -148,10 +150,11 @@ NULL, "logd", lf->filefd, - &lf->logfd); + &lf->ipccomm); if (x < 0) fatalf("execl %s failed!\n", Config.Program.logd); lf->pid = x; + assert(lf->logfd == lf->ipccomm.pwfd); commUnsetNonBlocking(lf->logfd); add_ipc_quit_handler(x, logfileHelperQuit, lf); } @@ -237,7 +240,7 @@ int x; assert (lf); /* TODO: safe logging of the restart */ - fprintf(stderr, "log helper %d has exited unexpectedly. Starting new helper\n", lf->pid); + fprintf(stderr, "log helper pid %d file %s has exited unexpectedly. Starting new helper\n", lf->pid, lf->path); x = ipcCreateOneWay( #if HAVE_POLL && defined(_SQUID_OSF_) /* pipes and poll() don't get along on DUNIX -DW */ @@ -249,10 +252,11 @@ NULL, "logd", lf->filefd, - &lf->logfd); + &lf->ipccomm); if (x < 0) fatalf("execl %s failed!\n", Config.Program.logd); lf->pid = x; + assert(lf->logfd == lf->ipccomm.pwfd); commUnsetNonBlocking(lf->logfd); add_ipc_quit_handler(x, logfileHelperQuit, lf); } Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.30.2.4 retrieving revision 1.30.2.5 diff -u -r1.30.2.4 -r1.30.2.5 --- squid/src/protos.h 13 Aug 2001 23:25:15 -0000 1.30.2.4 +++ squid/src/protos.h 14 Aug 2001 09:02:04 -0000 1.30.2.5 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.30.2.4 2001/08/13 23:25:15 rbcollins Exp $ + * $Id: protos.h,v 1.30.2.5 2001/08/14 09:02:04 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1194,7 +1194,7 @@ const char *name, int *rfd, int *wfd); -extern int ipcCreateOneWay(int, const char *, char *const *, const char *, int, int *); +extern int ipcCreateOneWay(int, const char *, char *const *, const char *, int, ipc_comm *); extern void add_ipc_quit_handler(int, EVH, void *); extern void remove_ipc_quit_handler(int, EVH, void *); extern void ipcCallQuitHandlers(int); Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.37.2.3 retrieving revision 1.37.2.4 diff -u -r1.37.2.3 -r1.37.2.4 --- squid/src/structs.h 13 Aug 2001 23:25:15 -0000 1.37.2.3 +++ squid/src/structs.h 14 Aug 2001 09:02:04 -0000 1.37.2.4 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.37.2.3 2001/08/13 23:25:15 rbcollins Exp $ + * $Id: structs.h,v 1.37.2.4 2001/08/14 09:02:04 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -2126,6 +2126,13 @@ } shm; }; +struct _ipc_comm { + int crfd; + int cwfd; + int prfd; + int pwfd; +}; + struct _Logfile { int filefd; int logfd; @@ -2137,6 +2144,7 @@ struct { unsigned int fatal:1; } flags; + ipc_comm ipccomm; }; struct cache_dir_option { Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.22.2.2 retrieving revision 1.22.2.3 diff -u -r1.22.2.2 -r1.22.2.3 --- squid/src/typedefs.h 13 Aug 2001 23:25:15 -0000 1.22.2.2 +++ squid/src/typedefs.h 14 Aug 2001 09:02:04 -0000 1.22.2.3 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.22.2.2 2001/08/13 23:25:15 rbcollins Exp $ + * $Id: typedefs.h,v 1.22.2.3 2001/08/14 09:02:04 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -110,6 +110,7 @@ typedef struct _HttpReply HttpReply; typedef struct _HttpStateData HttpStateData; typedef struct _icpUdpData icpUdpData; +typedef struct _ipc_comm ipc_comm; typedef struct _clientHttpRequest clientHttpRequest; typedef struct _ConnStateData ConnStateData; typedef struct _ConnCloseHelperData ConnCloseHelperData;