]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Migrated RegisteredRunners to a multi-action interface.
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 21 Feb 2014 16:14:05 +0000 (09:14 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Fri, 21 Feb 2014 16:14:05 +0000 (09:14 -0700)
Old generic two-action RegisteredRunners were good for handling paired
create/destroy events, but not all main.cc events fit that model well. In
fact, even the old runners implemented the destruction action for one event
only (rrAfterConfig); all other runners implemented a single action.

The adjusted API better supports runners that are interested in any number
of the supported events. It also allows a single runner object to handle
multiple events, which simplifies current code and may help with better
[re]configuration handling in the future.

Added startShutdown() and finishShutdown() events. The former will be needed
for authentication module shutdown and more polished shutdown initiation code
in general (patch pending). The latter is needed for final cleanup code that
previously ran as the destruction action for rrAfterConfig. finishShutdown()
also destroys all runners.

Note that the master process in SMP mode does not run startShutdown because
that process lacks the main loop and startShutdown() promises at least one
main loop iteration (to help with clean connections closures, for example).

Added syncConfig() event that will be needed for the standby pool
implementation (patch pending) and future code that reacts to Squid
configuration changes caused by reconfiguration.

"after config" event is now called "use config" to better match verb+noun or
action+object naming scheme.

16 files changed:
src/CollapsedForwarding.cc
src/DiskIO/IpcIo/IpcIoFile.cc
src/MemStore.cc
src/Transients.cc
src/base/RunnersRegistry.cc
src/base/RunnersRegistry.h
src/cache_cf.cc
src/client_db.cc
src/fs/rock/RockSwapDir.cc
src/fs/rock/RockSwapDir.h
src/ipc/mem/Pages.cc
src/ipc/mem/Segment.cc
src/ipc/mem/Segment.h
src/main.cc
src/ssl/support.cc
src/tests/testRock.cc

index 862a0111c9ca126d013ae862a4a5dfa1b3e5857d..a214f57f052506d5697fd07f291e13513a9ef2df 100644 (file)
@@ -134,16 +134,16 @@ public:
     virtual ~CollapsedForwardingRr();
 
 protected:
-    virtual void create(const RunnerRegistry &);
-    virtual void open(const RunnerRegistry &);
+    virtual void create();
+    virtual void open();
 
 private:
     Ipc::MultiQueue::Owner *owner;
 };
 
-RunnerRegistrationEntry(rrAfterConfig, CollapsedForwardingRr);
+RunnerRegistrationEntry(CollapsedForwardingRr);
 
-void CollapsedForwardingRr::create(const RunnerRegistry &)
+void CollapsedForwardingRr::create()
 {
     Must(!owner);
     owner = Ipc::MultiQueue::Init(ShmLabel, Config.workers, 1,
@@ -151,7 +151,7 @@ void CollapsedForwardingRr::create(const RunnerRegistry &)
                                   QueueCapacity);
 }
 
-void CollapsedForwardingRr::open(const RunnerRegistry &)
+void CollapsedForwardingRr::open()
 {
     CollapsedForwarding::Init();
 }
index d60d73f9082773f62839d259cdd3b3de0f39fbf8..6b7a67500a78b24cc51183c481a7c5b7c4fb6616 100644 (file)
@@ -907,17 +907,27 @@ DiskerClose(const String &path)
 }
 
 /// reports our needs for shared memory pages to Ipc::Mem::Pages
-class IpcIoClaimMemoryNeedsRr: public RegisteredRunner
+/// and initializes shared memory segments used by IpcIoFile
+class IpcIoRr: public Ipc::Mem::RegisteredRunner
 {
 public:
     /* RegisteredRunner API */
-    virtual void run(const RunnerRegistry &r);
+    IpcIoRr(): owner(NULL) {}
+    virtual ~IpcIoRr();
+    virtual void claimMemoryNeeds();
+
+protected:
+    /* Ipc::Mem::RegisteredRunner API */
+    virtual void create();
+
+private:
+    Ipc::FewToFewBiQueue::Owner *owner;
 };
 
-RunnerRegistrationEntry(rrClaimMemoryNeeds, IpcIoClaimMemoryNeedsRr);
+RunnerRegistrationEntry(IpcIoRr);
 
 void
