]> granicus.if.org Git - icinga2/commitdiff
Make sure all objects are set to 'active' before calling the Start() method
authorGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 4 May 2017 08:37:34 +0000 (10:37 +0200)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 4 May 2017 08:37:34 +0000 (10:37 +0200)
fixes #5224

lib/base/configobject.cpp
lib/base/configobject.hpp
lib/config/configitem.cpp

index f155af3bab73f2caf419ae1db58443d8a7a64ef4..616aee8d553293c9cbe21857993d657328747715 100644 (file)
@@ -374,6 +374,14 @@ void ConfigObject::Start(bool runtimeCreated)
        SetStartCalled(true);
 }
 
+void ConfigObject::PreActivate(void)
+{
+       CONTEXT("Setting 'active' to true for object '" + GetName() + "' of type '" + GetReflectionType()->GetName() + "'");
+
+       ASSERT(!IsActive());
+       SetActive(true, true);
+}
+
 void ConfigObject::Activate(bool runtimeCreated)
 {
        CONTEXT("Activating object '" + GetName() + "' of type '" + GetReflectionType()->GetName() + "'");
@@ -384,8 +392,6 @@ void ConfigObject::Activate(bool runtimeCreated)
                Start(runtimeCreated);
 
                ASSERT(GetStartCalled());
-               ASSERT(!IsActive());
-               SetActive(true, true);
 
                if (GetHAMode() == HARunEverywhere)
                        SetAuthority(true);
index b1f45b6f5bbaa663bc69ffcbcc848a965080f24b..1605941435ce245be326268cb2d01ae36bbe24eb 100644 (file)
@@ -60,6 +60,7 @@ public:
        void Register(void);
        void Unregister(void);
 
+       void PreActivate(void);
        void Activate(bool runtimeCreated = false);
        void Deactivate(bool runtimeRemoved = false);
        void SetAuthority(bool authority);
index 964ec2026c9f7b3f8302d29701d54546ea8df239..91a8922f5b4faefa15ebeae58ed89eca46156cf1 100644 (file)
@@ -597,9 +597,6 @@ bool ConfigItem::ActivateItems(WorkQueue& upq, const std::vector<ConfigItem::Ptr
                }
        }
 
-       if (!silent)
-               Log(LogInformation, "ConfigItem", "Triggering Start signal for config items");
-
        for (const ConfigItem::Ptr& item : newItems) {
                if (!item->m_Object)
                        continue;
@@ -609,6 +606,29 @@ bool ConfigItem::ActivateItems(WorkQueue& upq, const std::vector<ConfigItem::Ptr
                if (object->IsActive())
                        continue;
 
+#ifdef I2_DEBUG
+               Log(LogDebug, "ConfigItem")
+                   << "Setting 'active' to true for object '" << object->GetName() << "' of type '" << object->GetReflectionType()->GetName() << "'";
+#endif /* I2_DEBUG */
+               upq.Enqueue(boost::bind(&ConfigObject::PreActivate, object));
+       }
+
+       upq.Join();
+
+       if (upq.HasExceptions()) {
+               upq.ReportExceptions("ConfigItem");
+               return false;
+       }
+
+       if (!silent)
+               Log(LogInformation, "ConfigItem", "Triggering Start signal for config items");
+
+       for (const ConfigItem::Ptr& item : newItems) {
+               if (!item->m_Object)
+                       continue;
+
+               ConfigObject::Ptr object = item->m_Object;
+
 #ifdef I2_DEBUG
                Log(LogDebug, "ConfigItem")
                    << "Activating object '" << object->GetName() << "' of type '" << object->GetReflectionType()->GetName() << "'";