Ensure we have the right key for querying Environment.
authorIain Patterson <me@iain.cx>
Fri, 22 Jul 2016 13:20:07 +0000 (14:20 +0100)
committerIain Patterson <me@iain.cx>
Thu, 28 Jul 2016 15:44:18 +0000 (16:44 +0100)
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.

registry.cpp
settings.cpp

index 6974270..7c93a3d 100644 (file)
@@ -242,7 +242,7 @@ int get_environment(TCHAR *service_name, HKEY key, TCHAR *value, TCHAR **env, un
     *env = 0;\r
     /* The service probably doesn't have any environment configured */\r
     if (ret == ERROR_FILE_NOT_FOUND) return 0;\r
-    log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(GetLastError()), 0);\r
+    log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(ret), 0);\r
     return 1;\r
   }\r
 \r
index 7d08e13..c85bab4 100644 (file)
@@ -727,20 +727,20 @@ int native_get_displayname(const TCHAR *service_name, void *param, const TCHAR *
 }\r
 \r
 int native_set_environment(const TCHAR *service_name, void *param, const TCHAR *name, void *default_value, value_t *value, const TCHAR *additional) {\r
-  HKEY key = open_service_registry(service_name, KEY_SET_VALUE, false);\r
+  HKEY key = open_service_registry(service_name, KEY_SET_VALUE, true);\r
   if (! key) return -1;\r
 \r
-  int ret = setting_set_environment(service_name, (void *) key, NSSM_NATIVE_ENVIRONMENT, default_value, value, additional);\r
+  int ret = setting_set_environment(service_name, (void *) key, name, default_value, value, additional);\r
   RegCloseKey(key);\r
   return ret;\r
 }\r
 \r
 int native_get_environment(const TCHAR *service_name, void *param, const TCHAR *name, void *default_value, value_t *value, const TCHAR *additional) {\r
-  HKEY key = open_service_registry(service_name, KEY_READ, false);\r
+  HKEY key = open_service_registry(service_name, KEY_READ, true);\r
   if (! key) return -1;\r
 \r
   ZeroMemory(value, sizeof(value_t));\r
-  int ret = setting_get_environment(service_name, (void *) key, NSSM_NATIVE_ENVIRONMENT, default_value, value, additional);\r
+  int ret = setting_get_environment(service_name, (void *) key, name, default_value, value, additional);\r
   RegCloseKey(key);\r
   return ret;\r
 }\r