summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Bex <peter@more-magic.net>2025-07-02 14:41:53 +0200
committerPeter Bex <peter@more-magic.net>2025-07-02 14:41:53 +0200
commit4a9adfd4591ca5de96b1294cd47d12c4efc22535 (patch)
tree18a60707a359014633220fa9b38d6881b7e87310
parent5d2659453493d7a1de7b80257763c72236c4008f (diff)
downloadscsh-process-4a9adfd4591ca5de96b1294cd47d12c4efc22535.tar.gz
Fix cleanup handling in wait for processes forked without scsh-process1.7.1
Similar to the C5 code, here we assumed that proc+condition would be true if the pid-or-process argument was a raw pid number, as taken from the table maintained by scsh-process. Unfortunately, this assumption only holds when the process would've been forked using "fork" from the scsh-process egg. If one forked with the "core" fork from CHICKEN itself, both p and pending-before would be false, which would lead to a "(car) bad argument type: #f" error. Reported by Matthew Welland.
-rw-r--r--scsh-process.scm3
-rw-r--r--tests/run.scm12
2 files changed, 14 insertions, 1 deletions
diff --git a/scsh-process.scm b/scsh-process.scm
index bcc6dbd..a438aa3 100644
--- a/scsh-process.scm
+++ b/scsh-process.scm
@@ -157,10 +157,11 @@
(process-id pid-or-process)))))
(proc (if (process? pid-or-process)
pid-or-process
- (car proc+condition))))
+ (and proc+condition (car proc+condition)))))
(when proc+condition
(mutex-unlock! m (cdr proc+condition)))
(if (or (number? pid-or-process)
+ (not proc)
(not (process-exit-status proc)))
(lp) ; could be forcibly unblocked
(begin
diff --git a/tests/run.scm b/tests/run.scm
index 85a6b11..ed4f653 100644
--- a/tests/run.scm
+++ b/tests/run.scm
@@ -4,6 +4,7 @@
(import (scheme base) (scheme write) (scheme read)
(chicken base) (chicken port) (chicken condition)
(chicken io) (chicken file) (chicken file posix)
+ (chicken process)
(chicken process signal)
srfi-18 test)
(import scsh-process)
@@ -44,6 +45,17 @@
(receive (status2 ok?2 pid2) (wait p)
(list (eq? status status2) (eq? ok? ok?2) (or (eq? pid pid2) (list pid pid2)))))))
+ (let ((p (process-fork (lambda () (sleep 1)))))
+ (test "after forking via native process-fork, waiting for \"any\" next process still returns the status"
+ (list 0 #t (process-id p))
+ (call-with-values (lambda () (wait #f)) list)))
+
+ ;; Regression test for bug reported by Matt Welland (this broke w/ poule)
+ (let ((pid (process-fork (lambda () (sleep 1)))))
+ (test "after forking via native process-fork, waiting for the specific process by pid still returns the status"
+ (list 0 #t (process-id pid))
+ (call-with-values (lambda () (wait (process-id pid))) list)))
+
(test-assert "signal wasn't unmasked" (signal-masked? signal/chld))
(test "sigchld is masked inside child process"