};
StartServiceCtrlDispatcher(dispatchTable);
- Application::Exit(1);
+ Application::Exit(EXIT_FAILURE);
}
#endif /* _WIN32 */
int Application::m_ArgC;
char **Application::m_ArgV;
double Application::m_StartTime;
+int Application::m_ExitStatus = 0;
/**
* Constructor for the Application class.
}
UninitializeBase();
-
#ifdef I2_DEBUG
exit(rc);
#else /* I2_DEBUG */
goto mainloop;
}
- Log(LogInformation, "Application", "Shutting down Icinga...");
+ 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();
* Signals the application to shut down during the next
* execution of the event loop.
*/
-void Application::RequestShutdown(void)
+void Application::RequestShutdown(int rc)
{
+ m_ExitStatus = rc > m_ExitStatus ? rc : m_ExitStatus;
m_ShuttingDown = true;
}
static void InstallExceptionHandlers(void);
- static void RequestShutdown(void);
+ static void RequestShutdown(int rc = 0);
static void RequestRestart(void);
static void RequestReopenLogs(void);
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);
if (ret == pid) {
Log(LogCritical, "cli", "The daemon could not be started. See log output for details.");
- Application::Exit(EXIT_FAILURE);
+ _exit(EXIT_FAILURE);
} else if (ret == -1) {
Log(LogCritical, "cli")
<< "waitpid() failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
- Application::Exit(EXIT_FAILURE);
+ _exit(EXIT_FAILURE);
}
- Application::Exit(0);
+ _exit(EXIT_SUCCESS);
}
Application::GetTP().Start();
if (!row) {
Log(LogCritical, "IdoMysqlConnection", "Schema does not provide any valid version! Verify your schema installation.");
- Application::Exit(EXIT_FAILURE);
+ Application::RequestShutdown(EXIT_FAILURE);
}
DiscardRows(result);
<< "Schema version '" << version << "' does not match the required version '"
<< SCHEMA_VERSION << "'! Please check the upgrade documentation.";
- Application::Exit(EXIT_FAILURE);
+ Application::RequestShutdown(EXIT_FAILURE);
}
String instanceName = GetInstanceName();
if (!row) {
Log(LogCritical, "IdoPgsqlConnection", "Schema does not provide any valid version! Verify your schema installation.");
- Application::Exit(EXIT_FAILURE);
+ Application::RequestShutdown(EXIT_FAILURE);
}
String version = row->Get("version");
<< "Schema version '" << version << "' does not match the required version '"
<< SCHEMA_VERSION << "'! Please check the upgrade documentation.";
- Application::Exit(EXIT_FAILURE);
+ Application::RequestShutdown(EXIT_FAILURE);
}
String instanceName = GetInstanceName();
try {
cert = GetX509Certificate(GetCertPath());
} catch (const std::exception&) {
- Log(LogCritical, "ApiListener")
- << "Cannot get certificate from cert path: '" << GetCertPath() << "'.";
- Application::Exit(EXIT_FAILURE);
+ BOOST_THROW_EXCEPTION(ScriptError("Cannot get certificate from cert path: '" + GetCertPath() + "'.", GetDebugInfo()));
}
try {
SetIdentity(GetCertificateCN(cert));
} catch (const std::exception&) {
- Log(LogCritical, "ApiListener")
- << "Cannot get certificate common name from cert path: '" << GetCertPath() << "'.";
- Application::Exit(EXIT_FAILURE);
+ BOOST_THROW_EXCEPTION(ScriptError("Cannot get certificate common name from cert path: '" + GetCertPath() + "'.", GetDebugInfo()));
}
Log(LogInformation, "ApiListener")
try {
m_SSLContext = MakeSSLContext(GetCertPath(), GetKeyPath(), GetCaPath());
} catch (const std::exception&) {
- Log(LogCritical, "ApiListener")
- << "Cannot make SSL context for cert path: '" << GetCertPath() << "' key path: '" << GetKeyPath() << "' ca path: '" << GetCaPath() << "'.";
- Application::Exit(EXIT_FAILURE);
+ BOOST_THROW_EXCEPTION(ScriptError("Cannot make SSL context for cert path: '" + GetCertPath() + "' key path: '" + GetKeyPath() + "' ca path: '" + GetCaPath() + "'.", GetDebugInfo()));
}
if (!GetCrlPath().IsEmpty()) {
try {
AddCRLToSSLContext(m_SSLContext, GetCrlPath());
} catch (const std::exception&) {
- Log(LogCritical, "ApiListener")
- << "Cannot add certificate revocation list to SSL context for crl path: '" << GetCrlPath() << "'.";
- Application::Exit(EXIT_FAILURE);
+ BOOST_THROW_EXCEPTION(ScriptError("Cannot add certificate revocation list to SSL context for crl path: '" + GetCrlPath() + "'.", GetDebugInfo()));
}
}
}
void ApiListener::OnAllConfigLoaded(void)
{
- if (!Endpoint::GetByName(GetIdentity())) {
- Log(LogCritical, "ApiListener")
- << "Endpoint object for '" << GetIdentity() << "' is missing.";
- Application::Exit(EXIT_FAILURE);
- }
+ if (!Endpoint::GetByName(GetIdentity()))
+ BOOST_THROW_EXCEPTION(ScriptError("Endpoint object for '" + GetIdentity() + "' is missing.", GetDebugInfo()));
}
/**
if (!AddListener(GetBindHost(), GetBindPort())) {
Log(LogCritical, "ApiListener")
<< "Cannot add listener on host '" << GetBindHost() << "' for port '" << GetBindPort() << "'.";
- Application::Exit(EXIT_FAILURE);
+ Application::RequestShutdown(EXIT_FAILURE);
}
m_Timer = new Timer();