From 39d56be3b1cbecfb903617a63355b57f61424a73 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Tue, 15 May 2012 11:05:57 +0100 Subject: [PATCH] Fixed incomplete set_service_recovery(). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit A rogue return prevented set_service_recovery() from actually doing anything. Also we weren't checking for failure in ChangeServiceConfig2(). We expect ERROR_INVALID_LEVEL on pre-Vista Windows but other errors were not detected. French translation by François-Régis Tardy. --- messages.mc | 13 +++++++++++++ service.cpp | 9 +++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/messages.mc b/messages.mc index f939c20..2172a72 100644 --- a/messages.mc +++ b/messages.mc @@ -495,3 +495,16 @@ Language = French Le service %1 a reçu le code de contrôle inconnu %2, qui sera donc ignoré. . +MessageId = +1 +SymbolicName = NSSM_EVENT_CHANGESERVICECONFIG2_FAILED +Severity = Informational +Language = English +Error configuring service failure actions for service %1. The service will not be subject to recovery actions if it exits gracefully with a non-zero exit code. +ChangeServiceConfig2() failed: +%2 +. +Language = French +Erreur lors de la configuration des actions en cas d'échec du service %1. Le service ne déclenchera aucune action de récupération s'il se termine normalement avec un code retour non nul. +ChangeServiceConfig2() a échoué: +. + diff --git a/service.cpp b/service.cpp index fd25163..7e9a9d7 100644 --- a/service.cpp +++ b/service.cpp @@ -225,14 +225,19 @@ void set_service_recovery(char *service_name) { SC_HANDLE service = OpenService(services, service_name, SC_MANAGER_ALL_ACCESS); if (! service) return; - return; SERVICE_FAILURE_ACTIONS_FLAG flag; ZeroMemory(&flag, sizeof(flag)); flag.fFailureActionsOnNonCrashFailures = true; /* This functionality was added in Vista so the call may fail */ - ChangeServiceConfig2(service, SERVICE_CONFIG_FAILURE_ACTIONS_FLAG, &flag); + if (! ChangeServiceConfig2(service, SERVICE_CONFIG_FAILURE_ACTIONS_FLAG, &flag)) { + unsigned long error = GetLastError(); + /* Pre-Vista we expect to fail with ERROR_INVALID_LEVEL */ + if (error != ERROR_INVALID_LEVEL) { + log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_CHANGESERVICECONFIG2_FAILED, service_name, error_string(error), 0); + } + } } int monitor_service() { -- 2.7.4