summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Bex <peter@more-magic.net>2017-05-23 20:42:16 +0200
committerPeter Bex <peter@more-magic.net>2017-05-23 20:45:55 +0200
commit1f908fee0ab409932bcfe6aa8736d522aa2c4f8b (patch)
tree3128842ce7c615266c26eb369b1c083916f4c02d
parent217f7dc60a4a0ad0542e71f01378a5d110c9844e (diff)
downloadscsh-process-1f908fee0ab409932bcfe6aa8736d522aa2c4f8b.tar.gz
Fix race condition that caused mutex to get unlocked when the process wasn't ready yet
-rw-r--r--scsh-process.scm10
1 files 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)