Don't suicide on exit status 0.
[nssm.git] / registry.cpp
index 5dbadd2..ed01303 100644 (file)
@@ -146,7 +146,10 @@ int get_parameters(char *service_name, char *exe, int exelen, char *flags, int f
   return 0;\r
 }\r
 \r
-int get_exit_action(char *service_name, unsigned long *ret, unsigned char *action) {\r
+int get_exit_action(char *service_name, unsigned long *ret, unsigned char *action, bool *default_action) {\r
+  /* Are we returning the default action or a status-specific one? */\r
+  *default_action = ! ret;\r
+\r
   /* Get registry */\r
   char registry[KEY_LENGTH];\r
   if (_snprintf(registry, sizeof(registry), NSSM_REGISTRY "\\%s", service_name, NSSM_REG_EXIT) < 0) {\r
@@ -169,12 +172,12 @@ int get_exit_action(char *service_name, unsigned long *ret, unsigned char *actio
   if (! ret) code[0] = '\0';\r
   else if (_snprintf(code, sizeof(code), "%lu", *ret) < 0) {\r
     RegCloseKey(key);\r
-    return get_exit_action(service_name, 0, action);\r
+    return get_exit_action(service_name, 0, action, default_action);\r
   }\r
   if (RegQueryValueEx(key, code, 0, &type, action, &action_len) != ERROR_SUCCESS) {\r
     RegCloseKey(key);\r
     /* Try again with * as the key if an exit code was defined */\r
-    if (ret) return get_exit_action(service_name, 0, action);\r
+    if (ret) return get_exit_action(service_name, 0, action, default_action);\r
     return 0;\r
   }\r
 \r