mirror of https://github.com/Icinga/icinga2.git
Implemented SIGINT handler
This commit is contained in:
parent
6fea4d6baa
commit
2e8ed6a6b5
|
@ -359,3 +359,15 @@ bool Application::IsDebugging(void) const
|
|||
{
|
||||
return m_Debugging;
|
||||
}
|
||||
|
||||
void Application::SigIntHandler(int signum)
|
||||
{
|
||||
Application::Instance->Shutdown();
|
||||
|
||||
#ifndef _WIN32
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = SIG_DFL;
|
||||
sigaction(SIGINT, &sa, NULL);
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
|
|
|
@ -45,8 +45,14 @@ public:
|
|||
const string& GetExeDirectory(void);
|
||||
|
||||
bool IsDebugging(void) const;
|
||||
void SigIntHandler(int signum);
|
||||
};
|
||||
|
||||
inline void sigint_handler(int signum)
|
||||
{
|
||||
Application::Instance->SigIntHandler(signum);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
int application_main(int argc, char **argv)
|
||||
{
|
||||
|
@ -54,6 +60,13 @@ int application_main(int argc, char **argv)
|
|||
|
||||
Application::Instance = make_shared<T>();
|
||||
|
||||
#ifndef _WIN32
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = sigint_handler;
|
||||
sigaction(SIGINT, &sa, NULL);
|
||||
#endif /* _WIN32 */
|
||||
|
||||
vector<string> args;
|
||||
|
||||
for (int i = 0; i < argc; i++)
|
||||
|
@ -71,7 +84,7 @@ int application_main(int argc, char **argv)
|
|||
|
||||
string klass = typeid(ex).name();
|
||||
|
||||
#ifdef HAVE_GCC_ABI_DEMANGLE
|
||||
#ifdef HAVE_GCC_ABI_DEMANGLE
|
||||
int status;
|
||||
char *realname = abi::__cxa_demangle(klass.c_str(), 0, 0, &status);
|
||||
|
||||
|
@ -79,7 +92,7 @@ int application_main(int argc, char **argv)
|
|||
klass = string(realname);
|
||||
free(realname);
|
||||
}
|
||||
#endif /* HAVE_GCC_ABI_DEMANGLE */
|
||||
#endif /* HAVE_GCC_ABI_DEMANGLE */
|
||||
|
||||
cout << "Exception: " << klass << endl;
|
||||
cout << "Message: " << ex.GetMessage() << endl;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
void Sleep(unsigned long milliseconds);
|
||||
|
||||
|
|
Loading…
Reference in New Issue