diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-05-07 14:31:08 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-05-07 14:33:03 +0200 |
commit | 57aae632e28833c1ee33462858d79ed3de201a3c (patch) | |
tree | 61f44d48debb0c7e6fc5d6175bbb9c79f2454d6f /src/init.cpp | |
parent | bd83704ec6fa9a6564cd0f489efa65c1ecb095c2 (diff) | |
parent | ddebde71efe17eb3b1367948e9b728f6a86696ab (diff) |
Merge #13131: Add Windows shutdown handler
ddebde7 Add Windows shutdown handler (Chun Kuan Lee)
Pull request description:
Exit properly when clicked the red X of Windows Console
Tree-SHA512: f030edd08868390662b42abfa1dc6bd702166c6c19f5b1f8e7482e202451e79fb6f37ea672c26c2eb0d32c367bfca86160fbee624696c53828f280b7070be6a0
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp index 3239252778..7d8f462ef1 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -298,6 +298,7 @@ void Shutdown() * The execution context the handler is invoked in is not guaranteed, * so we restrict handler operations to just touching variables: */ +#ifndef WIN32 static void HandleSIGTERM(int) { fRequestShutdown = true; @@ -307,6 +308,14 @@ static void HandleSIGHUP(int) { g_logger->m_reopen_file = true; } +#else +static BOOL WINAPI consoleCtrlHandler(DWORD dwCtrlType) +{ + fRequestShutdown = true; + Sleep(INFINITE); + return true; +} +#endif #ifndef WIN32 static void registerSignalHandler(int signal, void(*handler)(int)) @@ -912,6 +921,8 @@ bool AppInitBasicSetup() // Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly signal(SIGPIPE, SIG_IGN); +#else + SetConsoleCtrlHandler(consoleCtrlHandler, true); #endif std::set_new_handler(new_handler_terminate); |