]> granicus.if.org Git - icinga2/commitdiff
Fix config validation.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 16 Oct 2013 11:37:54 +0000 (13:37 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 16 Oct 2013 11:37:54 +0000 (13:37 +0200)
Fixes #4888

lib/config/configitem.cpp
lib/config/configitem.h

index 3b36435e924de6552fcdbcdfa721ff54c41710de..bdf186423f3f0ce12284621892a13695f603aeb7 100644 (file)
@@ -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<String>& 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();
        }
index 834c03e01213c4a7d69fa855b19a3799242fed8d..93c76d3e271d9ff95e5a770b0e37223aff7aedee 100644 (file)
@@ -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<String> m_ParentNames; /**< The names of parent configuration