From: wessels <> Date: Sun, 23 Nov 1997 13:52:36 +0000 (+0000) Subject: Making it so reconfigure doesn't require waiting for all current X-Git-Tag: SQUID_3_0_PRE1~4480 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e144eae409917e8284f6af245e24dd78d3f48548;p=thirdparty%2Fsquid.git Making it so reconfigure doesn't require waiting for all current connections to finish --- diff --git a/src/comm.cc b/src/comm.cc index 12a54b9f95..fd5bc3435a 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.205 1997/11/15 00:14:47 wessels Exp $ + * $Id: comm.cc,v 1.206 1997/11/23 06:52:36 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -111,10 +111,6 @@ #include #endif -/* Block processing new client requests (accepts on ascii port) when we start - * running shy of free file descriptors. For example, under SunOS, we'll keep - * 64 file descriptors free for disk-i/o and connections to remote servers */ - #define min(x,y) ((x)<(y)? (x) : (y)) #define max(a,b) ((a)>(b)? (a) : (b)) @@ -829,6 +825,7 @@ comm_poll(time_t sec) #if !ALARM_UPDATES_TIME getCurrentTime(); #endif +#if 0 if (shutdown_pending || reconfigure_pending) { serverConnectionsClose(); dnsShutdownServers(); @@ -841,6 +838,7 @@ comm_poll(time_t sec) setSocketShutdownLifetimes(Config.shutdownLifetime); else setSocketShutdownLifetimes(1); +#endif } nfds = 0; maxfd = Biggest_FD + 1; diff --git a/src/dns.cc b/src/dns.cc index acd8ec02d7..aa4c3e7287 100644 --- a/src/dns.cc +++ b/src/dns.cc @@ -1,6 +1,6 @@ /* - * $Id: dns.cc,v 1.45 1997/11/12 00:08:48 wessels Exp $ + * $Id: dns.cc,v 1.46 1997/11/23 06:52:37 wessels Exp $ * * DEBUG: section 34 Dnsserver interface * AUTHOR: Harvest Derived @@ -232,10 +232,8 @@ dnsFreeMemory(void) int k; /* free old structures if present */ if (dns_child_table) { - for (k = 0; k < NDnsServersAlloc; k++) { - safe_free(dns_child_table[k]->ip_inbuf); - safe_free(dns_child_table[k]); - } + for (k = 0; k < NDnsServersAlloc; k++) + cbdataFree(dns_child_table[k]); safe_free(dns_child_table); } } @@ -255,6 +253,7 @@ dnsOpenServers(void) NDnsServersAlloc = 0; for (k = 0; k < N; k++) { dns_child_table[k] = xcalloc(1, sizeof(dnsserver_t)); + cbdataAdd(dns_child_table[k]); if ((dnssocket = dnsOpenServer(prg)) < 0) { debug(34, 1) ("dnsOpenServers: WARNING: Failed to start 'dnsserver' #%d.\n", k + 1); EBIT_CLR(dns_child_table[k]->flags, HELPER_ALIVE); @@ -272,8 +271,6 @@ dnsOpenServers(void) dns_child_table[k]->dispatch_time = current_time; dns_child_table[k]->size = DNS_INBUF_SZ - 1; dns_child_table[k]->offset = 0; - dns_child_table[k]->ip_inbuf = xcalloc(DNS_INBUF_SZ, 1); - /* update fd_stat */ if ((s = strrchr(prg, '/'))) s++; else @@ -314,10 +311,11 @@ dnsStats(StoreEntry * sentry) for (k = 0; k < NDnsServersAlloc; k++) { dns = *(dns_child_table + k); storeAppendPrintf(sentry, "{dnsserver #%d:}\n", k + 1); - storeAppendPrintf(sentry, "{ Flags: %c%c%c}\n", + storeAppendPrintf(sentry, "{ Flags: %c%c%c%c}\n", EBIT_TEST(dns->flags, HELPER_ALIVE) ? 'A' : ' ', EBIT_TEST(dns->flags, HELPER_BUSY) ? 'B' : ' ', - EBIT_TEST(dns->flags, HELPER_CLOSING) ? 'C' : ' '); + EBIT_TEST(dns->flags, HELPER_CLOSING) ? 'C' : ' ', + EBIT_TEST(dns->flags, HELPER_SHUTDOWN) ? 'S' : ' '); storeAppendPrintf(sentry, "{ FDs (in/out): %d/%d}\n", dns->inpipe, dns->outpipe); storeAppendPrintf(sentry, "{ Alive since: %s}\n", @@ -340,9 +338,8 @@ dnsStats(StoreEntry * sentry) void dnsShutdownServers(void) { - dnsserver_t *dnsData = NULL; + dnsserver_t *dns = NULL; int k; - static char *shutdown_cmd = "$shutdown\n"; debug(34, 3) ("dnsShutdownServers:\n"); @@ -350,48 +347,56 @@ dnsShutdownServers(void) if (fqdncacheQueueDrain() || k) return; for (k = 0; k < NDnsServersAlloc; k++) { - dnsData = *(dns_child_table + k); - if (!EBIT_TEST(dnsData->flags, HELPER_ALIVE)) { - debug(34, 3) ("dnsShutdownServers: #%d is NOT ALIVE.\n", dnsData->id); + dns = *(dns_child_table + k); + if (!EBIT_TEST(dns->flags, HELPER_ALIVE)) { + debug(34, 3) ("dnsShutdownServers: #%d is NOT ALIVE.\n", dns->id); continue; } - if (EBIT_TEST(dnsData->flags, HELPER_BUSY)) { - debug(34, 3) ("dnsShutdownServers: #%d is BUSY.\n", dnsData->id); + if (EBIT_TEST(dns->flags, HELPER_BUSY)) { + debug(34, 3) ("dnsShutdownServers: #%d is BUSY.\n", dns->id); + EBIT_SET(dns->flags, HELPER_SHUTDOWN); continue; } - if (EBIT_TEST(dnsData->flags, HELPER_CLOSING)) { - debug(34, 3) ("dnsShutdownServers: #%d is CLOSING.\n", dnsData->id); + if (EBIT_TEST(dns->flags, HELPER_CLOSING)) { + debug(34, 3) ("dnsShutdownServers: #%d is CLOSING.\n", dns->id); continue; } - debug(34, 3) ("dnsShutdownServers: sending '$shutdown' to dnsserver #%d\n", dnsData->id); - debug(34, 3) ("dnsShutdownServers: --> FD %d\n", dnsData->outpipe); - comm_write(dnsData->outpipe, - xstrdup(shutdown_cmd), - strlen(shutdown_cmd), - NULL, /* Handler */ - NULL, /* Handler-data */ - xfree); - commSetSelect(dnsData->inpipe, - COMM_SELECT_READ, - dnsShutdownRead, - dnsData, - 0); - EBIT_SET(dnsData->flags, HELPER_CLOSING); + dnsShutdownServer(dns); } } +void +dnsShutdownServer(dnsserver_t * dns) +{ + static char *shutdown_cmd = "$shutdown\n"; + debug(34, 3) ("dnsShutdownServer: sending '$shutdown' to dnsserver #%d\n", + dns->id); + debug(34, 3) ("dnsShutdownServer: --> FD %d\n", dns->outpipe); + cbdataLock(dns); + comm_write(dns->outpipe, + xstrdup(shutdown_cmd), + strlen(shutdown_cmd), + NULL, /* Handler */ + NULL, /* Handler-data */ + xfree); + commSetSelect(dns->inpipe, + COMM_SELECT_READ, + dnsShutdownRead, + dns, + 0); + EBIT_SET(dns->flags, HELPER_CLOSING); +} + static void dnsShutdownRead(int fd, void *data) { - dnsserver_t *dnsData = data; - debug(14, EBIT_TEST(dnsData->flags, HELPER_CLOSING) ? 5 : 1) + dnsserver_t *dns = data; + debug(14, EBIT_TEST(dns->flags, HELPER_CLOSING) ? 5 : 1) ("FD %d: Connection from DNSSERVER #%d is closed, disabling\n", fd, - dnsData->id); - dnsData->flags = 0; - commSetSelect(fd, - COMM_SELECT_WRITE, - NULL, - NULL, 0); + dns->id); + dns->flags = 0; + commSetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); + cbdataUnlock(dns); comm_close(fd); } diff --git a/src/enums.h b/src/enums.h index 38b6da419e..f310aefe17 100644 --- a/src/enums.h +++ b/src/enums.h @@ -350,7 +350,8 @@ enum { enum { HELPER_ALIVE, HELPER_BUSY, - HELPER_CLOSING + HELPER_CLOSING, + HELPER_SHUTDOWN }; enum { diff --git a/src/fqdncache.cc b/src/fqdncache.cc index f4f08f69e9..bea0365b34 100644 --- a/src/fqdncache.cc +++ b/src/fqdncache.cc @@ -1,6 +1,6 @@ /* - * $Id: fqdncache.cc,v 1.67 1997/11/14 17:21:17 wessels Exp $ + * $Id: fqdncache.cc,v 1.68 1997/11/23 06:52:38 wessels Exp $ * * DEBUG: section 35 FQDN Cache * AUTHOR: Harvest Derived @@ -204,26 +204,11 @@ fqdncacheDequeue(void) static void fqdncache_release(fqdncache_entry * f) { - hash_link *table_entry = NULL; int k; - - if ((table_entry = hash_lookup(fqdn_table, f->name)) == NULL) { - debug(35, 0) ("fqdncache_release: Could not find key '%s'\n", f->name); - return; - } - if (f != (fqdncache_entry *) table_entry) - fatal_dump("fqdncache_release: f != table_entry!"); - if (f->status == FQDN_PENDING) { - debug(35, 1) ("fqdncache_release: Someone called on a PENDING entry\n"); - return; - } - if (f->status == FQDN_DISPATCHED) { - debug(35, 1) ("fqdncache_release: Someone called on a DISPATCHED entry\n"); - return; - } - if (f->pending_head) - fatal_dump("fqdncache_release: still have pending clients"); - if (hash_remove_link(fqdn_table, table_entry)) { + assert(f->status != FQDN_PENDING); + assert(f->status != FQDN_DISPATCHED); + assert(f->pending_head == NULL); + if (hash_remove_link(fqdn_table, (hash_link *) f)) { debug(35, 0) ("fqdncache_release: hash_remove_link() failed for '%s'\n", f->name); return; @@ -238,7 +223,6 @@ fqdncache_release(fqdncache_entry * f) safe_free(f->error_message); safe_free(f); --meta_data.fqdncache_count; - return; } /* return match for given name */ @@ -406,8 +390,7 @@ static fqdncache_entry * fqdncacheAddNew(const char *name, const struct hostent *hp, fqdncache_status_t status) { fqdncache_entry *f; - if (fqdncache_get(name)) - fatal_dump("fqdncacheAddNew: somebody adding a duplicate!"); + assert(fqdncache_get(name) == NULL); debug(14, 10) ("fqdncacheAddNew: Adding '%s', status=%c\n", name, fqdncache_status_char[status]); @@ -983,9 +966,15 @@ fqdncache_restart(void) continue; if (this->status == FQDN_NEGATIVE_CACHED) continue; +#if DONT /* else its PENDING or DISPATCHED; there are no dnsservers * running, so abort it */ this->status = FQDN_NEGATIVE_CACHED; fqdncache_release(this); +#endif } + fqdncache_high = (long) (((float) MAX_FQDN * + (float) FQDN_HIGH_WATER) / (float) 100); + fqdncache_low = (long) (((float) MAX_FQDN * + (float) FQDN_LOW_WATER) / (float) 100); } diff --git a/src/ipcache.cc b/src/ipcache.cc index 0a4b122cf6..0b2a03db89 100644 --- a/src/ipcache.cc +++ b/src/ipcache.cc @@ -1,6 +1,6 @@ /* - * $Id: ipcache.cc,v 1.143 1997/11/14 17:21:22 wessels Exp $ + * $Id: ipcache.cc,v 1.144 1997/11/23 06:52:38 wessels Exp $ * * DEBUG: section 14 IP Cache * AUTHOR: Harvest Derived @@ -592,10 +592,7 @@ ipcache_dnsHandleRead(int fd, void *data) ("FD %d: Connection from DNSSERVER #%d is closed, disabling\n", fd, dnsData->id); dnsData->flags = 0; - commSetSelect(fd, - COMM_SELECT_WRITE, - NULL, - NULL, 0); + commSetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); comm_close(fd); return; } @@ -604,12 +601,8 @@ ipcache_dnsHandleRead(int fd, void *data) dnsData->offset += len; dnsData->ip_inbuf[dnsData->offset] = '\0'; i = dnsData->data; - if (i == NULL) { - debug_trap("NULL ipcache_entry"); - return; - } - if (i->status != IP_DISPATCHED) - fatal_dump("ipcache_dnsHandleRead: bad status"); + assert(i != NULL); + assert(i->status == IP_DISPATCHED); if (strstr(dnsData->ip_inbuf, "$end\n")) { /* end of record found */ IpcacheStats.avg_svc_time = intAverage(IpcacheStats.avg_svc_time, @@ -638,6 +631,9 @@ ipcache_dnsHandleRead(int fd, void *data) if (dnsData->offset == 0) { dnsData->data = NULL; EBIT_CLR(dnsData->flags, HELPER_BUSY); + if (EBIT_TEST(dnsData->flags, HELPER_SHUTDOWN)) + dnsShutdownServer(dnsData); + cbdataUnlock(dnsData); } ipcacheNudgeQueue(); } @@ -745,6 +741,7 @@ ipcache_dnsDispatch(dnsserver_t * dns, ipcache_entry * i) EBIT_SET(dns->flags, HELPER_BUSY); dns->data = i; i->status = IP_DISPATCHED; + cbdataLock(dns); comm_write(dns->outpipe, buf, strlen(buf), @@ -1155,10 +1152,12 @@ ipcache_restart(void) continue; if (this->status == IP_NEGATIVE_CACHED) continue; +#if DONT /* else its PENDING or DISPATCHED; there are no dnsservers * running, so abort it */ this->status = IP_NEGATIVE_CACHED; ipcache_release(this); +#endif } /* recalculate these while we're at it */ ipcache_high = (long) (((float) Config.ipcache.size * diff --git a/src/structs.h b/src/structs.h index 7e885e76d4..75ca8dbdb5 100644 --- a/src/structs.h +++ b/src/structs.h @@ -292,7 +292,7 @@ struct _dnsserver_t { time_t answer; off_t offset; size_t size; - char *ip_inbuf; + char ip_inbuf[DNS_INBUF_SZ]; struct timeval dispatch_time; void *data; }; @@ -890,6 +890,7 @@ struct _ErrorState { char *request; char *reply; } ftp; + char *request_hdrs; }; struct _StatCounters {