mirror of https://github.com/Icinga/icinga2.git
Handle some exceptions that previously caused crashes.
This commit is contained in:
parent
c5479057f7
commit
0cb232f494
|
@ -132,20 +132,25 @@ int main(int argc, char **argv)
|
|||
Component::AddSearchDir(ICINGA_LIBDIR);
|
||||
#endif /* ICINGA_LIBDIR */
|
||||
|
||||
DynamicObject::BeginTx();
|
||||
try {
|
||||
DynamicObject::BeginTx();
|
||||
|
||||
/* load config file */
|
||||
String configFile = argv[2];
|
||||
vector<ConfigItem::Ptr> configItems = ConfigCompiler::CompileFile(configFile);
|
||||
/* load config file */
|
||||
String configFile = argv[2];
|
||||
vector<ConfigItem::Ptr> configItems = ConfigCompiler::CompileFile(configFile);
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Executing config items...");
|
||||
Logger::Write(LogInformation, "icinga", "Executing config items...");
|
||||
|
||||
BOOST_FOREACH(const ConfigItem::Ptr& item, configItems) {
|
||||
item->Commit();
|
||||
BOOST_FOREACH(const ConfigItem::Ptr& item, configItems) {
|
||||
item->Commit();
|
||||
}
|
||||
|
||||
DynamicObject::FinishTx();
|
||||
} catch (const exception& ex) {
|
||||
Logger::Write(LogCritical, "icinga", "Configuration error: " + String(ex.what()));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
DynamicObject::FinishTx();
|
||||
|
||||
Application::Ptr app = Application::GetInstance();
|
||||
|
||||
if (!app)
|
||||
|
|
|
@ -167,11 +167,19 @@ void Application::TimeWatchThreadProc(void)
|
|||
* Signals the application to shut down during the next
|
||||
* execution of the event loop.
|
||||
*/
|
||||
void Application::Shutdown(void)
|
||||
void Application::RequestShutdown(void)
|
||||
{
|
||||
m_ShuttingDown = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminates the application.
|
||||
*/
|
||||
void Application::Terminate(int exitCode)
|
||||
{
|
||||
_exit(exitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the full path of the executable.
|
||||
*
|
||||
|
@ -283,7 +291,7 @@ void Application::SigIntHandler(int signum)
|
|||
if (!instance)
|
||||
return;
|
||||
|
||||
instance->Shutdown();
|
||||
instance->RequestShutdown();
|
||||
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
|
@ -302,7 +310,7 @@ BOOL WINAPI Application::CtrlHandler(DWORD type)
|
|||
if (!instance)
|
||||
return TRUE;
|
||||
|
||||
instance->GetInstance()->Shutdown();
|
||||
instance->GetInstance()->RequestShutdown();
|
||||
|
||||
SetConsoleCtrlHandler(NULL, FALSE);
|
||||
return TRUE;
|
||||
|
@ -347,7 +355,8 @@ int Application::Run(int argc, char **argv)
|
|||
}
|
||||
|
||||
/**
|
||||
* Grabs the PID file lock and updates the PID.
|
||||
* Grabs the PID file lock and updates the PID. Terminates the application
|
||||
* if the PID file is already locked by another instance of the application.
|
||||
*
|
||||
* @param filename The name of the PID file.
|
||||
*/
|
||||
|
@ -366,9 +375,11 @@ void Application::UpdatePidFile(const String& filename)
|
|||
if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) {
|
||||
ClosePidFile();
|
||||
|
||||
throw_exception(runtime_error("Another instance of the application is "
|
||||
Logger::Write(LogCritical, "base",
|
||||
"Another instance of the application is "
|
||||
"already running. Remove the '" + filename + "' file if "
|
||||
"you're certain that this is not the case."));
|
||||
"you're certain that this is not the case.");
|
||||
Terminate(EXIT_FAILURE);
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
|
|
|
@ -49,7 +49,8 @@ public:
|
|||
*/
|
||||
virtual int Main(const vector<String>& args) = 0;
|
||||
|
||||
static void Shutdown(void);
|
||||
static void RequestShutdown(void);
|
||||
static void Terminate(int exitCode);
|
||||
|
||||
static bool IsDebugging(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue