]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ipc/Kid.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / ipc / Kid.cc
index 15cf79ceefa19057c6bc39f849b0b77ae613050c..9a3cc1fa178b9435876bb05549d0f79d00082603 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * 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.
@@ -11,6 +11,7 @@
 #include "squid.h"
 #include "globals.h"
 #include "ipc/Kid.h"
+#include "SquidConfig.h"
 
 #include <ctime>
 #if HAVE_SYS_WAIT_H
@@ -45,8 +46,9 @@ void Kid::start(pid_t cpid)
     assert(cpid > 0);
 
     isRunning = true;
+    stopTime = 0;
     pid = cpid;
-    time(&startTime);
+    startTime = squid_curtime;
 }
 
 /// called when kid terminates, sets exiting status
@@ -57,15 +59,39 @@ Kid::stop(PidStatus const theExitStatus)
     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
@@ -147,3 +173,9 @@ const String& Kid::name() const
     return theName;
 }
 
+time_t
+Kid::deathDuration() const
+{
+    return squid_curtime > stopTime ? squid_curtime - stopTime : 0;
+}
+