浏览代码

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 14 年之前
父节点
当前提交
1766fb0329
共有 3 个文件被更改,包括 10 次插入1 次删除
  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
 Changes since 2.8
 -----------------
 -----------------
   * Fixed failure to run on Windows versions prior to Vista.
   * 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
 application could be left running on service shutdown, and that a missing
 registry value for AppDirectory confused NSSM.
 registry value for AppDirectory confused NSSM.
 Thanks to Peter Wagemans and Laszlo Keresztfalvi for suggesting throttling restarts.
 Thanks to Peter Wagemans and Laszlo Keresztfalvi for suggesting throttling restarts.
+Thanks to Eugene Lifshitz for finding an edge case in CreateProcess().
 
 
 Licence
 Licence
 -------
 -------

+ 1 - 1
service.cpp

@@ -308,7 +308,7 @@ int start_service() {
 
 
   /* Launch executable with arguments */
   /* Launch executable with arguments */
   char cmd[CMD_LENGTH];
   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);
     log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "command line", "start_service", 0);
     return stop_service(2, true, true);
     return stop_service(2, true, true);
   }
   }