From 021655a300b7d9518d473207a30a61ecccf853e9 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Sat, 28 Dec 2013 16:33:38 +0000 Subject: [PATCH] Fixed print_message() when out of memory. We were passing NSSM_EVENT_OUT_OF_MEMORY to print_message() but print_message() expects printf-style message strings and NSSM_EVENT_* strings use %1, %2 etc. Instead we now use the new message NSSM_MESSAGE_OUT_OF_MEMORY when printing memory errors to the console. --- messages.mc | 13 +++++++++++++ service.cpp | 10 +++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/messages.mc b/messages.mc index 1a36fe2..6750def 100644 --- a/messages.mc +++ b/messages.mc @@ -128,6 +128,19 @@ Language = Italian Per rimuovere un servizio da riga di comando: nssm remove confirm . +MessageId = +1 +SymbolicName = NSSM_MESSAGE_OUT_OF_MEMORY +Severity = Error +Language = English +Out of memory for %s in %s!%0 +. +Language = French +Mémoire insuffisante pour %s dans %s!%0 +. +Language = Italian +Memoria insufficiente per %s in %s!%0 +. + MessageId = +1 SymbolicName = NSSM_MESSAGE_OPEN_SERVICE_MANAGER_FAILED Severity = Informational diff --git a/service.cpp b/service.cpp index 177ac15..aff8cbb 100644 --- a/service.cpp +++ b/service.cpp @@ -90,7 +90,7 @@ int pre_install_service(int argc, TCHAR **argv) { if (argc < 2) return nssm_gui(IDD_INSTALL, service); if (! service) { - print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("pre_install_service()")); + print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("service"), _T("pre_install_service()")); return 1; } _sntprintf_s(service->exe, _countof(service->exe), _TRUNCATE, _T("%s"), argv[1]); @@ -155,7 +155,7 @@ int pre_edit_service(int argc, TCHAR **argv) { if (error == ERROR_INSUFFICIENT_BUFFER) { qsc = (QUERY_SERVICE_CONFIG *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bufsize); if (! qsc) { - print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, _T("QUERY_SERVICE_CONFIG"), _T("pre_edit_service()"), 0); + print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("QUERY_SERVICE_CONFIG"), _T("pre_edit_service()"), 0); return 4; } } @@ -199,7 +199,7 @@ int pre_edit_service(int argc, TCHAR **argv) { HeapFree(GetProcessHeap(), 0, qsc); CloseHandle(service->handle); CloseServiceHandle(services); - print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, _T("username"), _T("pre_edit_service()")); + print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("username"), _T("pre_edit_service()")); return 4; } } @@ -222,7 +222,7 @@ int pre_edit_service(int argc, TCHAR **argv) { if (! info) { CloseHandle(service->handle); CloseServiceHandle(services); - print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, _T("SERVICE_DELAYED_AUTO_START_INFO"), _T("pre_edit_service()")); + print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("SERVICE_DELAYED_AUTO_START_INFO"), _T("pre_edit_service()")); return 5; } @@ -254,7 +254,7 @@ int pre_edit_service(int argc, TCHAR **argv) { if (! description) { CloseHandle(service->handle); CloseServiceHandle(services); - print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, _T("SERVICE_CONFIG_DESCRIPTION"), _T("pre_edit_service()")); + print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("SERVICE_CONFIG_DESCRIPTION"), _T("pre_edit_service()")); return 6; } -- 2.20.1