From 1f908fee0ab409932bcfe6aa8736d522aa2c4f8b Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Tue, 23 May 2017 20:42:16 +0200 Subject: Fix race condition that caused mutex to get unlocked when the process wasn't ready yet --- scsh-process.scm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scsh-process.scm b/scsh-process.scm index 2810baf..0676681 100644 --- a/scsh-process.scm +++ b/scsh-process.scm @@ -121,11 +121,13 @@ (scsh-process-ok? p) (scsh-process-pid p)) (if (and p (not nohang)) - (let ((m (make-mutex))) + (let lp ((m (make-mutex))) (mutex-unlock! m (scsh-process-child-condition p)) - (values (scsh-process-exit-status p) - (scsh-process-ok? p) - (scsh-process-pid p))) + (if (not (scsh-process-exit-status p)) + (lp m) ; might have been forcibly unblocked + (values (scsh-process-exit-status p) + (scsh-process-ok? p) + (scsh-process-pid p)))) (handle-exceptions exn (if (and p (scsh-process-exit-status p)) ; Signal might've occurred (values (scsh-process-exit-status p) -- cgit v1.2.3