- (multiple-value-bind (pid what code core)
- (wait3 t t)
- (unless pid
- (return))
- (let ((proc (with-active-processes-lock ()
- (find pid *active-processes* :key #'process-pid))))
- (when proc
- (setf (process-%status proc) what)
- (setf (process-exit-code proc) code)
- (setf (process-core-dumped proc) core)
- (when (process-status-hook proc)
- (funcall (process-status-hook proc) proc))
- (when (position what #(:exited :signaled))
- (with-active-processes-lock ()
- (setf *active-processes*
- (delete proc *active-processes*)))))))))
+ (multiple-value-bind (pid what code core)
+ (wait3 t t)
+ (unless pid
+ (return))
+ (let ((proc (with-active-processes-lock ()
+ (find pid *active-processes* :key #'process-pid))))
+ (when proc
+ (setf (process-%status proc) what)
+ (setf (process-exit-code proc) code)
+ (setf (process-core-dumped proc) core)
+ (when (process-status-hook proc)
+ (funcall (process-status-hook proc) proc))
+ (when (position what #(:exited :signaled))
+ (with-active-processes-lock ()
+ (setf *active-processes*
+ (delete proc *active-processes*))))))))
+ #+win32
+ (let (exited)
+ (with-active-processes-lock ()
+ (setf *active-processes*
+ (delete-if (lambda (proc)
+ (multiple-value-bind (ok code)
+ (get-exit-code-process (process-pid proc))
+ (when (and (plusp ok) (/= code 259))
+ (setf (process-%status proc) :exited
+ (process-exit-code proc) code)
+ (when (process-status-hook proc)
+ (push proc exited))
+ t)))
+ *active-processes*)))
+ ;; Can't call the hooks before all the processes have been deal
+ ;; with, as calling a hook may cause re-entry to
+ ;; GET-PROCESS-STATUS-CHANGES. That may be OK when using wait3,
+ ;; but in the Windows implementation is would be deeply bad.
+ (dolist (proc exited)
+ (let ((hook (process-status-hook proc)))
+ (when hook
+ (funcall hook proc))))))