Fixed print_message() when out of memory.
authorIain Patterson <me@iain.cx>
Sat, 28 Dec 2013 16:33:38 +0000 (16:33 +0000)
committerIain Patterson <me@iain.cx>
Sat, 28 Dec 2013 17:12:13 +0000 (17:12 +0000)
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
service.cpp

index 1a36fe2..6750def 100644 (file)
@@ -128,6 +128,19 @@ Language = Italian
 Per rimuovere un servizio da riga di comando: nssm remove <servicename> 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
index 177ac15..aff8cbb 100644 (file)
@@ -90,7 +90,7 @@ int pre_install_service(int argc, TCHAR **argv) {
   if (argc < 2) return nssm_gui(IDD_INSTALL, service);\r
 \r
   if (! service) {\r
-    print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("pre_install_service()"));\r
+    print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("service"), _T("pre_install_service()"));\r
     return 1;\r
   }\r
   _sntprintf_s(service->exe, _countof(service->exe), _TRUNCATE, _T("%s"), argv[1]);\r
@@ -155,7 +155,7 @@ int pre_edit_service(int argc, TCHAR **argv) {
   if (error == ERROR_INSUFFICIENT_BUFFER) {\r
     qsc = (QUERY_SERVICE_CONFIG *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bufsize);\r
     if (! qsc) {\r
-      print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, _T("QUERY_SERVICE_CONFIG"), _T("pre_edit_service()"), 0);\r
+      print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("QUERY_SERVICE_CONFIG"), _T("pre_edit_service()"), 0);\r
       return 4;\r
     }\r
   }\r
@@ -199,7 +199,7 @@ int pre_edit_service(int argc, TCHAR **argv) {
       HeapFree(GetProcessHeap(), 0, qsc);\r
       CloseHandle(service->handle);\r
       CloseServiceHandle(services);\r
-      print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, _T("username"), _T("pre_edit_service()"));\r
+      print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("username"), _T("pre_edit_service()"));\r
       return 4;\r
     }\r
   }\r
@@ -222,7 +222,7 @@ int pre_edit_service(int argc, TCHAR **argv) {
       if (! info) {\r
         CloseHandle(service->handle);\r
         CloseServiceHandle(services);\r
-        print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, _T("SERVICE_DELAYED_AUTO_START_INFO"), _T("pre_edit_service()"));\r
+        print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("SERVICE_DELAYED_AUTO_START_INFO"), _T("pre_edit_service()"));\r
         return 5;\r
       }\r
 \r
@@ -254,7 +254,7 @@ int pre_edit_service(int argc, TCHAR **argv) {
     if (! description) {\r
       CloseHandle(service->handle);\r
       CloseServiceHandle(services);\r
-      print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, _T("SERVICE_CONFIG_DESCRIPTION"), _T("pre_edit_service()"));\r
+      print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("SERVICE_CONFIG_DESCRIPTION"), _T("pre_edit_service()"));\r
       return 6;\r
     }\r
 \r