Explorar o código

More CreateProcess() fun.

Correctly handle the case where the application executable is under
a path which contains space and an executable sharing the initial
part of that path (up to a space) exists.

A (contrived) example is when Application is

  C:\stuff\app lications\foo.exe

and C:\stuff\app.exe also exists.

Thanks Eugene Lifshitz.
Iain Patterson %!s(int64=12) %!d(string=hai) anos
pai
achega
1766fb0329
Modificáronse 3 ficheiros con 10 adicións e 1 borrados
  1. 8 0
      ChangeLog.txt
  2. 1 0
      README.txt
  3. 1 1
      service.cpp

+ 8 - 0
ChangeLog.txt

@@ -1,3 +1,11 @@
+Changes since 2.9
+-----------------
+  * Fixed edge case with CreateProcess().
+
+    Correctly handle the case where the application executable is under
+    a path which contains space and an executable sharing the initial
+    part of that path (up to a space) exists.
+
 Changes since 2.8
 -----------------
   * Fixed failure to run on Windows versions prior to Vista.

+ 1 - 0
README.txt

@@ -178,6 +178,7 @@ Thanks to Arve Knudsen for spotting that child processes of the monitored
 application could be left running on service shutdown, and that a missing
 registry value for AppDirectory confused NSSM.
 Thanks to Peter Wagemans and Laszlo Keresztfalvi for suggesting throttling restarts.
+Thanks to Eugene Lifshitz for finding an edge case in CreateProcess().
 
 Licence
 -------

+ 1 - 1
service.cpp

@@ -308,7 +308,7 @@ int start_service() {
 
   /* Launch executable with arguments */
   char cmd[CMD_LENGTH];
-  if (_snprintf(cmd, sizeof(cmd), "%s %s", exe, flags) < 0) {
+  if (_snprintf(cmd, sizeof(cmd), "\"%s\" %s", exe, flags) < 0) {
     log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "command line", "start_service", 0);
     return stop_service(2, true, true);
   }