-IpcIoClaimMemoryNeedsRr::run(const RunnerRegistry &)
+IpcIoRr::claimMemoryNeeds()
 {
     const int itemsCount = Ipc::FewToFewBiQueue::MaxItemsCount(
                                ::Config.workers, ::Config.cacheSwap.n_strands, QueueCapacity);
@@ -929,24 +939,8 @@ IpcIoClaimMemoryNeedsRr::run(const RunnerRegistry &)
                            static_cast<int>(itemsCount * 1.1));
 }
 
-/// initializes shared memory segments used by IpcIoFile
-class IpcIoRr: public Ipc::Mem::RegisteredRunner
-{
-public:
-    /* RegisteredRunner API */
-    IpcIoRr(): owner(NULL) {}
-    virtual ~IpcIoRr();
-
-protected:
-    virtual void create(const RunnerRegistry &);
-
-private:
-    Ipc::FewToFewBiQueue::Owner *owner;
-};
-
-RunnerRegistrationEntry(rrAfterConfig, IpcIoRr);
-
-void IpcIoRr::create(const RunnerRegistry &)
+void
+IpcIoRr::create()
 {
     if (Config.cacheSwap.n_strands <= 0)
         return;
index 23b881db31819e059c4f08aec6c60ccc78b5a4c5..29c1917418a7ebb85afdd72da70da3387b276054 100644 (file)
@@ -746,33 +746,38 @@ MemStore::EntryLimit()
     return entryLimit;
 }
 
-/// reports our needs for shared memory pages to Ipc::Mem::Pages
-class MemStoreClaimMemoryNeedsRr: public RegisteredRunner
+/// reports our needs for shared memory pages to Ipc::Mem::Pages;
+/// decides whether to use a shared memory cache or checks its configuration;
+/// and initializes shared memory segments used by MemStore
+class MemStoreRr: public Ipc::Mem::RegisteredRunner
 {
 public:
     /* RegisteredRunner API */
-    virtual void run(const RunnerRegistry &r);
+    MemStoreRr(): spaceOwner(NULL), mapOwner(NULL) {}
+    virtual void finalizeConfig();
+    virtual void claimMemoryNeeds();
+    virtual void useConfig();
+    virtual ~MemStoreRr();
+
+protected:
+    /* Ipc::Mem::RegisteredRunner API */
+    virtual void create();
+
+private:
+    Ipc::Mem::Owner<Ipc::Mem::PageStack> *spaceOwner; ///< free slices Owner
+    MemStoreMap::Owner *mapOwner; ///< primary map Owner
 };
 
-RunnerRegistrationEntry(rrClaimMemoryNeeds, MemStoreClaimMemoryNeedsRr);
+RunnerRegistrationEntry(MemStoreRr);
 
 void
-MemStoreClaimMemoryNeedsRr::run(const RunnerRegistry &)
+MemStoreRr::claimMemoryNeeds()
 {
     Ipc::Mem::NotePageNeed(Ipc::Mem::PageId::cachePage, MemStore::EntryLimit());
 }
 
-/// decides whether to use a shared memory cache or checks its configuration
-class MemStoreCfgRr: public ::RegisteredRunner
-{
-public:
-    /* RegisteredRunner API */
-    virtual void run(const RunnerRegistry &);
-};
-
-RunnerRegistrationEntry(rrFinalizeConfig, MemStoreCfgRr);
-
-void MemStoreCfgRr::run(const RunnerRegistry &r)
+void
+MemStoreRr::finalizeConfig()
 {
     // decide whether to use a shared memory cache if the user did not specify
     if (!Config.memShared.configured()) {
@@ -790,32 +795,15 @@ void MemStoreCfgRr::run(const RunnerRegistry &r)
     }
 }
 
-/// initializes shared memory segments used by MemStore
-class MemStoreRr: public Ipc::Mem::RegisteredRunner
-{
-public:
-    /* RegisteredRunner API */
-    MemStoreRr(): spaceOwner(NULL), mapOwner(NULL) {}
-    virtual void run(const RunnerRegistry &);
-    virtual ~MemStoreRr();
-
-protected:
-    virtual void create(const RunnerRegistry &);
-
-private:
-    Ipc::Mem::Owner<Ipc::Mem::PageStack> *spaceOwner; ///< free slices Owner
-    MemStoreMap::Owner *mapOwner; ///< primary map Owner
-};
-
-RunnerRegistrationEntry(rrAfterConfig, MemStoreRr);
-
-void MemStoreRr::run(const RunnerRegistry &r)
+void
+MemStoreRr::useConfig()
 {
     assert(Config.memShared.configured());
-    Ipc::Mem::RegisteredRunner::run(r);
+    Ipc::Mem::RegisteredRunner::useConfig();
 }
 
