/*
- * $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
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;
void
authenticateShutdown(void)
{
- if (authenticators)
+ if (authenticators) {
helperShutdown(authenticators);
+ helperFree(authenticators);
+ authenticators = NULL;
+ }
}
/*
- * $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
{
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);
return;
helperShutdown(dnsservers);
wordlistDestroy(&dnsservers->cmdline);
+ helperFree(dnsservers);
+ dnsservers = NULL;
}
void
#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);
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);
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);
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) {
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;
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);
}
/*
- * $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/
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
/*
- * $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
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;
return;
helperShutdown(redirectors);
wordlistDestroy(&redirectors->cmdline);
+ helperFree(redirectors);
+ redirectors = NULL;
}
/*
- * $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/
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;