From 8573636cc9a9d51e4001f3b0a5507b1e434ed98e Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 12 Mar 2015 11:43:04 +0100 Subject: [PATCH] Fix crash in Dependency::Stop() This partially reverts the fix in #8436 fixes #8687 refs #8436 --- lib/base/application.cpp | 17 +++++++++-------- lib/base/application.hpp | 3 +-- lib/db_ido_mysql/idomysqlconnection.cpp | 6 ++---- lib/db_ido_pgsql/idopgsqlconnection.cpp | 5 ++--- lib/remote/apilistener.cpp | 2 +- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 7ce329e24..4d72652b4 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -57,7 +57,6 @@ static bool l_InExceptionHandler = false; int Application::m_ArgC; char **Application::m_ArgV; double Application::m_StartTime; -int Application::m_ExitStatus = 0; /** * Constructor for the Application class. @@ -107,6 +106,12 @@ Application::~Application(void) void Application::Exit(int rc) { + if (rc) + Log(LogCritical, "Application") + << "Shutting down after a fatal error; exit code: " << rc; + else + Log(LogInformation, "Application", "Shutting down..."); + std::cout.flush(); BOOST_FOREACH(const Logger::Ptr& logger, Logger::GetLoggers()) { @@ -310,11 +315,6 @@ mainloop: goto mainloop; } - if (m_ExitStatus) - Log(LogInformation, "Application", "Shutting down Icinga after a fatal error."); - else - Log(LogInformation, "Application", "Shutting down Icinga..."); - DynamicObject::StopObjects(); Application::GetInstance()->OnShutdown(); @@ -361,9 +361,10 @@ pid_t Application::StartReloadProcess(void) * Signals the application to shut down during the next * execution of the event loop. */ -void Application::RequestShutdown(int rc) +void Application::RequestShutdown(void) { - m_ExitStatus = rc > m_ExitStatus ? rc : m_ExitStatus; + Log(LogInformation, "Application", "Received request to shut down."); + m_ShuttingDown = true; } diff --git a/lib/base/application.hpp b/lib/base/application.hpp index bc2b73a1b..37bf6aa99 100644 --- a/lib/base/application.hpp +++ b/lib/base/application.hpp @@ -69,7 +69,7 @@ public: static void InstallExceptionHandlers(void); - static void RequestShutdown(int rc = 0); + static void RequestShutdown(void); static void RequestRestart(void); static void RequestReopenLogs(void); @@ -162,7 +162,6 @@ private: static bool m_Debugging; /**< Whether debugging is enabled. */ static LogSeverity m_DebuggingSeverity; /**< Whether debugging severity is set. */ static double m_StartTime; - static int m_ExitStatus; #ifndef _WIN32 static void SigIntTermHandler(int signum); diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index e66479ba4..bf2f660cc 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -228,8 +228,7 @@ void IdoMysqlConnection::Reconnect(void) Log(LogCritical, "IdoMysqlConnection", "Schema does not provide any valid version! Verify your schema installation."); - Application::RequestShutdown(EXIT_FAILURE); - return; + Application::Exit(EXIT_FAILURE); } DiscardRows(result); @@ -246,8 +245,7 @@ void IdoMysqlConnection::Reconnect(void) << "Schema version '" << version << "' does not match the required version '" << IDO_COMPAT_SCHEMA_VERSION << "' (or newer)! Please check the upgrade documentation."; - Application::RequestShutdown(EXIT_FAILURE); - return; + Application::Exit(EXIT_FAILURE); } String instanceName = GetInstanceName(); diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp index 54622c6c9..122075a4f 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.cpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp @@ -234,7 +234,7 @@ void IdoPgsqlConnection::Reconnect(void) Log(LogCritical, "IdoPgsqlConnection", "Schema does not provide any valid version! Verify your schema installation."); - BOOST_THROW_EXCEPTION(std::runtime_error("Schema does not provide any valid version! Verify your schema installation.")); + Application::Exit(EXIT_FAILURE); } String version = row->Get("version"); @@ -250,8 +250,7 @@ void IdoPgsqlConnection::Reconnect(void) << "Schema version '" << version << "' does not match the required version '" << IDO_COMPAT_SCHEMA_VERSION << "' (or newer)! Please check the upgrade documentation."; - Application::RequestShutdown(EXIT_FAILURE); - return; + Application::Exit(EXIT_FAILURE); } String instanceName = GetInstanceName(); diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 7fe35b5c9..42042270a 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -110,7 +110,7 @@ void ApiListener::Start(void) if (!AddListener(GetBindHost(), GetBindPort())) { Log(LogCritical, "ApiListener") << "Cannot add listener on host '" << GetBindHost() << "' for port '" << GetBindPort() << "'."; - Application::RequestShutdown(EXIT_FAILURE); + Application::Exit(EXIT_FAILURE); } m_Timer = new Timer();