From: wessels <> Date: Sat, 17 Oct 1998 02:02:45 +0000 (+0000) Subject: fixed helper restart bugs X-Git-Tag: SQUID_3_0_PRE1~2566 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1f5f60dda027f22ffe0efd4e0eb20466b4c581bd;p=thirdparty%2Fsquid.git fixed helper restart bugs --- diff --git a/src/authenticate.cc b/src/authenticate.cc index 78db7bb89b..a45fe03444 100644 --- a/src/authenticate.cc +++ b/src/authenticate.cc @@ -1,6 +1,6 @@ /* - * $Id: authenticate.cc,v 1.5 1998/10/10 14:57:36 wessels Exp $ + * $Id: authenticate.cc,v 1.6 1998/10/16 20:02:45 wessels Exp $ * * DEBUG: section 29 Authenticator * AUTHOR: Duane Wessels @@ -105,11 +105,10 @@ void authenticateInit(void) { static int init = 0; - safe_free(authenticators); + assert(authenticators == NULL); if (!Config.Program.authenticate) return; - authenticators = xcalloc(1, sizeof(*authenticators)); - authenticators->id_name = "authenticator"; + authenticators = helperCreate("authenticator"); authenticators->cmdline = Config.Program.authenticate; authenticators->n_to_start = Config.authenticateChildren; authenticators->ipc_type = IPC_TCP_SOCKET; @@ -125,6 +124,9 @@ authenticateInit(void) void authenticateShutdown(void) { - if (authenticators) + if (authenticators) { helperShutdown(authenticators); + helperFree(authenticators); + authenticators = NULL; + } } diff --git a/src/dns.cc b/src/dns.cc index e773b17a62..9c9b380fd1 100644 --- a/src/dns.cc +++ b/src/dns.cc @@ -1,6 +1,6 @@ /* - * $Id: dns.cc,v 1.68 1998/10/13 23:15:01 wessels Exp $ + * $Id: dns.cc,v 1.69 1998/10/16 20:02:45 wessels Exp $ * * DEBUG: section 34 Dnsserver interface * AUTHOR: Harvest Derived @@ -49,11 +49,10 @@ dnsInit(void) { static int init = 0; wordlist *w; - safe_free(dnsservers); + assert(dnsservers == NULL); if (!Config.Program.dnsserver) return; - dnsservers = xcalloc(1, sizeof(*dnsservers)); - dnsservers->id_name = "dnsserver"; + dnsservers = helperCreate("dnsserver"); dnsservers->n_to_start = Config.dnsChildren; dnsservers->ipc_type = IPC_TCP_SOCKET; wordlistAdd(&dnsservers->cmdline, Config.Program.dnsserver); @@ -80,6 +79,8 @@ dnsShutdown(void) return; helperShutdown(dnsservers); wordlistDestroy(&dnsservers->cmdline); + helperFree(dnsservers); + dnsservers = NULL; } void diff --git a/src/helper.cc b/src/helper.cc index 6ff48935a5..2a10cefe82 100644 --- a/src/helper.cc +++ b/src/helper.cc @@ -3,7 +3,7 @@ #define HELPER_MAX_ARGS 64 static PF helperHandleRead; -static PF helperStateFree; +static PF helperServerFree; static void Enqueue(helper * hlp, helper_request *); static helper_request *Dequeue(helper * hlp); static helper_server *GetFirstAvailable(helper * hlp); @@ -69,6 +69,7 @@ helperOpenServers(helper * hlp) srv->buf_sz = 8192; srv->offset = 0; srv->parent = hlp; + cbdataLock(hlp); /* lock because of the parent backlink */ dlinkAddTail(srv, &srv->link, &hlp->servers); if (rfd == wfd) { snprintf(fd_note_buf, FD_DESC_SZ, "%s #%d", shortname, k + 1); @@ -82,7 +83,7 @@ helperOpenServers(helper * hlp) commSetNonBlocking(rfd); if (wfd != rfd) commSetNonBlocking(wfd); - comm_add_close_handler(rfd, helperStateFree, srv); + comm_add_close_handler(rfd, helperServerFree, srv); } safe_free(shortname); safe_free(procname); @@ -158,10 +159,10 @@ helperShutdown(helper * hlp) hlp->id_name, srv->index + 1); continue; } + srv->flags.shutdown = 1; /* request it to shut itself down */ if (srv->flags.busy) { debug(34, 3) ("helperShutdown: %s #%d is BUSY.\n", hlp->id_name, srv->index + 1); - srv->flags.shutdown = 1; continue; } if (srv->flags.closing) { @@ -169,17 +170,33 @@ helperShutdown(helper * hlp) hlp->id_name, srv->index + 1); continue; } - comm_close(srv->wfd); srv->flags.closing = 1; + comm_close(srv->wfd); } } +helper * +helperCreate(const char *name) +{ + helper *hlp = xcalloc(1, sizeof(*hlp)); + cbdataAdd(hlp, MEM_NONE); + hlp->id_name = name; + return hlp; +} + +void +helperFree(helper * hlp) +{ + /* note, don't free hlp->name, it probably points to static memory */ + cbdataFree(hlp); +} + /* ====================================================================== */ /* LOCAL FUNCTIONS */ /* ====================================================================== */ static void -helperStateFree(int fd, void *data) +helperServerFree(int fd, void *data) { helper_server *srv = data; helper *hlp = srv->parent; @@ -193,12 +210,14 @@ helperStateFree(int fd, void *data) dlinkDelete(&srv->link, &hlp->servers); hlp->n_running--; assert(hlp->n_running >= 0); - if (!shutting_down && !reconfiguring) { - debug(34, 0) ("WARNING: %s #%d (FD %d) exited\n", + if (!srv->flags.shutdown) { + debug(34, 0) ("WARNING: %s #%d (FD %d) exited\n", hlp->id_name, srv->index + 1, fd); - if (hlp->n_running < hlp->n_to_start / 2) + assert(hlp->n_running >= hlp->n_to_start / 2); + if (hlp->n_running < hlp->n_to_start / 2) fatalf("Too few %s processes are running", hlp->id_name); } + cbdataUnlock(srv->parent); cbdataFree(srv); } diff --git a/src/protos.h b/src/protos.h index 33b5b55ebc..1a6a33198c 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.279 1998/10/15 23:40:06 wessels Exp $ + * $Id: protos.h,v 1.280 1998/10/16 20:02:47 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -1079,10 +1079,13 @@ extern void delaySetStoreClient(StoreEntry * e, void *data, delay_id delay_id); extern int delayBytesWanted(delay_id d, int min, int max); #endif +/* helper.c */ extern void helperOpenServers(helper * hlp); extern void helperSubmit(helper * hlp, const char *buf, HLPCB * callback, void *data); extern void helperStats(StoreEntry * sentry, helper * hlp); extern void helperShutdown(helper * hlp); +extern helper *helperCreate(const char *); +extern void helperFree(helper *); /* * prototypes for system functions missing from system includes diff --git a/src/redirect.cc b/src/redirect.cc index 0f1bcddcce..b9dc922bb5 100644 --- a/src/redirect.cc +++ b/src/redirect.cc @@ -1,6 +1,6 @@ /* - * $Id: redirect.cc,v 1.72 1998/10/14 20:14:04 wessels Exp $ + * $Id: redirect.cc,v 1.73 1998/10/16 20:02:48 wessels Exp $ * * DEBUG: section 29 Redirector * AUTHOR: Duane Wessels @@ -126,11 +126,10 @@ void redirectInit(void) { static int init = 0; - safe_free(redirectors); + assert(redirectors == NULL); if (!Config.Program.redirect) return; - redirectors = xcalloc(1, sizeof(*redirectors)); - redirectors->id_name = "redirector"; + redirectors = helperCreate("redirector"); wordlistAdd(&redirectors->cmdline, Config.Program.redirect); redirectors->n_to_start = Config.redirectChildren; redirectors->ipc_type = IPC_TCP_SOCKET; @@ -150,4 +149,6 @@ redirectShutdown(void) return; helperShutdown(redirectors); wordlistDestroy(&redirectors->cmdline); + helperFree(redirectors); + redirectors = NULL; } diff --git a/src/structs.h b/src/structs.h index 16d8c83b3b..068e74e244 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.242 1998/10/15 23:40:07 wessels Exp $ + * $Id: structs.h,v 1.243 1998/10/16 20:02:49 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -1622,7 +1622,7 @@ struct _helper { wordlist *cmdline; dlink_list servers; dlink_list queue; - char *id_name; + const char *id_name; int n_to_start; int n_running; int ipc_type;