Skip to content

Commit ddebde7

Browse files
committed
Add Windows shutdown handler
1 parent 9e9b48d commit ddebde7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/init.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ void Shutdown()
298298
* The execution context the handler is invoked in is not guaranteed,
299299
* so we restrict handler operations to just touching variables:
300300
*/
301+
#ifndef WIN32
301302
static void HandleSIGTERM(int)
302303
{
303304
fRequestShutdown = true;
@@ -307,6 +308,14 @@ static void HandleSIGHUP(int)
307308
{
308309
fReopenDebugLog = true;
309310
}
311+
#else
312+
static BOOL WINAPI consoleCtrlHandler(DWORD dwCtrlType)
313+
{
314+
fRequestShutdown = true;
315+
Sleep(INFINITE);
316+
return true;
317+
}
318+
#endif
310319

311320
#ifndef WIN32
312321
static void registerSignalHandler(int signal, void(*handler)(int))
@@ -909,6 +918,8 @@ bool AppInitBasicSetup()
909918

910919
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
911920
signal(SIGPIPE, SIG_IGN);
921+
#else
922+
SetConsoleCtrlHandler(consoleCtrlHandler, true);
912923
#endif
913924

914925
std::set_new_handler(new_handler_terminate);

0 commit comments

Comments
 (0)