From f3bb959c9baba18a3575db969eaa4eecf5a9a21a Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 21 Oct 2021 01:12:48 -0700 Subject: 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 --- src/image.lisp | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'src/image.lisp') 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 () -- cgit v1.2.3