diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-10-21 01:12:48 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-10-23 12:47:28 -0700 |
commit | f3bb959c9baba18a3575db969eaa4eecf5a9a21a (patch) | |
tree | 17f184048de1f14aca10c39064a9c17847cb8b21 /src | |
parent | 399e65035866f7c48ad0829a82833614f9e5b3c3 (diff) | |
download | consfigurator-f3bb959c9baba18a3575db969eaa4eecf5a9a21a.tar.gz |
HANDLE-FORK-REQUEST: immediately begin reading from out & err pipes
Previously we waited for waitpid(2) to return before reading from the pipes.
If either pipe filled up before the child process exited, we would deadlock.
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src')
-rw-r--r-- | src/image.lisp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/image.lisp b/src/image.lisp index aa1a4b2..bde16a1 100644 --- a/src/image.lisp +++ b/src/image.lisp @@ -264,20 +264,30 @@ already running from FILENAME." (eval-input) (with-fork-control (eval-input))))))) (unwind-protect - (with-open-file (out out :element-type 'character) - (with-open-file (err err :element-type 'character) - (let ((status (nth-value 1 (nix:waitpid child)))) - (unless (nix:WIFEXITED status) - (failed-change - "~&Grandchild process did not exit normally, status #x~(~4,'0X~)." - status)) - (with-open-file (output output :direction :output - :if-exists :append - :element-type 'character) - (write-to-mkfifo (list (slurp-stream-string out) - (slurp-stream-string err) - (nix:WEXITSTATUS status)) - output))))) + (let* (outbuf + (out-reader + (bt:make-thread + (lambda () + (setq outbuf + (read-file-string out :element-type 'character))))) + errbuf + (err-reader + (bt:make-thread + (lambda () + (setq errbuf + (read-file-string err :element-type 'character))))) + (status (nth-value 1 (nix:waitpid child)))) + (unless (nix:WIFEXITED status) + (failed-change + "~&Grandchild process did not exit normally, status #x~(~4,'0X~)." + status)) + (bt:join-thread out-reader) + (bt:join-thread err-reader) + (with-open-file (output output :direction :output + :if-exists :append + :element-type 'character) + (write-to-mkfifo + (list outbuf errbuf (nix:WEXITSTATUS status)) output))) (delete-file out) (delete-file err)))) (defclass asdf-requirements () |