Pārlūkot izejas kodu

Clean up Parameters properly.

If create_parameters() failed to write Application, AppParameters or
AppDirectory it would try to clean up by deleting the Parameters key.
The method used to do so was flawed.  It would attempt to delete the key
defined by the NSSM_REGISTRY macro but that macro contains a printf
control string and is not suitable for standalone use.
Iain Patterson 9 gadi atpakaļ
vecāks
revīzija
e072e7ea67
1 mainītis faili ar 7 papildinājumiem un 3 dzēšanām
  1. 7 3
      registry.cpp

+ 7 - 3
registry.cpp

@@ -32,19 +32,23 @@ int create_parameters(nssm_service_t *service, bool editing) {
   HKEY key = open_registry(service->name, KEY_WRITE);
   if (! key) return 1;
 
+  /* Remember parameters in case we need to delete them. */
+  TCHAR registry[KEY_LENGTH];
+  int ret = service_registry_path(service->name, true, 0, registry, _countof(registry));
+
   /* Try to create the parameters */
   if (set_expand_string(key, NSSM_REG_EXE, service->exe)) {
-    RegDeleteKey(HKEY_LOCAL_MACHINE, NSSM_REGISTRY);
+    if (ret > 0) RegDeleteKey(HKEY_LOCAL_MACHINE, registry);
     RegCloseKey(key);
     return 2;
   }
   if (set_expand_string(key, NSSM_REG_FLAGS, service->flags)) {
-    RegDeleteKey(HKEY_LOCAL_MACHINE, NSSM_REGISTRY);
+    if (ret > 0) RegDeleteKey(HKEY_LOCAL_MACHINE, registry);
     RegCloseKey(key);
     return 3;
   }
   if (set_expand_string(key, NSSM_REG_DIR, service->dir)) {
-    RegDeleteKey(HKEY_LOCAL_MACHINE, NSSM_REGISTRY);
+    if (ret > 0) RegDeleteKey(HKEY_LOCAL_MACHINE, registry);
     RegCloseKey(key);
     return 4;
   }