]> granicus.if.org Git - icinga2/commitdiff
Implemented SIGINT handler
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 3 Apr 2012 17:49:56 +0000 (19:49 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 3 Apr 2012 17:57:09 +0000 (19:57 +0200)
base/application.cpp
base/application.h
base/unix.h

index 01840c581696a5dcf330908331b31dba669ac6da..901b59b855d1a24495ed894eb9fb4ceb8f80a237 100644 (file)
@@ -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 */
+}
index 406cc8f6cb19c8cc51d8d094fd688bd2fff59d74..e4211146b5c3d7fb5aebac0ec6bbf4e5cb45804d 100644 (file)
@@ -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;
index ea946f348dab8fb9cc1ca0428c0a27bf82b7e7ab..f0eba440f8e1452a87d91799e2397ebad4d75253 100644 (file)
@@ -11,6 +11,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <pthread.h>
+#include <signal.h>
 
 void Sleep(unsigned long milliseconds);