From 8835843825b95ec9597ea958055e55499e1aa1c9 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Fri, 22 Jul 2016 14:20:07 +0100 Subject: [PATCH] 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. --- registry.cpp | 2 +- settings.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/registry.cpp b/registry.cpp index 6974270..7c93a3d 100644 --- a/registry.cpp +++ b/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; } diff --git a/settings.cpp b/settings.cpp index 7d08e13..c85bab4 100644 --- a/settings.cpp +++ b/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; } -- 2.7.4