]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
fixed helper restart bugs
authorwessels <>
Sat, 17 Oct 1998 02:02:45 +0000 (02:02 +0000)
committerwessels <>
Sat, 17 Oct 1998 02:02:45 +0000 (02:02 +0000)
src/authenticate.cc
src/dns.cc
src/helper.cc
src/protos.h
src/redirect.cc
src/structs.h

index 78db7bb89bb7e553b85dfc406573833d735119ee..a45fe0344472ba894328cb8af1e5267e39de03a0 100644 (file)
@@ -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;
+    }
 }
index e773b17a62c135322357d15b66c2d593522039ce..9c9b380fd181d28e1919c38909530c9398924832 100644 (file)
@@ -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
index 6ff48935a544f9e808c4bb1d7fe575f19212cbd8..2a10cefe82173f2c95b9d667df16a4a323e7e1c0 100644 (file)
@@ -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);
 }
 
index 33b5b55ebca8eb6086fb2d668cf0f966f4fb6102..1a6a33198cd79af51553b8fd4ce88d71cc3249a4 100644 (file)
@@ -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
index 0f1bcddcce78a0b0ce580b9587313af6309813fe..b9dc922bb584c3003405a378b33425ab21853efb 100644 (file)
@@ -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;
 }
index 16d8c83b3b2aacd058101192a93b5453a3e4d930..068e74e244c2f108bb9e01dbace6fff39338bc3d 100644 (file)
@@ -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;