diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -299,6 +299,7 @@ * 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; } @@ -306,6 +307,13 @@ static void HandleSIGHUP(int) { GetLogger().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)) { @@ -1453,6 +1461,8 @@ // 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);