From: Iain Patterson Date: Thu, 31 Mar 2016 07:34:33 +0000 (+0100) Subject: Technically we should stop ignoring Control-C. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=76673b917b29d2a0206062f4bc132ae6e043b0d2;p=nssm.git Technically we should stop ignoring Control-C. Before signalling our application we implement a null Control-C handler so we don't get killed ourselves when signalling the process group. We should probably restore the default behaviour after signalling. --- diff --git a/process.cpp b/process.cpp index d1a9a49..62a46af 100644 --- a/process.cpp +++ b/process.cpp @@ -241,7 +241,8 @@ int kill_console(nssm_service_t *service, kill_t *k) { /* Ignore the event ourselves. */ ret = 0; - if (! SetConsoleCtrlHandler(0, TRUE)) { + bool ignored = SetConsoleCtrlHandler(0, TRUE); + if (! ignored) { log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SETCONSOLECTRLHANDLER_FAILED, k->name, error_string(GetLastError()), 0); ret = 4; } @@ -262,6 +263,11 @@ int kill_console(nssm_service_t *service, kill_t *k) { /* Wait for process to exit. */ if (await_single_handle(k->status_handle, k->status, k->process_handle, k->name, _T(__FUNCTION__), k->kill_console_delay)) ret = 6; + /* Remove our handler. */ + if (ignored && ! SetConsoleCtrlHandler(0, FALSE)) { + log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SETCONSOLECTRLHANDLER_FAILED, k->name, error_string(GetLastError()), 0); + } + return ret; }