~ chicken-core (master) 801328605663461a43e9f5b1d6e2269c127f42cc
commit 801328605663461a43e9f5b1d6e2269c127f42cc
Author: felix <felix@call-with-current-continuation.org>
AuthorDate: Tue Jul 7 22:20:54 2026 +0200
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Tue Jul 7 22:20:54 2026 +0200
catch any exceptions when executing process in forked thunk to avoid process hanging in limbo
When starting a process using the "process[*]" primitive, the particular
combination of process-fork (with a thunk) and an executable name with
an argument list, where execvp(2) fails could result in the forked process
being in some "limbo" state, that is, not terminated and still alive.
A waitpid(2) on the forked process will wait indefinitely, as the process
never dies. The reason is not clear to me, but I assume this is related
to the context set up by certain eldritch arcana we perform to minimize
life data. The problem can be reproduced by invoking
(process "/does/not/exist" '())
The problem also exist in C5.
This problem was reported by Stanislav Kljuhhin.
diff --git a/posixunix.scm b/posixunix.scm
index a9f0ebd6..3b6ee2b4 100644
--- a/posixunix.scm
+++ b/posixunix.scm
@@ -1114,7 +1114,8 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime)
((fx= 0 pid) ; child process
(set! children '())
(when killothers
- (call-with-current-continuation (lambda (continue) (##sys#kill-other-threads (lambda () (continue #f))))))
+ (call-with-current-continuation
+ (lambda (continue) (##sys#kill-other-threads (lambda () (continue #f))))))
(if thunk
(##sys#call-with-cthulhu
(lambda ()
@@ -1251,7 +1252,11 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime)
(connect-child loc opipe stdinf chicken.file.posix#fileno/stdin)
(connect-child loc (swapped-ends ipipe) stdoutf chicken.file.posix#fileno/stdout)
(connect-child loc (swapped-ends epipe) stderrf chicken.file.posix#fileno/stderr)
- (chicken.process#process-execute cmd args env)))) ) ) ))
+ (handle-exceptions ex
+ (begin
+ (print-error-message ex ##sys#standard-error)
+ (##core#inline "C_exit_runtime" 126))
+ (chicken.process#process-execute cmd args env)))) ) ) )))
[input-port
(lambda (loc cmd pipe stdf stdfd on-close enc)
(and-let* ([fd (connect-parent loc pipe stdf stdfd)])
Trap