diff options
author | Constantin Wenger <constantin.wenger@googlemail.com> | 2011-11-06 15:17:18 +0100 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-11-06 19:24:44 +0200 |
commit | 61f2cc45c275ce493ec7f53e6f22fb8cda89db31 (patch) | |
tree | 1c8c4199467e4a0718ede0deff9da70e861de87a /src | |
parent | c1d92d72e1af6d99c6fdbeec0900326dd9938fd2 (diff) | |
download | minetest-61f2cc45c275ce493ec7f53e6f22fb8cda89db31.tar.gz minetest-61f2cc45c275ce493ec7f53e6f22fb8cda89db31.tar.bz2 minetest-61f2cc45c275ce493ec7f53e6f22fb8cda89db31.zip |
Command-line signal handling for Windows
Diffstat (limited to 'src')
-rw-r--r-- | src/porting.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/porting.cpp b/src/porting.cpp index f349c0ce5..f3a0ab074 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -75,10 +75,45 @@ void signal_handler_init(void) } #else // _WIN32 + #include <signal.h> + #include <windows.h> + + BOOL WINAPI event_handler(DWORD sig) + { + switch(sig) + { + case CTRL_C_EVENT: + case CTRL_CLOSE_EVENT: + case CTRL_LOGOFF_EVENT: + case CTRL_SHUTDOWN_EVENT: + + if(g_killed == false) + { + dstream<<DTIME<<"INFO: event_handler(): " + <<"Ctrl+C, Close Event, Logoff Event or Shutdown Event, shutting down."<<std::endl; + dstream<<DTIME<<"INFO: event_handler(): " + <<"Printing debug stacks"<<std::endl; + debug_stacks_print(); + + g_killed = true; + } + else + { + (void)signal(SIGINT, SIG_DFL); + } + break; + case CTRL_BREAK_EVENT: + break; + } + + return TRUE; + } + void signal_handler_init(void) { - // No-op + dstream<<"signal_handler_init()"<<std::endl; + SetConsoleCtrlHandler( (PHANDLER_ROUTINE)event_handler,TRUE); } #endif |