summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/core.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/common/core.c b/src/common/core.c
index 89a002ebe..243fac24c 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -18,6 +18,8 @@
#include <string.h>
#ifndef _WIN32
#include <unistd.h>
+#else
+#include <windows.h> // Console close event handling
#endif
@@ -69,6 +71,35 @@ sigfunc *compat_signal(int signo, sigfunc *func)
#endif
/*======================================
+ * CORE : Console events for Windows
+ *--------------------------------------*/
+#ifdef _WIN32
+static BOOL WINAPI console_handler(DWORD c_event)
+{
+ switch(c_event)
+ {
+ case CTRL_CLOSE_EVENT:
+ case CTRL_LOGOFF_EVENT:
+ case CTRL_SHUTDOWN_EVENT:
+ if( shutdown_callback != NULL )
+ shutdown_callback();
+ else
+ runflag = CORE_ST_STOP;// auto-shutdown
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+static void cevents_init()
+{
+ if (SetConsoleCtrlHandler(console_handler,TRUE)==FALSE)
+ ShowWarning ("Unable to install the console handler!\n");
+}
+#endif
+
+/*======================================
* CORE : Signal Sub Function
*--------------------------------------*/
static void sig_proc(int sn)
@@ -251,6 +282,10 @@ int main (int argc, char **argv)
db_init();
signals_init();
+#ifdef _WIN32
+ cevents_init();
+#endif
+
timer_init();
socket_init();
plugins_init();