]> granicus.if.org Git - icinga2/commitdiff
Fix another race condition in DynamicObject::Start.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sat, 14 Dec 2013 06:36:49 +0000 (07:36 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 14 Dec 2013 06:36:49 +0000 (07:36 +0100)
Fixes #5330

lib/base/dynamicobject.cpp
lib/base/dynamicobject.ti
lib/config/configitem.cpp

index 5f637ece9c2a2aa1a05cc44c7c65a89e74bd147a..55beefa124eb4a66ee13d7de33ac9b50440bc30c 100644 (file)
@@ -150,9 +150,24 @@ void DynamicObject::Register(void)
 void DynamicObject::Start(void)
 {
        ASSERT(!OwnsLock());
+       ObjectLock olock(this);
 
-       ASSERT(!IsActive());
-       SetActive(true);
+       SetStartCalled(true);
+}
+
+void DynamicObject::Activate(void)
+{
+       ASSERT(!OwnsLock());
+
+       Start();
+
+       ASSERT(GetStartCalled());
+
+       {
+               ObjectLock olock(this);
+               ASSERT(!IsActive());
+               SetActive(true);
+       }
 
        OnStarted(GetSelf());
 }
@@ -160,9 +175,27 @@ void DynamicObject::Start(void)
 void DynamicObject::Stop(void)
 {
        ASSERT(!OwnsLock());
+       ObjectLock olock(this);
+
+       SetStopCalled(true);
+}
+
+void DynamicObject::Deactivate(void)
+{
+       ASSERT(!OwnsLock());
+
+       {
+               ObjectLock olock(this);
+
+               if (!IsActive())
+                       return;
+
+               SetActive(false);
+       }
+
+       Stop();
 
-       ASSERT(IsActive());
-       SetActive(false);
+       ASSERT(GetStopCalled());
 
        OnStopped(GetSelf());
 }
@@ -299,8 +332,7 @@ void DynamicObject::StopObjects(void)
 {
        BOOST_FOREACH(const DynamicType::Ptr& dt, DynamicType::GetTypes()) {
                BOOST_FOREACH(const DynamicObject::Ptr& object, dt->GetObjects()) {
-                       if (object->IsActive())
-                               object->Stop();
+                       object->Deactivate();
                }
        }
 }
index bbf361e73082e0ef886ecb925074f85b5bcece8c..c68aec7ade0a62517182f8783dd57620c30906da 100644 (file)
@@ -10,6 +10,8 @@ abstract class DynamicObject
        [config] Array::Ptr domains;
        [config] Array::Ptr authorities;
        [get_protected] bool active;
+       [get_protected] bool start_called;
+       [get_protected] bool stop_called;
        Dictionary::Ptr authority_info;
        [protected] Dictionary::Ptr extensions;
 };
index 76177353d38466670f70aa10b6a1705eb88a28b6..0b1f242b4bdef61a721e536e8419461592a80cc8 100644 (file)
@@ -337,7 +337,7 @@ bool ConfigItem::ActivateItems(bool validateOnly)
 #ifdef _DEBUG
                        Log(LogDebug, "config", "Activating object '" + object->GetName() + "' of type '" + object->GetType()->GetName() + "'");
 #endif /* _DEBUG */
-                       upq.Enqueue(boost::bind(&DynamicObject::Start, object));
+                       upq.Enqueue(boost::bind(&DynamicObject::Activate, object));
                }
        }