Browse Source

Read registry before each restart.

Read Application, AppDirectory and AppParameters before each restart so
a change to any one doesn't require restarting NSSM itself.
Iain Patterson 11 years ago
parent
commit
9ee3804b6f
1 changed files with 7 additions and 11 deletions
  1. 7 11
      service.cpp

+ 7 - 11
service.cpp

@@ -198,17 +198,6 @@ void WINAPI service_main(unsigned long argc, char **argv) {
     return;
   }
 
-  /* Get startup parameters */
-  int ret = get_parameters(argv[0], exe, sizeof(exe), flags, sizeof(flags), dir, sizeof(dir));
-  if (ret) {
-    log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_GET_PARAMETERS_FAILED, argv[0], 0);
-    service_status.dwCurrentState = SERVICE_STOPPED;
-    /* An accurate, if not particularly helpful, status */
-    service_status.dwWin32ExitCode = ERROR_SERVICE_NOT_ACTIVE;
-    SetServiceStatus(service_handle, &service_status);
-    return;
-  }
-
   service_status.dwCurrentState = SERVICE_START_PENDING;
   service_status.dwWaitHint = NSSM_RESET_THROTTLE_RESTART + NSSM_WAITHINT_MARGIN;
   SetServiceStatus(service_handle, &service_status);
@@ -304,6 +293,13 @@ int start_service() {
   PROCESS_INFORMATION pi;
   ZeroMemory(&pi, sizeof(pi));
 
+  /* Get startup parameters */
+  int ret = get_parameters(service_name, exe, sizeof(exe), flags, sizeof(flags), dir, sizeof(dir));
+  if (ret) {
+    log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_GET_PARAMETERS_FAILED, service_name, 0);
+    return stop_service(2, true, true);
+  }
+
   /* Launch executable with arguments */
   char cmd[CMD_LENGTH];
   if (_snprintf(cmd, sizeof(cmd), "%s %s", exe, flags) < 0) {