From: Gunnar Beutner Date: Sat, 14 Dec 2013 06:36:49 +0000 (+0100) Subject: Fix another race condition in DynamicObject::Start. X-Git-Tag: v0.0.6~33 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4563bb355f32862bdf598733a62a6049b995bc0e;p=icinga2 Fix another race condition in DynamicObject::Start. Fixes #5330 --- diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index 5f637ece9..55beefa12 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -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(); } } } diff --git a/lib/base/dynamicobject.ti b/lib/base/dynamicobject.ti index bbf361e73..c68aec7ad 100644 --- a/lib/base/dynamicobject.ti +++ b/lib/base/dynamicobject.ti @@ -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; }; diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 76177353d..0b1f242b4 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -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)); } }