fix RUN-PROGRAM :WAIT T on Windows
authorNikodemus Siivola <nikodemus@random-state.net>
Sun, 20 Nov 2011 11:54:07 +0000 (13:54 +0200)
committerNikodemus Siivola <nikodemus@random-state.net>
Sun, 20 Nov 2011 11:58:46 +0000 (13:58 +0200)
  Recent change to report the errno from exec() broke things on Windows.

  There when :WAIT is true it is the C code that waits, and the subsequently
  returns the exit code of the process -- meaning our attempt to use 0 to
  indicate exec() failure makes every successfull execution on Windows look
  like an exec failure.

  Oops. Use -2 instead. MORE MAGIC.

src/code/run-program.lisp
src/runtime/run-program.c

index b4394a1..b854e31 100644 (file)
@@ -773,7 +773,7 @@ Users Manual for details about the PROCESS structure."#-win32"
                                                   (if search 1 0)
                                                   environment-vec pty-name
                                                   (if wait 1 0))))
-                             (when (plusp child)
+                             (unless (minusp child)
                                (setf proc
                                      (apply
                                       #'make-process
@@ -791,9 +791,13 @@ Users Manual for details about the PROCESS structure."#-win32"
                                                   (list :%status :running))))
                                (push proc *active-processes*)))))
                        ;; Report the error outside the lock.
+                       #+win32
+                       (when (minusp child)
+                         (error "Couldn't execute ~S: ~A" progname (strerror)))
+                       #-win32
                        (case child
-                         (0
-                          (error "Couldn't execute ~A: ~A" progname (strerror)))
+                         (-2
+                          (error "Couldn't execute ~S: ~A" progname (strerror)))
                          (-1
                           (error "Couldn't fork child process: ~A" (strerror))))))))))
         (dolist (fd *close-in-parent*)
index 7377e7f..4e6f829 100644 (file)
@@ -140,7 +140,9 @@ int spawn(char *program, char *argv[], int sin, int sout, int serr,
             }
             if (child_errno) {
                 waitpid(pid, NULL, 0);
-                pid = 0;
+                /* Our convention to tell Lisp that it was the exec that
+                 * failed, not the fork. */
+                pid = -2;
                 errno = child_errno;
             }
         }