diff options
author | Chun Kuan Lee <ken2812221@gmail.com> | 2018-04-30 23:31:11 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2018-06-13 16:09:04 +0800 |
commit | ce8aa5491f35c2cca03ba1877cd4c926b506a961 (patch) | |
tree | e6c2d553f59f7f2e0f5f4daf2b1d013be8ab9eb4 | |
parent | 18b0c69e2fc9f9d5cd56659abab467c2c6826be2 (diff) |
Add Windows shutdown handler
GitHub-Pull: #13131
Rebased-From: ddebde7
-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 162c32c38c..382915a633 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -283,6 +283,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; @@ -292,6 +293,14 @@ static void HandleSIGHUP(int) { fReopenDebugLog = 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)) @@ -880,6 +889,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); |