/*
- * $Id: comm.cc,v 1.278 1998/07/22 20:37:11 wessels Exp $
+ * $Id: comm.cc,v 1.279 1998/07/25 00:16:23 wessels Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
}
/* NOTREACHED */
}
+
+void
+commCloseAllSockets(void)
+{
+ int fd;
+ fde *F = NULL;
+ PF *callback;
+ for (fd = 0; fd <= Biggest_FD; fd++) {
+ F = &fd_table[fd];
+ if (F->open != FD_OPEN)
+ continue;
+ if (F->type != FD_SOCKET)
+ continue;
+ if (F->timeout_handler) {
+ debug(5, 5) ("commCloseAllSockets: FD %d: Calling timeout handler\n",
+ fd);
+ callback = F->timeout_handler;
+ F->timeout_handler = NULL;
+ callback(fd, F->timeout_data);
+ } else {
+ debug(5, 5) ("commCloseAllSockets: FD %d: calling comm_close()\n", fd);
+ comm_close(fd);
+ }
+ }
+}
/*
- * $Id: comm_select.cc,v 1.2 1998/07/22 20:37:11 wessels Exp $
+ * $Id: comm_select.cc,v 1.3 1998/07/25 00:16:25 wessels Exp $
*
* DEBUG: section 5 Socket Functions
*
#if !ALARM_UPDATES_TIME
getCurrentTime();
#endif
- if (shutting_down) {
- serverConnectionsClose();
- dnsShutdownServers();
- redirectShutdownServers();
- /* shutting_down will be set to
- * +1 for SIGTERM
- * -1 for SIGINT */
- if (shutting_down > 0)
- setSocketShutdownLifetimes(Config.shutdownLifetime);
- else
- setSocketShutdownLifetimes(1);
- }
#if USE_ASYNC_IO
aioCheckCallbacks();
#endif
nfds++;
}
}
- if (shutting_down)
- debug(5, 2) ("comm_poll: Still waiting on %d FDs\n", nfds);
- if (nfds == 0)
+ if (nfds == 0) {
+ assert(shutting_down);
return COMM_SHUTDOWN;
+ }
if (msec > MAX_POLL_TIME)
msec = MAX_POLL_TIME;
for (;;) {
#endif
FD_ZERO(&readfds);
FD_ZERO(&writefds);
- if (shutting_down) {
- serverConnectionsClose();
- dnsShutdownServers();
- redirectShutdownServers();
- /* shutting_down will be set to
- * +1 for SIGTERM
- * -1 for SIGINT */
- if (shutting_down > 0)
- setSocketShutdownLifetimes(Config.shutdownLifetime);
- else
- setSocketShutdownLifetimes(1);
- }
if (commCheckICPIncoming)
comm_select_icp_incoming();
if (commCheckHTTPIncoming)
FD_SET(i, &writefds);
}
}
- if (shutting_down)
- debug(5, 2) ("comm_select: Still waiting on %d FDs\n", nfds);
- if (nfds == 0)
+ if (nfds == 0) {
+ assert(shutting_down);
return COMM_SHUTDOWN;
+ }
if (msec > MAX_POLL_TIME)
msec = MAX_POLL_TIME;
for (;;) {
/*
- * $Id: dns.cc,v 1.61 1998/07/22 20:37:14 wessels Exp $
+ * $Id: dns.cc,v 1.62 1998/07/25 00:16:26 wessels Exp $
*
* DEBUG: section 34 Dnsserver interface
* AUTHOR: Harvest Derived
}
void
-dnsShutdownServers(void)
+dnsShutdownServers(void *notused)
{
dnsserver_t *dns = NULL;
int k;
+ int na = 0;
debug(34, 3) ("dnsShutdownServers:\n");
for (k = 0; k < NDnsServersAlloc; k++) {
dns = *(dns_child_table + k);
if (EBIT_TEST(dns->flags, HELPER_BUSY)) {
debug(34, 3) ("dnsShutdownServers: #%d is BUSY.\n", dns->id);
EBIT_SET(dns->flags, HELPER_SHUTDOWN);
+ na++;
continue;
}
if (EBIT_TEST(dns->flags, HELPER_CLOSING)) {
}
dnsShutdownServer(dns);
}
+ if (na)
+ eventAdd("dnsShutdownServers", dnsShutdownServers, NULL, 1.0, 1);
}
void
/*
- * $Id: main.cc,v 1.261 1998/07/24 16:14:13 wessels Exp $
+ * $Id: main.cc,v 1.262 1998/07/25 00:16:27 wessels Exp $
*
* DEBUG: section 1 Startup and Main Loop
* AUTHOR: Harvest Derived
static void serverConnectionsOpen(void);
static void watch_child(char **);
static void setEffectiveUser(void);
-static void normal_shutdown(void);
#if MEM_GEN_TRACE
extern void log_trace_done();
extern void log_trace_init(char *);
#endif
-static EVH force_shutdown;
+static EVH SquidShutdown;
static void
usage(void)
void
serverConnectionsClose(void)
{
- /*
- * NOTE, this function will be called repeatedly while shutdown
- * is pending
- */
+ assert(shutting_down);
clientHttpConnectionsClose();
icpConnectionShutdown();
#if USE_HTCP
#ifdef SQUID_SNMP
snmpConnectionClose();
#endif
- dnsShutdownServers();
- redirectShutdownServers();
+ dnsShutdownServers(NULL);
+ redirectShutdownServers(NULL);
storeDirCloseSwapLogs();
errorFree();
parseConfigFile(ConfigFile);
wait);
do_shutdown = 0;
shutting_down = 1;
- eventAdd("force_shutdown", force_shutdown,
- NULL, (double) (wait+1), 1);
+ serverConnectionsClose();
+ eventAdd("dnsShutdownServers", dnsShutdownServers, NULL, 0.0, 1);
+ eventAdd("redirectShutdownServers", redirectShutdownServers, NULL, 0.0, 1);
+ eventAdd("SquidShutdown", SquidShutdown, NULL, (double) (wait + 1), 1);
}
eventRun();
if ((loop_delay = eventNextTime()) < 0)
if (errcount == 10)
fatal_dump("Select Loop failed!");
break;
- case COMM_SHUTDOWN:
- /* delayed close so we can transmit while shutdown pending */
- icpConnectionClose();
-#if USE_HTCP
- htcpSocketClose();
-#endif
-#ifdef SQUID_SNMP
- snmpConnectionClose();
-#endif
- if (shutting_down) {
- normal_shutdown();
- } else {
- fatal_dump("MAIN: Unexpected SHUTDOWN from comm_select.");
- }
- break;
case COMM_TIMEOUT:
break;
+ case COMM_SHUTDOWN:
+ SquidShutdown(NULL);
+ break;
default:
fatal_dump("MAIN: Internal error -- this should never happen.");
break;
}
static void
-normal_shutdown(void)
+SquidShutdown(void *unused)
{
debug(1, 1) ("Shutting down...\n");
if (Config.pidFilename && strcmp(Config.pidFilename, "none")) {
safeunlink(Config.pidFilename, 0);
leave_suid();
}
+ icpConnectionClose();
+#if USE_HTCP
+ htcpSocketClose();
+#endif
+#ifdef SQUID_SNMP
+ snmpConnectionClose();
+#endif
releaseServerSockets();
+ commCloseAllSockets();
unlinkdClose();
storeDirWriteCleanLogs(0);
PrintRusage();
#if MEM_GEN_TRACE
log_trace_done();
#endif
-
debug(1, 0) ("Squid Cache (Version %s): Exiting normally.\n",
version_string);
fclose(debug_log);
exit(0);
}
-
-static void
-force_shutdown(void *unused)
-{
- fdDumpOpen();
- fatal_dump("Shutdown procedure failed");
-}
/*
- * $Id: protos.h,v 1.241 1998/07/23 19:57:52 wessels Exp $
+ * $Id: protos.h,v 1.242 1998/07/25 00:16:28 wessels Exp $
*
*
* SQUID Internet Object Cache http://squid.nlanr.net/Squid/
extern int commSetTimeout(int fd, int, PF *, void *);
extern void commSetDefer(int fd, DEFER * func, void *);
extern int ignoreErrno(int);
+extern void commCloseAllSockets(void);
/*
* comm_select.c
extern void disk_init(void);
extern int diskWriteIsComplete(int);
-extern void dnsShutdownServers(void);
+extern void dnsShutdownServers(void *);
extern void dnsShutdownServer(dnsserver_t * dns);
extern void dnsOpenServers(void);
extern dnsserver_t *dnsGetFirstAvailable(void);
extern const ipcache_addrs *ipcache_gethostbyname(const char *, int flags);
extern void ipcacheInvalidate(const char *);
extern void ipcacheReleaseInvalid(const char *);
-extern void ipcacheShutdownServers(void);
extern void ipcache_init(void);
extern void stat_ipcache_get(StoreEntry *);
extern int ipcacheQueueDrain(void);
extern void redirectStart(clientHttpRequest *, RH *, void *);
extern void redirectOpenServers(void);
-extern void redirectShutdownServers(void);
+extern void redirectShutdownServers(void *);
extern void redirectStats(StoreEntry *);
extern int redirectUnregister(const char *url, void *);
extern void redirectFreeMemory(void);
/*
- * $Id: redirect.cc,v 1.63 1998/07/22 20:37:44 wessels Exp $
+ * $Id: redirect.cc,v 1.64 1998/07/25 00:16:29 wessels Exp $
*
* DEBUG: section 29 Redirector
* AUTHOR: Duane Wessels
}
void
-redirectShutdownServers(void)
+redirectShutdownServers(void *unused)
{
redirector_t *redirect = NULL;
redirectStateData *r = NULL;
int k;
+ int na = 0;
if (Config.Program.redirect == NULL)
return;
if (redirectQueueHead) {
redirect = *(redirect_child_table + k);
if (!EBIT_TEST(redirect->flags, HELPER_ALIVE))
continue;
- if (EBIT_TEST(redirect->flags, HELPER_BUSY))
- continue;
if (EBIT_TEST(redirect->flags, HELPER_CLOSING))
continue;
+ if (EBIT_TEST(redirect->flags, HELPER_BUSY)) {
+ na++;
+ continue;
+ }
debug(29, 3) ("redirectShutdownServers: closing redirector #%d, FD %d\n",
redirect->index + 1, redirect->fd);
comm_close(redirect->fd);
EBIT_SET(redirect->flags, HELPER_CLOSING);
EBIT_SET(redirect->flags, HELPER_BUSY);
}
+ if (na)
+ eventAdd("redirectShutdownServers", redirectShutdownServers, NULL, 1.0, 1);
}
-
int
redirectUnregister(const char *url, void *data)
{
/*
- * $Id: tools.cc,v 1.164 1998/07/22 20:38:02 wessels Exp $
+ * $Id: tools.cc,v 1.165 1998/07/25 00:16:30 wessels Exp $
*
* DEBUG: section 21 Misc Functions
* AUTHOR: Harvest Derived
static void fatal_common(const char *);
static void fatalvf(const char *fmt, va_list args);
static void mail_warranty(void);
-static void shutdownTimeoutHandler(int fd, void *data);
#if USE_ASYNC_IO
static void safeunlinkComplete(void *data, int retcode, int errcode);
#endif
#endif
}
-static void
-shutdownTimeoutHandler(int fd, void *datanotused)
-{
- debug(21, 1) ("Forcing close of FD %d\n", fd);
- comm_close(fd);
-}
-
-void
-setSocketShutdownLifetimes(int to)
-{
- fde *f = NULL;
- int i;
- for (i = Biggest_FD; i >= 0; i--) {
- f = &fd_table[i];
- if (!f->read_handler && !f->write_handler)
- continue;
- if (f->type != FD_SOCKET)
- continue;
- if (f->timeout > 0 && (int) (f->timeout - squid_curtime) <= to)
- continue;
- commSetTimeout(i,
- to,
- f->timeout_handler ? f->timeout_handler : shutdownTimeoutHandler,
- f->timeout_data);
- }
-}
-
static void
fatal_common(const char *message)
{