[icinga-checkins] icinga.org: icinga2/master: Bugfix: Deadlock in SigHupHandler due to Event: :Post not being signal-safe

git at icinga.org git at icinga.org
Sun Feb 3 16:02:37 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sun Feb  3 16:00:53 2013 +0100

Bugfix: Deadlock in SigHupHandler due to Event::Post not being signal-safe

Fixes #3622

---

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

diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp
index 23ebe01..8b70cfe 100644
--- a/icinga-app/icinga.cpp
+++ b/icinga-app/icinga.cpp
@@ -33,6 +33,11 @@ namespace po = boost::program_options;
 static po::variables_map g_AppParams;
 static vector<ConfigItem::WeakPtr> g_ConfigItems;
 
+#ifndef _WIN32
+static bool g_ReloadConfig = false;
+static Timer::Ptr g_ReloadConfigTimer;
+#endif /* _WIN32 */
+
 static bool LoadConfigFiles(void)
 {
 	set<ConfigItem::Ptr> allItems;
@@ -97,13 +102,20 @@ static bool LoadConfigFiles(void)
 
 }
 
+static void ReloadConfigTimerHandler(void)
+{
+	if (g_ReloadConfig) {
+		Logger::Write(LogInformation, "icinga-app", "Received SIGHUP. Reloading config files.");
+		LoadConfigFiles();
+		g_ReloadConfig = false;
+	}
+}
+
 static void SigHupHandler(int signum)
 {
 	assert(signum == SIGHUP);
 
-	Logger::Write(LogInformation, "icinga-app", "Received SIGHUP. Reloading config files.");
-
-	Event::Post(boost::bind(&LoadConfigFiles));
+	g_ReloadConfig = true;
 }
 
 /**
@@ -252,6 +264,11 @@ int main(int argc, char **argv)
 	memset(&sa, 0, sizeof(sa));
 	sa.sa_handler = &SigHupHandler;
 	sigaction(SIGHUP, &sa, NULL);
+
+	g_ReloadConfigTimer = boost::make_shared<Timer>();
+	g_ReloadConfigTimer->SetInterval(1);
+	g_ReloadConfigTimer->OnTimerExpired.connect(boost::bind(&ReloadConfigTimerHandler));
+	g_ReloadConfigTimer->Start();
 #endif /* _WIN32 */
 
 	return app->Run();





More information about the icinga-checkins mailing list