From: Gunnar Beutner Date: Wed, 16 Oct 2013 11:37:54 +0000 (+0200) Subject: Fix config validation. X-Git-Tag: v0.0.3~92 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=816d0e8d739eb5b46fa4841641ef23f83c2fdae2;p=icinga2 Fix config validation. Fixes #4888 --- diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 3b36435e9..bdf186423 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -48,7 +48,7 @@ ConfigItem::ItemMap ConfigItem::m_Items; ConfigItem::ConfigItem(const String& type, const String& name, bool abstract, const ExpressionList::Ptr& exprl, const std::vector& parents, const DebugInfo& debuginfo) - : m_Type(type), m_Name(name), m_Abstract(abstract), + : m_Type(type), m_Name(name), m_Abstract(abstract), m_Validated(false), m_ExpressionList(exprl), m_ParentNames(parents), m_DebugInfo(debuginfo) { } @@ -235,6 +235,9 @@ ConfigItem::Ptr ConfigItem::GetObject(const String& type, const String& name) void ConfigItem::ValidateItem(void) { + if (m_Validated) + return; + ConfigType::Ptr ctype = ConfigType::GetByName(GetType()); if (!ctype) { @@ -244,6 +247,8 @@ void ConfigItem::ValidateItem(void) } ctype->ValidateItem(GetSelf()); + + m_Validated = true; } bool ConfigItem::ActivateItems(bool validateOnly) @@ -258,6 +263,15 @@ bool ConfigItem::ActivateItems(bool validateOnly) item->Link(); } + if (ConfigCompilerContext::GetInstance()->HasErrors()) + return false; + + Log(LogInformation, "config", "Validating config items (step 1)..."); + + BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) { + item->ValidateItem(); + } + if (ConfigCompilerContext::GetInstance()->HasErrors()) return false; @@ -276,6 +290,8 @@ bool ConfigItem::ActivateItems(bool validateOnly) object->OnConfigLoaded(); } + Log(LogInformation, "config", "Validating config items (step 2)..."); + BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) { item->ValidateItem(); } diff --git a/lib/config/configitem.h b/lib/config/configitem.h index 834c03e01..93c76d3e2 100644 --- a/lib/config/configitem.h +++ b/lib/config/configitem.h @@ -73,6 +73,7 @@ private: String m_Type; /**< The object type. */ String m_Name; /**< The name. */ bool m_Abstract; /**< Whether this is a template. */ + bool m_Validated; /** Whether this object has been validated. */ ExpressionList::Ptr m_ExpressionList; std::vector m_ParentNames; /**< The names of parent configuration