/*
- * $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
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);
}
}
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);
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
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",
void
dnsShutdownServers(void)
{
- dnsserver_t *dnsData = NULL;
+ dnsserver_t *dns = NULL;
int k;
- static char *shutdown_cmd = "$shutdown\n";
debug(34, 3) ("dnsShutdownServers:\n");
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);
}
/*
- * $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
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;
safe_free(f->error_message);
safe_free(f);
--meta_data.fqdncache_count;
- return;
}
/* return match for given name */
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]);
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);
}
/*
- * $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
("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;
}
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,
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();
}
EBIT_SET(dns->flags, HELPER_BUSY);
dns->data = i;
i->status = IP_DISPATCHED;
+ cbdataLock(dns);
comm_write(dns->outpipe,
buf,
strlen(buf),
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 *