]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ipc/Kids.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / ipc / Kids.cc
index 717cf47615e25a6bf286424ff66c7dc7f75c52e3..725bead57cb41fa583b33bf25d17ac19b9d8a009 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -16,7 +16,7 @@
 #include "tools.h"
 
 Kids TheKids;
-KidName TheKidName;
+SBuf TheKidName;
 
 Kids::Kids()
 {
@@ -29,25 +29,16 @@ void Kids::init()
 
     storage.reserve(NumberOfKids());
 
-    char kid_name[32];
-
-    // add Kid records for all workers
-    for (int i = 0; i < Config.workers; ++i) {
-        snprintf(kid_name, sizeof(kid_name), "(squid-%d)", (int)(storage.size()+1));
-        storage.push_back(Kid(kid_name));
-    }
+    for (int i = 0; i < Config.workers; ++i)
+        storage.emplace_back("squid", storage.size() + 1);
 
     // add Kid records for all disk processes
-    for (int i = 0; i < Config.cacheSwap.n_strands; ++i) {
-        snprintf(kid_name, sizeof(kid_name), "(squid-disk-%d)", (int)(storage.size()+1));
-        storage.push_back(Kid(kid_name));
-    }
+    for (int i = 0; i < Config.cacheSwap.n_strands; ++i)
+        storage.emplace_back("squid-disk", storage.size() + 1);
 
     // if coordination is needed, add a Kid record for Coordinator
-    if (storage.size() > 1) {
-        snprintf(kid_name, sizeof(kid_name), "(squid-coord-%d)", (int)(storage.size()+1));
-        storage.push_back(Kid(kid_name));
-    }
+    if (storage.size() > 1)
+        storage.emplace_back("squid-coord", storage.size() + 1);
 
     Must(storage.size() == static_cast<size_t>(NumberOfKids()));
 }
@@ -82,6 +73,35 @@ bool Kids::allHopeless() const
     return true;
 }
 
+void
+Kids::forgetAllFailures()
+{
+    for (auto &kid: storage)
+        kid.forgetFailures();
+}
+
+time_t
+Kids::forgetOldFailures()
+{
+    time_t nextCheckDelay = 0;
+    for (auto &kid: storage) {
+        if (!kid.hopeless())
+            continue;
+
+        const auto deathDuration = kid.deathDuration(); // protect from time changes
+        if (Config.hopelessKidRevivalDelay <= deathDuration) {
+            kid.forgetFailures(); // this kid will be revived now
+            continue;
+        }
+
+        const auto remainingDeathTime = Config.hopelessKidRevivalDelay - deathDuration;
+        assert(remainingDeathTime > 0);
+        if (remainingDeathTime < nextCheckDelay || !nextCheckDelay)
+            nextCheckDelay = remainingDeathTime;
+    }
+    return nextCheckDelay; // still zero if there were no still-hopeless kids
+}
+
 /// whether all kids called exited happy
 bool Kids::allExitedHappy() const
 {