Be quieter loading imports.
authorIain Patterson <me@iain.cx>
Wed, 27 Jul 2016 10:47:16 +0000 (11:47 +0100)
committerIain Patterson <me@iain.cx>
Thu, 28 Jul 2016 15:44:35 +0000 (16:44 +0100)
There's no need to log an event if we couldn't load a missing DLL.

There's no need to go to the trouble of converting to a wide buffer if
we aren't then going to log an event.

imports.cpp

index ec3a2a8..230bf43 100644 (file)
@@ -15,7 +15,7 @@ HMODULE get_dll(const TCHAR *dll, unsigned long *error) {
   HMODULE ret = LoadLibrary(dll);\r
   if (! ret) {\r
     *error = GetLastError();\r
-    log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_LOADLIBRARY_FAILED, dll, error_string(*error), 0);\r
+    if (*error != ERROR_PROC_NOT_FOUND) log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_LOADLIBRARY_FAILED, dll, error_string(*error), 0);\r
   }\r
 \r
   return ret;\r
@@ -27,19 +27,21 @@ FARPROC get_import(HMODULE library, const char *function, unsigned long *error)
   FARPROC ret = GetProcAddress(library, function);\r
   if (! ret) {\r
     *error = GetLastError();\r
-    TCHAR *function_name;\r
+    if (*error != ERROR_PROC_NOT_FOUND) {\r
+      TCHAR *function_name;\r
 #ifdef UNICODE\r
-    size_t buflen;\r
-    mbstowcs_s(&buflen, NULL, 0, function, _TRUNCATE);\r
-    function_name = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, buflen * sizeof(TCHAR));\r
-    if (function_name) mbstowcs_s(&buflen, function_name, buflen * sizeof(TCHAR), function, _TRUNCATE);\r
+      size_t buflen;\r
+      mbstowcs_s(&buflen, NULL, 0, function, _TRUNCATE);\r
+      function_name = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, buflen * sizeof(TCHAR));\r
+      if (function_name) mbstowcs_s(&buflen, function_name, buflen * sizeof(TCHAR), function, _TRUNCATE);\r
 #else\r
-    function_name = (TCHAR *) function;\r
+      function_name = (TCHAR *) function;\r
 #endif\r
-    if (*error != ERROR_PROC_NOT_FOUND) log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_GETPROCADDRESS_FAILED, function_name, error_string(*error), 0);\r
+      log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_GETPROCADDRESS_FAILED, function_name, error_string(*error), 0);\r
 #ifdef UNICODE\r
-    if (function_name) HeapFree(GetProcessHeap(), 0, function_name);\r
+      if (function_name) HeapFree(GetProcessHeap(), 0, function_name);\r
 #endif\r
+    }\r
   }\r
 \r
   return ret;\r