--------------------- PatchSet 8600 Date: 2006/09/03 12:20:09 Author: serassio Branch: nt Tag: (none) Log: Little refactoring of IPC support Members: src/helper.c:1.32.2.7->1.32.2.8 src/icmp.c:1.10.2.1->1.10.2.2 src/ipc.c:1.11.2.7->1.11.2.8 src/ipc_win32.c:1.1.2.1->1.1.2.2 src/protos.h:1.74.2.35->1.74.2.36 src/structs.h:1.81.2.30->1.81.2.31 src/unlinkd.c:1.11.2.4->1.11.2.5 src/fs/diskd/store_dir_diskd.c:1.45.2.8->1.45.2.9 src/fs/diskd/store_diskd.h:1.8.8.3->1.8.8.4 Index: squid/src/helper.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/helper.c,v retrieving revision 1.32.2.7 retrieving revision 1.32.2.8 diff -u -r1.32.2.7 -r1.32.2.8 --- squid/src/helper.c 9 Jul 2006 18:58:19 -0000 1.32.2.7 +++ squid/src/helper.c 3 Sep 2006 12:20:09 -0000 1.32.2.8 @@ -1,6 +1,6 @@ /* - * $Id: helper.c,v 1.32.2.7 2006/07/09 18:58:19 serassio Exp $ + * $Id: helper.c,v 1.32.2.8 2006/09/03 12:20:09 serassio Exp $ * * DEBUG: section 84 Helper process maintenance * AUTHOR: Harvest Derived? @@ -66,14 +66,12 @@ helper_server *srv; int nargs = 0; int k; - int x; + pid_t pid; int rfd; int wfd; wordlist *w; -#ifdef _SQUID_MSWIN_ - HANDLE hIpc; - pid_t pid; -#endif + void * hIpc; + if (hlp->cmdline == NULL) return; progname = hlp->cmdline->key; @@ -93,29 +91,22 @@ for (k = 0; k < hlp->n_to_start; k++) { getCurrentTime(); rfd = wfd = -1; - x = ipcCreate(hlp->ipc_type, + pid = ipcCreate(hlp->ipc_type, progname, args, shortname, &rfd, - &wfd -#ifdef _SQUID_MSWIN_ - , &hIpc, &pid -#endif - ); - if (x < 0) { + &wfd, + &hIpc); + if (pid < 0) { debug(84, 1) ("WARNING: Cannot run '%s' process.\n", progname); continue; } hlp->n_running++; hlp->n_active++; srv = cbdataAlloc(helper_server); -#ifdef _SQUID_MSWIN_ srv->hIpc = hIpc; srv->pid = pid; -#else - srv->pid = x; -#endif srv->index = k; srv->rfd = rfd; srv->wfd = wfd; @@ -158,14 +149,11 @@ helper_stateful_server *srv; int nargs = 0; int k; - int x; + pid_t pid; int rfd; int wfd; wordlist *w; -#ifdef _SQUID_MSWIN_ - HANDLE hIpc; - pid_t pid; -#endif + void * hIpc; if (hlp->cmdline == NULL) return; @@ -186,29 +174,22 @@ for (k = 0; k < hlp->n_to_start; k++) { getCurrentTime(); rfd = wfd = -1; - x = ipcCreate(hlp->ipc_type, + pid = ipcCreate(hlp->ipc_type, progname, args, shortname, &rfd, - &wfd -#ifdef _SQUID_MSWIN_ - , &hIpc, &pid -#endif - ); - if (x < 0) { + &wfd, + &hIpc); + if (pid < 0) { debug(84, 1) ("WARNING: Cannot run '%s' process.\n", progname); continue; } hlp->n_running++; hlp->n_active++; srv = cbdataAlloc(helper_stateful_server); -#ifdef _SQUID_MSWIN_ srv->hIpc = hIpc; srv->pid = pid; -#else - srv->pid = x; -#endif srv->flags.reserved = 0; srv->stats.submits = 0; srv->index = k; Index: squid/src/icmp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/icmp.c,v retrieving revision 1.10.2.1 retrieving revision 1.10.2.2 diff -u -r1.10.2.1 -r1.10.2.2 --- squid/src/icmp.c 16 May 2006 21:06:04 -0000 1.10.2.1 +++ squid/src/icmp.c 3 Sep 2006 12:20:11 -0000 1.10.2.2 @@ -1,6 +1,6 @@ /* - * $Id: icmp.c,v 1.10.2.1 2006/05/16 21:06:04 serassio Exp $ + * $Id: icmp.c,v 1.10.2.2 2006/09/03 12:20:11 serassio Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels @@ -50,10 +50,8 @@ static void icmpHandleSourcePing(const struct sockaddr_in *from, const char *buf); #endif -#ifdef _SQUID_MSWIN_ -static HANDLE hIpc; +static void * hIpc; static pid_t pid; -#endif static void icmpSendEcho(struct in_addr to, int opcode, const char *payload, int len) @@ -194,7 +192,6 @@ { #if USE_ICMP const char *args[2]; - int x; int rfd; int wfd; if (strcmp(Config.Program.pinger, "none") == 0) { @@ -203,17 +200,14 @@ } args[0] = "(pinger)"; args[1] = NULL; - x = ipcCreate(IPC_DGRAM, + pid = ipcCreate(IPC_DGRAM, Config.Program.pinger, args, "Pinger Socket", &rfd, - &wfd -#ifdef _SQUID_MSWIN_ - , &hIpc, &pid -#endif - ); - if (x < 0) + &wfd, + &hIpc); + if (pid < 0) return; assert(rfd == wfd); icmp_sock = rfd; Index: squid/src/ipc.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ipc.c,v retrieving revision 1.11.2.7 retrieving revision 1.11.2.8 diff -u -r1.11.2.7 -r1.11.2.8 --- squid/src/ipc.c 1 Sep 2006 19:21:07 -0000 1.11.2.7 +++ squid/src/ipc.c 3 Sep 2006 12:20:11 -0000 1.11.2.8 @@ -1,6 +1,6 @@ /* - * $Id: ipc.c,v 1.11.2.7 2006/09/01 19:21:07 serassio Exp $ + * $Id: ipc.c,v 1.11.2.8 2006/09/03 12:20:11 serassio Exp $ * * DEBUG: section 54 Interprocess Communication * AUTHOR: Duane Wessels @@ -55,8 +55,8 @@ return -1; } -int -ipcCreate(int type, const char *prog, const char *const args[], const char *name, int *rfd, int *wfd) +pid_t +ipcCreate(int type, const char *prog, const char *const args[], const char *name, int *rfd, int *wfd, void **hIpc) { pid_t pid; struct sockaddr_in CS; @@ -84,6 +84,9 @@ *rfd = -1; if (wfd) *wfd = -1; + if (hIpc) + *hIpc = NULL; + if (type == IPC_TCP_SOCKET) { crfd = cwfd = comm_open(SOCK_STREAM, IPPROTO_TCP, Index: squid/src/ipc_win32.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ipc_win32.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/ipc_win32.c 1 Sep 2006 19:21:08 -0000 1.1.2.1 +++ squid/src/ipc_win32.c 3 Sep 2006 12:20:11 -0000 1.1.2.2 @@ -1,6 +1,6 @@ /* - * $Id: ipc_win32.c,v 1.1.2.1 2006/09/01 19:21:08 serassio Exp $ + * $Id: ipc_win32.c,v 1.1.2.2 2006/09/03 12:20:11 serassio Exp $ * * DEBUG: section 54 Interprocess Communication * AUTHOR: Duane Wessels @@ -84,8 +84,8 @@ return -1; } -int -ipcCreate(int type, const char *prog, const char *const args[], const char *name, int *rfd, int *wfd, HANDLE * hIpc, pid_t * ppid) +pid_t +ipcCreate(int type, const char *prog, const char *const args[], const char *name, int *rfd, int *wfd, void ** hIpc) { unsigned long thread; struct ipc_params params; @@ -110,8 +110,6 @@ *wfd = -1; if (hIpc) *hIpc = NULL; - if (ppid) - *ppid = -1; if (WIN32_OS_version != _WIN_OS_WINNT) { getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *) &opt, &optlen); @@ -281,9 +279,7 @@ if (GetExitCodeThread((HANDLE) thread, &ecode) && ecode == STILL_ACTIVE) { if (hIpc) *hIpc = (HANDLE) thread; - if (ppid) - *ppid = pid; - return pwfd; + return pid; } else { CloseHandle((HANDLE) thread); return ipcCloseAllFD(prfd, pwfd, -1, -1); Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.74.2.35 retrieving revision 1.74.2.36 diff -u -r1.74.2.35 -r1.74.2.36 --- squid/src/protos.h 2 Sep 2006 20:30:49 -0000 1.74.2.35 +++ squid/src/protos.h 3 Sep 2006 12:20:11 -0000 1.74.2.36 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.74.2.35 2006/09/02 20:30:49 serassio Exp $ + * $Id: protos.h,v 1.74.2.36 2006/09/03 12:20:11 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1227,16 +1227,13 @@ /* * ipc.c */ -extern int ipcCreate(int type, +extern pid_t ipcCreate(int type, const char *prog, const char *const args[], const char *name, int *rfd, - int *wfd -#ifdef _SQUID_MSWIN_ - ,HANDLE * hIpc, pid_t * ppid -#endif -); + int *wfd, + void **hIpc); /* CacheDigest */ extern CacheDigest *cacheDigestCreate(int capacity, int bpe); Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.81.2.30 retrieving revision 1.81.2.31 diff -u -r1.81.2.30 -r1.81.2.31 --- squid/src/structs.h 2 Sep 2006 20:30:50 -0000 1.81.2.30 +++ squid/src/structs.h 3 Sep 2006 12:20:11 -0000 1.81.2.31 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.81.2.30 2006/09/02 20:30:50 serassio Exp $ + * $Id: structs.h,v 1.81.2.31 2006/09/03 12:20:11 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -2332,9 +2332,7 @@ int uses; unsigned int pending; } stats; -#ifdef _SQUID_MSWIN_ - HANDLE hIpc; -#endif + void *hIpc; }; @@ -2364,9 +2362,7 @@ int releases; } stats; void *data; /* State data used by the calling routines */ -#ifdef _SQUID_MSWIN_ - HANDLE hIpc; -#endif + void *hIpc; }; /* Index: squid/src/unlinkd.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/unlinkd.c,v retrieving revision 1.11.2.4 retrieving revision 1.11.2.5 diff -u -r1.11.2.4 -r1.11.2.5 --- squid/src/unlinkd.c 24 Aug 2006 09:58:27 -0000 1.11.2.4 +++ squid/src/unlinkd.c 3 Sep 2006 12:20:12 -0000 1.11.2.5 @@ -1,6 +1,6 @@ /* - * $Id: unlinkd.c,v 1.11.2.4 2006/08/24 09:58:27 serassio Exp $ + * $Id: unlinkd.c,v 1.11.2.5 2006/09/03 12:20:12 serassio Exp $ * * DEBUG: section 2 Unlink Daemon * AUTHOR: Duane Wessels @@ -74,10 +74,8 @@ static int unlinkd_wfd = -1; static int unlinkd_rfd = -1; -#ifdef _SQUID_MSWIN_ -static HANDLE hIpc; +static void * hIpc; static pid_t pid; -#endif #define UNLINKD_QUEUE_LIMIT 20 @@ -188,7 +186,6 @@ void unlinkdInit(void) { - int x; const char *args[2]; struct timeval slp; args[0] = "(unlinkd)"; @@ -196,21 +193,18 @@ #if (HAVE_POLL && defined(_SQUID_OSF_)) || defined(_SQUID_MSWIN_) /* pipes and poll() don't get along on DUNIX -DW */ /* On Windows select() will fail on a pipe */ - x = ipcCreate(IPC_STREAM, + pid = ipcCreate(IPC_STREAM, #else /* We currently need to use FIFO.. see below */ - x = ipcCreate(IPC_FIFO, + pid = ipcCreate(IPC_FIFO, #endif Config.Program.unlinkd, args, "unlinkd", &unlinkd_rfd, - &unlinkd_wfd -#ifdef _SQUID_MSWIN_ - , &hIpc, &pid -#endif - ); - if (x < 0) + &unlinkd_wfd, + &hIpc); + if (pid < 0) fatal("Failed to create unlinkd subprocess"); slp.tv_sec = 0; slp.tv_usec = 250000; Index: squid/src/fs/diskd/store_dir_diskd.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/diskd/store_dir_diskd.c,v retrieving revision 1.45.2.8 retrieving revision 1.45.2.9 diff -u -r1.45.2.8 -r1.45.2.9 --- squid/src/fs/diskd/store_dir_diskd.c 3 Aug 2006 19:08:58 -0000 1.45.2.8 +++ squid/src/fs/diskd/store_dir_diskd.c 3 Sep 2006 12:20:12 -0000 1.45.2.9 @@ -375,7 +375,7 @@ storeDiskdDirInit(SwapDir * sd) { static int started_clean_event = 0; - int x; + pid_t pid; int i; int ikey; const char *args[5]; @@ -426,13 +426,14 @@ args[2] = skey2; args[3] = skey3; args[4] = NULL; - x = ipcCreate(IPC_STREAM, + pid = ipcCreate(IPC_STREAM, Config.Program.diskd, args, "diskd", &diskdinfo->rfd, - &diskdinfo->wfd); - if (x < 0) + &diskdinfo->wfd, + &diskdinfo->hIpc); + if (pid < 0) fatalf("execl: %s", Config.Program.diskd); fd_note(diskdinfo->rfd, "diskd -> squid health monitor"); fd_note(diskdinfo->wfd, "squid -> diskd health monitor"); Index: squid/src/fs/diskd/store_diskd.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/diskd/store_diskd.h,v retrieving revision 1.8.8.3 retrieving revision 1.8.8.4 diff -u -r1.8.8.3 -r1.8.8.4 --- squid/src/fs/diskd/store_diskd.h 31 Jul 2006 10:22:03 -0000 1.8.8.3 +++ squid/src/fs/diskd/store_diskd.h 3 Sep 2006 12:20:12 -0000 1.8.8.4 @@ -25,6 +25,7 @@ int rmsgid; int rfd; int wfd; + void * hIpc; int away; struct { char *buf;