\r
/* Ignore the event ourselves. */\r
ret = 0;\r
- if (! SetConsoleCtrlHandler(0, TRUE)) {\r
+ bool ignored = SetConsoleCtrlHandler(0, TRUE);\r
+ if (! ignored) {\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SETCONSOLECTRLHANDLER_FAILED, k->name, error_string(GetLastError()), 0);\r
ret = 4;\r
}\r
/* Wait for process to exit. */\r
if (await_single_handle(k->status_handle, k->status, k->process_handle, k->name, _T(__FUNCTION__), k->kill_console_delay)) ret = 6;\r
\r
+ /* Remove our handler. */\r
+ if (ignored && ! SetConsoleCtrlHandler(0, FALSE)) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SETCONSOLECTRLHANDLER_FAILED, k->name, error_string(GetLastError()), 0);\r
+ }\r
+\r
return ret;\r
}\r
\r