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
This commit is contained in:
Wladimir J. van der Laan 2018-05-07 14:31:08 +02:00
commit 57aae632e2
No known key found for this signature in database
GPG key ID: 1E4AED62986CD25D

View file

@ -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);