Skip to content

Commit

Permalink
Add Windows shutdown handler
Browse files Browse the repository at this point in the history
GitHub-Pull: #13131
Rebased-From: ddebde7
  • Loading branch information
ken2812221 authored and fanquake committed Jun 13, 2018
1 parent 18b0c69 commit ce8aa54
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/init.cpp
Expand Up @@ -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;
Expand All @@ -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))
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ce8aa54

Please sign in to comment.