{
PROF_start(SignalEngine_checkEvents);
- if (do_reconfigure) {
- if (!reconfiguring && configured_once) {
- mainReconfigureStart();
- do_reconfigure = 0;
- } // else wait until previous reconfigure is done
- } else if (do_rotate) {
+ if (do_reconfigure)
+ mainReconfigureStart();
+ else if (do_rotate)
mainRotate();
- do_rotate = 0;
- } else if (do_shutdown) {
+ else if (do_shutdown)
doShutdown(do_shutdown > 0 ? (int) Config.shutdownLifetime : 0);
- do_shutdown = 0;
- }
- if (do_handle_stopped_child) {
- do_handle_stopped_child = 0;
+ if (do_handle_stopped_child)
handleStoppedChild();
- }
PROF_stop(SignalEngine_checkEvents);
return EVENT_IDLE;
}
+/// Decides whether the signal-controlled action X should be delayed, canceled,
+/// or executed immediately. Clears do_X (via signalVar) as needed.
+static bool
+AvoidSignalAction(const char *description, volatile int &signalVar)
+{
+ const char *avoiding = "delaying";
+ const char *currentEvent = "none";
+ if (shutting_down) {
+ currentEvent = "shutdown";
+ avoiding = "canceling";
+ signalVar = 0;
+ }
+ else if (!configured_once)
+ currentEvent = "startup";
+ else if (reconfiguring)
+ currentEvent = "reconfiguration";
+ else {
+ signalVar = 0;
+ return false; // do not avoid (i.e., execute immediately)
+ // the caller may produce a signal-specific debugging message
+ }
+
+ debugs(1, DBG_IMPORTANT, avoiding << ' ' << description <<
+ " request during " << currentEvent);
+ return true;
+}
+
void
SignalEngine::doShutdown(time_t wait)
{
+ if (AvoidSignalAction("shutdown", do_shutdown))
+ return;
+
debugs(1, DBG_IMPORTANT, "Preparing for shutdown after " << statCounter.client_http.requests << " requests");
debugs(1, DBG_IMPORTANT, "Waiting " << wait << " seconds for active connections to finish");
void
SignalEngine::handleStoppedChild()
{
+ // no AvoidSignalAction() call: This code can run at any time because it
+ // does not depend on Squid state. It does not need debugging because it
+ // handles an "internal" signal, not an external/admin command.
+ do_handle_stopped_child = 0;
#if !_SQUID_WINDOWS_
PidStatus status;
pid_t pid;
static void
mainReconfigureStart(void)
{
+ if (AvoidSignalAction("reconfiguration", do_reconfigure))
+ return;
+
debugs(1, DBG_IMPORTANT, "Reconfiguring Squid Cache (version " << version_string << ")...");
reconfiguring = 1;
writePidFile(); /* write PID file */
reconfiguring = 0;
-
- // ignore any pending re-reconfigure signals if shutdown received
- if (do_shutdown)
- do_reconfigure = 0;
}
static void
mainRotate(void)
{
+ if (AvoidSignalAction("log rotation", do_rotate))
+ return;
+
icmpEngine.Close();
redirectShutdown();
#if USE_AUTH
Format::Token::Init(); // XXX: temporary. Use a runners registry of pre-parse runners instead.
try {
- do_reconfigure = 0; // ignore any early (boot/startup) reconfigure signals
parse_err = parseConfigFile(ConfigFile);
} catch (...) {
// for now any errors are a fatal condition...