Add Windows shutdown handler

GitHub-Pull: #13131
Rebased-From: ddebde7
This commit is contained in:
Chun Kuan Lee 2018-04-30 23:31:11 +08:00 committed by fanquake
parent 18b0c69e2f
commit ce8aa5491f
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

View File

@ -283,6 +283,7 @@ void Shutdown()
* The execution context the handler is invoked in is not guaranteed, * The execution context the handler is invoked in is not guaranteed,
* so we restrict handler operations to just touching variables: * so we restrict handler operations to just touching variables:
*/ */
#ifndef WIN32
static void HandleSIGTERM(int) static void HandleSIGTERM(int)
{ {
fRequestShutdown = true; fRequestShutdown = true;
@ -292,6 +293,14 @@ static void HandleSIGHUP(int)
{ {
fReopenDebugLog = true; fReopenDebugLog = true;
} }
#else
static BOOL WINAPI consoleCtrlHandler(DWORD dwCtrlType)
{
fRequestShutdown = true;
Sleep(INFINITE);
return true;
}
#endif
#ifndef WIN32 #ifndef WIN32
static void registerSignalHandler(int signal, void(*handler)(int)) 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 // Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
#else
SetConsoleCtrlHandler(consoleCtrlHandler, true);
#endif #endif
std::set_new_handler(new_handler_terminate); std::set_new_handler(new_handler_terminate);