/*
- * DEBUG: section 54 Interprocess Communication
+ * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
*
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
+/* DEBUG: section 54 Interprocess Communication */
+
#include "squid.h"
#include "globals.h"
#include "ipc/Kid.h"
+#include "SquidConfig.h"
+#include <ctime>
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
int TheProcessKind = pkOther;
Kid::Kid():
- badFailures(0),
- pid(-1),
- startTime(0),
- isRunning(false),
- status(0)
+ badFailures(0),
+ pid(-1),
+ startTime(0),
+ isRunning(false),
+ status(0)
{
}
Kid::Kid(const String& kid_name):
- theName(kid_name),
- badFailures(0),
- pid(-1),
- startTime(0),
- isRunning(false),
- status(0)
+ theName(kid_name),
+ badFailures(0),
+ pid(-1),
+ startTime(0),
+ isRunning(false),
+ status(0)
{
}
assert(cpid > 0);
isRunning = true;
+ stopTime = 0;
pid = cpid;
- time(&startTime);
+ startTime = squid_curtime;
}
/// called when kid terminates, sets exiting status
-void Kid::stop(status_type theExitStatus)
+void
+Kid::stop(PidStatus const theExitStatus)
{
assert(running());
assert(startTime != 0);
isRunning = false;
+ stopTime = squid_curtime;
+ status = theExitStatus;
- time_t stop_time;
- time(&stop_time);
- if ((stop_time - startTime) < fastFailureTimeLimit)
+ if ((stopTime - startTime) < fastFailureTimeLimit)
++badFailures;
else
badFailures = 0; // the failures are not "frequent" [any more]
- status = theExitStatus;
+ reportStopped(); // after all state changes
+}
+
+/// describes a recently stopped kid
+void
+Kid::reportStopped() const
+{
+ if (calledExit()) {
+ syslog(LOG_NOTICE,
+ "Squid Parent: %s process %d exited with status %d",
+ theName.termedBuf(), pid, exitStatus());
+ } else if (signaled()) {
+ syslog(LOG_NOTICE,
+ "Squid Parent: %s process %d exited due to signal %d with status %d",
+ theName.termedBuf(), pid, termSignal(), exitStatus());
+ } else {
+ syslog(LOG_NOTICE, "Squid Parent: %s process %d exited",
+ theName.termedBuf(), pid);
+ }
+
+ if (hopeless() && Config.hopelessKidRevivalDelay) {
+ syslog(LOG_NOTICE, "Squid Parent: %s process %d will not be restarted for %ld "
+ "seconds due to repeated, frequent failures",
+ theName.termedBuf(), pid, Config.hopelessKidRevivalDelay);
+ }
}
/// returns true if tracking of kid is stopped
{
return theName;
}
+
+time_t
+Kid::deathDuration() const
+{
+ return squid_curtime > stopTime ? squid_curtime - stopTime : 0;
+}
+