Skip to content

Commit 57aae63

Browse files
committed
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
2 parents bd83704 + ddebde7 commit 57aae63

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
g_logger->m_reopen_file = 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))
@@ -912,6 +921,8 @@ bool AppInitBasicSetup()
912921

913922
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
914923
signal(SIGPIPE, SIG_IGN);
924+
#else
925+
SetConsoleCtrlHandler(consoleCtrlHandler, true);
915926
#endif
916927

917928
std::set_new_handler(new_handler_terminate);

0 commit comments

Comments
 (0)