From ce8aa5491f35c2cca03ba1877cd4c926b506a961 Mon Sep 17 00:00:00 2001 From: Chun Kuan Lee Date: Mon, 30 Apr 2018 23:31:11 +0800 Subject: [PATCH] Add Windows shutdown handler GitHub-Pull: #13131 Rebased-From: ddebde7 --- src/init.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 162c32c38cf49..382915a633585 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);