mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 14:44:32 +02:00
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);
|
Component::AddSearchDir(ICINGA_LIBDIR);
|
||||||
#endif /* ICINGA_LIBDIR */
|
#endif /* ICINGA_LIBDIR */
|
||||||
|
|
||||||
DynamicObject::BeginTx();
|
try {
|
||||||
|
DynamicObject::BeginTx();
|
||||||
|
|
||||||
/* load config file */
|
/* load config file */
|
||||||
String configFile = argv[2];
|
String configFile = argv[2];
|
||||||
vector<ConfigItem::Ptr> configItems = ConfigCompiler::CompileFile(configFile);
|
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) {
|
BOOST_FOREACH(const ConfigItem::Ptr& item, configItems) {
|
||||||
item->Commit();
|
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();
|
Application::Ptr app = Application::GetInstance();
|
||||||
|
|
||||||
if (!app)
|
if (!app)
|
||||||
|
@ -167,11 +167,19 @@ void Application::TimeWatchThreadProc(void)
|
|||||||
* Signals the application to shut down during the next
|
* Signals the application to shut down during the next
|
||||||
* execution of the event loop.
|
* execution of the event loop.
|
||||||
*/
|
*/
|
||||||
void Application::Shutdown(void)
|
void Application::RequestShutdown(void)
|
||||||
{
|
{
|
||||||
m_ShuttingDown = true;
|
m_ShuttingDown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Terminates the application.
|
||||||
|
*/
|
||||||
|
void Application::Terminate(int exitCode)
|
||||||
|
{
|
||||||
|
_exit(exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the full path of the executable.
|
* Retrieves the full path of the executable.
|
||||||
*
|
*
|
||||||
@ -283,7 +291,7 @@ void Application::SigIntHandler(int signum)
|
|||||||
if (!instance)
|
if (!instance)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
instance->Shutdown();
|
instance->RequestShutdown();
|
||||||
|
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
@ -302,7 +310,7 @@ BOOL WINAPI Application::CtrlHandler(DWORD type)
|
|||||||
if (!instance)
|
if (!instance)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
instance->GetInstance()->Shutdown();
|
instance->GetInstance()->RequestShutdown();
|
||||||
|
|
||||||
SetConsoleCtrlHandler(NULL, FALSE);
|
SetConsoleCtrlHandler(NULL, FALSE);
|
||||||
return TRUE;
|
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.
|
* @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) {
|
if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) {
|
||||||
ClosePidFile();
|
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 "
|
"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 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
@ -49,7 +49,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual int Main(const vector<String>& args) = 0;
|
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);
|
static bool IsDebugging(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user