Browse Source

Ensure we have the right key for querying Environment.

The Environment value is under the service key not our subkey.
If we're querying it we should expect that the service definition exists
in the registry.
Iain Patterson 7 năm trước cách đây
mục cha
commit
8835843825
2 tập tin đã thay đổi với 5 bổ sung5 xóa
  1. 1 1
      registry.cpp
  2. 4 4
      settings.cpp

+ 1 - 1
registry.cpp

@@ -242,7 +242,7 @@ int get_environment(TCHAR *service_name, HKEY key, TCHAR *value, TCHAR **env, un
     *env = 0;
     /* The service probably doesn't have any environment configured */
     if (ret == ERROR_FILE_NOT_FOUND) return 0;
-    log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(GetLastError()), 0);
+    log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(ret), 0);
     return 1;
   }
 

+ 4 - 4
settings.cpp

@@ -727,20 +727,20 @@ int native_get_displayname(const TCHAR *service_name, void *param, const TCHAR *
 }
 
 int native_set_environment(const TCHAR *service_name, void *param, const TCHAR *name, void *default_value, value_t *value, const TCHAR *additional) {
-  HKEY key = open_service_registry(service_name, KEY_SET_VALUE, false);
+  HKEY key = open_service_registry(service_name, KEY_SET_VALUE, true);
   if (! key) return -1;
 
-  int ret = setting_set_environment(service_name, (void *) key, NSSM_NATIVE_ENVIRONMENT, default_value, value, additional);
+  int ret = setting_set_environment(service_name, (void *) key, name, default_value, value, additional);
   RegCloseKey(key);
   return ret;
 }
 
 int native_get_environment(const TCHAR *service_name, void *param, const TCHAR *name, void *default_value, value_t *value, const TCHAR *additional) {
-  HKEY key = open_service_registry(service_name, KEY_READ, false);
+  HKEY key = open_service_registry(service_name, KEY_READ, true);
   if (! key) return -1;
 
   ZeroMemory(value, sizeof(value_t));
-  int ret = setting_get_environment(service_name, (void *) key, NSSM_NATIVE_ENVIRONMENT, default_value, value, additional);
+  int ret = setting_get_environment(service_name, (void *) key, name, default_value, value, additional);
   RegCloseKey(key);
   return ret;
 }