-void MemStoreRr::create(const RunnerRegistry &)
+void
+MemStoreRr::create()
 {
     if (!Config.memShared)
         return;
index 480e82e6611e6e2a8293305d479e8b32315e8205..a5925288813c6bad5d0893b5ddf4ce31db49727e 100644 (file)
@@ -384,27 +384,27 @@ class TransientsRr: public Ipc::Mem::RegisteredRunner
 public:
     /* RegisteredRunner API */
     TransientsRr(): mapOwner(NULL) {}
-    virtual void run(const RunnerRegistry &);
+    virtual void useConfig();
     virtual ~TransientsRr();
 
 protected:
-    virtual void create(const RunnerRegistry &);
+    virtual void create();
 
 private:
     TransientsMap::Owner *mapOwner;
 };
 
-RunnerRegistrationEntry(rrAfterConfig, TransientsRr);
+RunnerRegistrationEntry(TransientsRr);
 
 void
-TransientsRr::run(const RunnerRegistry &r)
+TransientsRr::useConfig()
 {
     assert(Config.memShared.configured());
-    Ipc::Mem::RegisteredRunner::run(r);
+    Ipc::Mem::RegisteredRunner::useConfig();
 }
 
 void
-TransientsRr::create(const RunnerRegistry &)
+TransientsRr::create()
 {
     if (!Config.onoff.collapsed_forwarding)
         return;
index 0a93a763d1e9b98860f6d7c2689239c6afa9d4b4..743e09772549f76567242e5946e13787b62f558a 100644 (file)
@@ -1,52 +1,40 @@
 #include "squid.h"
 #include "base/RunnersRegistry.h"
-#include <list>
-#include <map>
+#include <set>
 
-typedef std::list<RegisteredRunner*> Runners;
-typedef std::map<RunnerRegistry, Runners*> Registries;
+/// a collection of unique runners, in no particular order
+typedef std::set<RegisteredRunner*> Runners;
+/// all known runners
+static Runners *TheRunners = NULL;
 
-/// all known registries
-static Registries *TheRegistries = NULL;
-
-/// returns the requested runners list, initializing structures as needed
+/// safely returns registered runners, initializing structures as needed
 static Runners &
-GetRunners(const RunnerRegistry &registryId)
+GetRunners()
 {
-    if (!TheRegistries)
-        TheRegistries = new Registries;
-
-    if (TheRegistries->find(registryId) == TheRegistries->end())
-        (*TheRegistries)[registryId] = new Runners;
-
-    return *(*TheRegistries)[registryId];
+    if (!TheRunners)
+        TheRunners = new Runners;
+    return *TheRunners;
 }
 
 int
-RegisterRunner(const RunnerRegistry &registryId, RegisteredRunner *rr)
+RegisterRunner(RegisteredRunner *rr)
 {
-    Runners &runners = GetRunners(registryId);
-    runners.push_back(rr);
+    Runners &runners = GetRunners();
+    runners.insert(rr);
     return runners.size();
 }
 
-int
-ActivateRegistered(const RunnerRegistry &registryId)
+void
+RunRegistered(const RegisteredRunner::Method &m)
 {
-    Runners &runners = GetRunners(registryId);
+    Runners &runners = GetRunners();
     typedef Runners::iterator RRI;
     for (RRI i = runners.begin(); i != runners.end(); ++i)
-        (*i)->run(registryId);
-    return runners.size();
-}
+        ((*i)->*m)();
 
-void
-DeactivateRegistered(const RunnerRegistry &registryId)
-{
-    Runners &runners = GetRunners(registryId);
-    while (!runners.empty()) {
-        delete runners.back();
-        runners.pop_back();
+    if (m == &RegisteredRunner::finishShutdown) {
+        delete TheRunners;
+        TheRunners = NULL;
     }
 }
 
index 8af8f334974643d7524dba801d1ae5ebbb561c3f..d0e369c20893d1e7c5344ecc1dc3a3e3d62fefa3 100644 (file)
@@ -2,70 +2,94 @@
 #define SQUID_BASE_RUNNERSREGISTRY_H
 
 /**
- * This API allows virtually any module to register with a well-known registry,
- * be activated by some central processor at some registry-specific time, and
- * be deactiveated by some central processor at some registry-specific time.
+ * This API allows virtually any module to register its interest in receiving
+ * notification about initial configuration availability, configuration changes
+ * and other critical events in Squid lifetime without exposing the notifier
+ * to the details of the module.
  *
  * For example, main.cc may activate registered I/O modules after parsing
- * squid.conf and deactivate them before exiting.
+ * squid.conf and deactivate them before exiting, all without knowing what
+ * those I/O modules really are.
  *
  * A module in this context is code providing a functionality or service to the
- * rest of Squid, such as src/DiskIO/Blocking, src/fs/ufs, or Cache Manager. A
- * module must declare a RegisteredRunner child class to implement activation and
- * deactivation logic using the run() method and destructor, respectively.
+ * rest of Squid, such as src/DiskIO/Blocking, src/fs/ufs, or Cache Manager. To
+ * receive notifications, a module must declare a RegisteredRunner child class
+ * and implement the methods corresponding to the events the module is
+ * interested in.
  *
- * This API allows the registry to determine the right [de]activation time for
- * each group of similar modules, without knowing any module specifics.
+ * The order of events is documented in this header (where applicable), but
+ * the order in which runners are notified about a given event is undefined.
+ * If a specific notification order is required, split the event into two or
+ * more related event(s), documenting their relative order here.
  *
  */
 
-/// well-known registries
-typedef enum {
-    /// Managed by main.cc. Activated after parsing squid.conf and
-    /// deactivated before freeing configuration-related memory or exit()-ing.
+/// a runnable registrant API
+/// kids must override [only] the methods they are interested in
+class RegisteredRunner
+{
+public:
+    /* Related methods below are declared in their calling order */
+
+    /* Configuration events */
+
+    /// Called after parsing squid.conf.
     /// Meant for setting configuration options that depend on other
     /// configuration options and were not explicitly configured.
-    rrFinalizeConfig,
+    virtual void finalizeConfig() {}
 
-    /// Managed by main.cc. Activated after rrFinalizeConfig and
-    /// deactivated before rrFinalizeConfig. Meant for announcing
-    /// memory reservations before memory is allocated.
-    rrClaimMemoryNeeds,
+    /// Called after finalizeConfig().
+    /// Meant for announcing memory reservations before memory is allocated.
+    virtual void claimMemoryNeeds() {}
 
-    /// Managed by main.cc. Activated after rrClaimMemoryNeeds and
-    /// deactivated before rrClaimMemoryNeeds. Meant for activating
-    /// modules and features based on the finalized configuration.
-    rrAfterConfig,
+    /// Called after claimMemoryNeeds().
+    /// Meant for activating modules and features using a finalized
+    /// configuration with known memory requirements.
+    virtual void useConfig() {}
 
-    rrEnd ///< not a real registry, just a label to mark the end of enum
-} RunnerRegistry;
+    /* Reconfiguration events */
 
-/// a runnable registrant API
-class RegisteredRunner
-{
-public:
-    // called when this runner's registry is deactivated
+    /// Called after parsing squid.conf during reconfiguration.
+    /// Meant for adjusting the module state based on configuration changes.
+    virtual void syncConfig() {}
+
+    /* Shutdown events */
+
+    /// Called after receiving a shutdown request and before stopping the main
+    /// loop. At least one main loop iteration is guaranteed after this call.
+    /// Meant for cleanup and state saving that may require other modules.
+    virtual void startShutdown() {}
+
+    /// Called after stopping the main loop.
+    /// Meant for quick/basic cleanup that does not require any other modules.
     virtual ~RegisteredRunner() {}
+    /// exists to simplify caller interface; override the destructor instead
+    void finishShutdown() { delete this; }
+
+    /// a pointer to one of the above notification methods
+    typedef void (RegisteredRunner::*Method)();
 
-    // called when this runner's registry is activated
-    virtual void run(const RunnerRegistry &r) = 0;
 };
 
 /// registers a given runner with the given registry and returns registry count
-int RegisterRunner(const RunnerRegistry &registry, RegisteredRunner *rr);
+int RegisterRunner(RegisteredRunner *rr);
+
+/// Calls a given method of all runners.
+/// All runners are destroyed after the finishShutdown() call.
+void RunRegistered(const RegisteredRunner::Method &m);
 
-/// calls run() methods of all runners in the given registry
-int ActivateRegistered(const RunnerRegistry &registry);
-/// deletes all runners in the given registry
-void DeactivateRegistered(const RunnerRegistry &registry);
+/// convenience macro to describe/debug the caller and the method being called
+#define RunRegisteredHere(m) \
+    debugs(1, 2, "running " # m); \
+    RunRegistered(&m)
 
 /// convenience function to "use" an otherwise unreferenced static variable
 bool UseThisStatic(const void *);
 
 /// convenience macro: register one RegisteredRunner kid as early as possible
-#define RunnerRegistrationEntry(Registry, Who) \
-    static const bool Who ## _RegisteredWith_ ## Registry = \
-        RegisterRunner(Registry, new Who) > 0 && \
-        UseThisStatic(& Who ## _RegisteredWith_ ## Registry);
+#define RunnerRegistrationEntry(Who) \
+    static const bool Who ## _Registered_ = \
+        RegisterRunner(new Who) > 0 && \
+        UseThisStatic(& Who ## _Registered_);
 
 #endif /* SQUID_BASE_RUNNERSREGISTRY_H */
index 6e9a4b325a01bf1eb3c3b44d79c89e145261f263..0b537d34454953ba9d6937e7c2acc695271a0062 100644 (file)
@@ -4602,14 +4602,15 @@ class sslBumpCfgRr: public ::RegisteredRunner
 public:
     static Ssl::BumpMode lastDeprecatedRule;
     /* RegisteredRunner API */
-    virtual void run(const RunnerRegistry &);
+    virtual void finalizeConfig();
 };
 
 Ssl::BumpMode sslBumpCfgRr::lastDeprecatedRule = Ssl::bumpEnd;
 
-RunnerRegistrationEntry(rrFinalizeConfig, sslBumpCfgRr);
+RunnerRegistrationEntry(sslBumpCfgRr);
 
-void sslBumpCfgRr::run(const RunnerRegistry &r)
+void
+sslBumpCfgRr::finalizeConfig()
 {
     if (lastDeprecatedRule != Ssl::bumpEnd) {
         assert( lastDeprecatedRule == Ssl::bumpClientFirst || lastDeprecatedRule == Ssl::bumpNone);
index 87ab1b2a338231de5f41e979d3ffc91ec54c0bd0..1da277eb8ca62289e76059928072a24df4ab3be9 100644 (file)
@@ -124,12 +124,13 @@ clientdbInit(void)
 class ClientDbRr: public RegisteredRunner
 {
 public:
-    virtual void run(const RunnerRegistry &);
+    /* RegisteredRunner API */
+    virtual void useConfig();
 };
-RunnerRegistrationEntry(rrAfterConfig, ClientDbRr);
+RunnerRegistrationEntry(ClientDbRr);
 
 void
-ClientDbRr::run(const RunnerRegistry &r)
+ClientDbRr::useConfig()
 {
     clientdbInit();
     Mgr::RegisterAction("client_list", "Cache Client List", clientdbDump, 0, 1);
index f23280c611d598d3f0f53e7f6788e2237b148e58..91f98c475aa5756399d3df8f8f323c1a1ddf7943 100644 (file)
@@ -1004,10 +1004,10 @@ Rock::SwapDir::freeSlotsPath() const
 
 namespace Rock
 {
-RunnerRegistrationEntry(rrAfterConfig, SwapDirRr);
+RunnerRegistrationEntry(SwapDirRr);
 }
 
-void Rock::SwapDirRr::create(const RunnerRegistry &)
+void Rock::SwapDirRr::create()
 {
     Must(mapOwners.empty() && freeSlotsOwners.empty());
     for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
index e58052c7305766a5ed0df777ab024749099a5578..a8c61cf25ddb9be9ff1160684b252bcdb5c91b63 100644 (file)
@@ -143,7 +143,7 @@ public:
 
 protected:
     /* Ipc::Mem::RegisteredRunner API */
-    virtual void create(const RunnerRegistry &);
+    virtual void create();
 
 private:
     std::vector<SwapDir::DirMap::Owner *> mapOwners;
index 51d65dd10cafa7bfa52447a387291c720e485570..b9d9590c28844d2e1bfb59688fcf1aaff9e31967 100644 (file)
@@ -90,28 +90,28 @@ class SharedMemPagesRr: public Ipc::Mem::RegisteredRunner
 public:
     /* RegisteredRunner API */
     SharedMemPagesRr(): owner(NULL) {}
-    virtual void run(const RunnerRegistry &);
-    virtual void create(const RunnerRegistry &);
-    virtual void open(const RunnerRegistry &);
+    virtual void useConfig();
+    virtual void create();
+    virtual void open();
     virtual ~SharedMemPagesRr();
 
 private:
     Ipc::Mem::PagePool::Owner *owner;
 };
 
-RunnerRegistrationEntry(rrAfterConfig, SharedMemPagesRr);
+RunnerRegistrationEntry(SharedMemPagesRr);
 
 void
-SharedMemPagesRr::run(const RunnerRegistry &r)
+SharedMemPagesRr::useConfig()
 {
     if (Ipc::Mem::PageLimit() <= 0)
         return;
 
-    Ipc::Mem::RegisteredRunner::run(r);
+    Ipc::Mem::RegisteredRunner::useConfig();
 }
 
 void
-SharedMemPagesRr::create(const RunnerRegistry &)
+SharedMemPagesRr::create()
 {
     Must(!owner);
     owner = Ipc::Mem::PagePool::Init(PagePoolId, Ipc::Mem::PageLimit(),
@@ -119,7 +119,7 @@ SharedMemPagesRr::create(const RunnerRegistry &)
 }
 
 void
-SharedMemPagesRr::open(const RunnerRegistry &)
+SharedMemPagesRr::open()
 {
     Must(!ThePagePool);
     ThePagePool = new Ipc::Mem::PagePool(PagePoolId);
index c2073b011d87e129955661ef3c35ef55f22999f8..4242119b41321560c7a5644a3516db7081ff43d6 100644 (file)
@@ -279,7 +279,7 @@ Ipc::Mem::Segment::checkSupport(const char *const context)
 #endif // HAVE_SHM
 
 void
-Ipc::Mem::RegisteredRunner::run(const RunnerRegistry &r)
+Ipc::Mem::RegisteredRunner::useConfig()
 {
     // If Squid is built with real segments, we create() real segments
     // in the master process only.  Otherwise, we create() fake
@@ -290,10 +290,10 @@ Ipc::Mem::RegisteredRunner::run(const RunnerRegistry &r)
 #else
     if (IamWorkerProcess())
 #endif
-        create(r);
+        create();
 
     // we assume that master process does not need shared segments
     // unless it is also a worker
     if (!InDaemonMode() || !IamMasterProcess())
-        open(r);
+        open();
 }
index 6626a88018dad71af5c3d04bed52127edecfb4db..7d0807a81dbde5ee9f055c82866056b859344a2b 100644 (file)
@@ -72,14 +72,14 @@ class RegisteredRunner: public ::RegisteredRunner
 {
 public:
     /* RegisteredRunner API */
-    virtual void run(const RunnerRegistry &r);
+    virtual void useConfig();
 
 protected:
     /// called when the runner should create a new memory segment
-    virtual void create(const RunnerRegistry &) = 0;
+    virtual void create() = 0;
     /// called when the runner should open a previously created segment,
     /// not needed if segments are opened in constructor or init methods
-    virtual void open(const RunnerRegistry &) {}
+    virtual void open() {}
 };
 
 } // namespace Mem
index 2469b0bed016fee62b056b833694187241feb1ee..82af145cccf3ba98be7187f9f5b5e484e38f7aef 100644 (file)
@@ -274,6 +274,8 @@ SignalEngine::doShutdown(time_t wait)
     /* detach the auth components (only do this on full shutdown) */
     Auth::Scheme::FreeAll();
 #endif
+
+    RunRegisteredHere(RegisteredRunner::startShutdown);
     eventAdd("SquidShutdown", &StopEventLoop, this, (double) (wait + 1), 1, false);
 }
 
@@ -804,6 +806,8 @@ mainReconfigureFinish(void *)
         Config.workers = oldWorkers;
     }
 
+    RunRegisteredHere(RegisteredRunner::syncConfig);
+
     if (IamPrimaryProcess())
         CpuAffinityCheck();
     CpuAffinityReconfigure();
@@ -1443,9 +1447,9 @@ SquidMain(int argc, char **argv)
 
     debugs(1,2, HERE << "Doing post-config initialization\n");
     leave_suid();
-    ActivateRegistered(rrFinalizeConfig);
-    ActivateRegistered(rrClaimMemoryNeeds);
-    ActivateRegistered(rrAfterConfig);
+    RunRegisteredHere(RegisteredRunner::finalizeConfig);
+    RunRegisteredHere(RegisteredRunner::claimMemoryNeeds);
+    RunRegisteredHere(RegisteredRunner::useConfig);
     enter_suid();
 
     if (!opt_no_daemon && Config.workers > 0)
@@ -1804,9 +1808,9 @@ watch_child(char *argv[])
 
         if (!TheKids.someRunning() && !TheKids.shouldRestartSome()) {
             leave_suid();
-            DeactivateRegistered(rrAfterConfig);
-            DeactivateRegistered(rrClaimMemoryNeeds);
-            DeactivateRegistered(rrFinalizeConfig);
+            // XXX: Master process has no main loop and, hence, should not call
+            // RegisteredRunner::startShutdown which promises a loop iteration.
+            RunRegisteredHere(RegisteredRunner::finishShutdown);
             enter_suid();
 
             if (TheKids.someSignaled(SIGINT) || TheKids.someSignaled(SIGTERM)) {
@@ -1902,9 +1906,6 @@ SquidShutdown()
     Store::Root().sync();              /* Flush log close */
     StoreFileSystem::FreeAllFs();
     DiskIOModule::FreeAllModules();
-    DeactivateRegistered(rrAfterConfig);
-    DeactivateRegistered(rrClaimMemoryNeeds);
-    DeactivateRegistered(rrFinalizeConfig);
 #if LEAK_CHECK_MODE && 0 /* doesn't work at the moment */
 
     configFreeMemory();
@@ -1939,6 +1940,8 @@ SquidShutdown()
 
     memClean();
 
+    RunRegisteredHere(RegisteredRunner::finishShutdown);
+
 #if XMALLOC_TRACE
 
     xmalloc_find_leaks();
index 719fe103d7b464f286f18d5b74abb9d99d30544e..2923ea13df382cc68017b8f354d4770f2b04d01a 100644 (file)
@@ -1839,26 +1839,26 @@ class SharedSessionCacheRr: public Ipc::Mem::RegisteredRunner
 public:
     /* RegisteredRunner API */
     SharedSessionCacheRr(): owner(NULL) {}
-    virtual void run(const RunnerRegistry &);
+    virtual void useConfig();
     virtual ~SharedSessionCacheRr();
 
 protected:
-    virtual void create(const RunnerRegistry &);
+    virtual void create();
 
 private:
     Ipc::MemMap::Owner *owner;
 };
 
-RunnerRegistrationEntry(rrAfterConfig, SharedSessionCacheRr);
+RunnerRegistrationEntry(SharedSessionCacheRr);
 
 void
-SharedSessionCacheRr::run(const RunnerRegistry &r)
+SharedSessionCacheRr::useConfig()
 {
-    Ipc::Mem::RegisteredRunner::run(r);
+    Ipc::Mem::RegisteredRunner::useConfig();
 }
 
 void
-SharedSessionCacheRr::create(const RunnerRegistry &)
+SharedSessionCacheRr::create()
 {
     if (!isSslServer()) //no need to configure ssl session cache.
         return;
index c823c5a546f5d61fc6b99be3fabe8cce974e319c..b0eba88678f17b840a2df0d1b3b9037d979cf996 100644 (file)
@@ -80,7 +80,7 @@ testRock::setUp()
     store->create();
 
     rr = new Rock::SwapDirRr;
-    rr->run(rrAfterConfig);
+    rr->useConfig();
 }
 
 void
@@ -94,7 +94,8 @@ testRock::tearDown()
 
     free_cachedir(&Config.cacheSwap);
 
-    delete rr;
+    rr->finishShutdown(); // deletes rr
+    rr = NULL;
 
     // TODO: do this once, or each time.
     // safe_free(Config.replPolicy->type);