[icinga-checkins] icinga.org: icinga2/master: Delete removed config objects after SIGHUP

git at icinga.org git at icinga.org
Sun Feb 3 12:26:22 CET 2013


Module: icinga2
Branch: master
Commit: ba49fd38e120b3b67a8a31909b0a76b67352ef90
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=ba49fd38e120b3b67a8a31909b0a76b67352ef90

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sun Feb  3 12:26:22 2013 +0100

Delete removed config objects after SIGHUP

Fixes #3620

---

 icinga-app/icinga.cpp |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp
index dc4c860..23ebe01 100644
--- a/icinga-app/icinga.cpp
+++ b/icinga-app/icinga.cpp
@@ -31,9 +31,12 @@ using namespace icinga;
 namespace po = boost::program_options;
 
 static po::variables_map g_AppParams;
+static vector<ConfigItem::WeakPtr> g_ConfigItems;
 
 static bool LoadConfigFiles(void)
 {
+	set<ConfigItem::Ptr> allItems;
+
 	try {
 		BOOST_FOREACH(const String& configPath, g_AppParams["config"].as<vector<String> >()) {
 			vector<ConfigItem::Ptr> items;
@@ -67,8 +70,25 @@ static bool LoadConfigFiles(void)
 					ctype->ValidateObject(object);
 				}
 			}
+
+			std::copy(items.begin(), items.end(), std::inserter(allItems, allItems.begin()));
 		}
 
+		BOOST_FOREACH(const ConfigItem::WeakPtr& witem, g_ConfigItems) {
+			ConfigItem::Ptr item = witem.lock();
+
+			/* Ignore this item if it's not active anymore */
+			if (!item || ConfigItem::GetObject(item->GetType(), item->GetName()) != item)
+				continue;
+
+			/* Remove the object if it's not in the list of current items */
+			if (allItems.find(item) == allItems.end())
+				item->Unregister();
+		}
+
+		g_ConfigItems.clear();
+		std::copy(allItems.begin(), allItems.end(), std::back_inserter(g_ConfigItems));
+
 		return true;
 	} catch (const exception& ex) {
 		Logger::Write(LogCritical, "icinga-app", "Configuration error: " + String(ex.what()));





More information about the icinga-checkins mailing list