From 7c30a59e25ed1ac4c6284915e6505fbdaeff8209 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Tue, 14 Dec 2021 22:33:59 +0100 Subject: [PATCH] package: allow 'tee' to catch up before returning (re: beb3c64a) In the referenced commit message I neglected to mention that, when doing bin/package make, we're now running 'tee' in the background again and the building job in the foreground, as opposed to the other way around. Foreground jobs are more reliably interruptable. But that reintroduced the problem fixed in 5b8d29d3. Now I don't know what I was thinking then -- the obvious fix is to add a 'wait' command, allowing 'tee' to catch up before returning to the prompt. --- bin/package | 9 ++++++++- src/cmd/INIT/package.sh | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bin/package b/bin/package index a5b421804..64110f394 100755 --- a/bin/package +++ b/bin/package @@ -2821,6 +2821,7 @@ showenv() capture() # file command ... { + tee_pid= case $make:$noexec in :) case $action in install|make|view) @@ -2883,7 +2884,7 @@ capture() # file command ... then TEE=tee fi # Connect 'tee' to a FIFO instead of a pipe, so that we can obtain - # the build's exit status with 'wait' and use it for $error_status + # the build's exit status and use it for $error_status rm -f $o.fifo mkfifo -m 600 $o.fifo || exit ( @@ -2892,6 +2893,7 @@ capture() # file command ... exec rm $o.fifo ) & $TEE -a $o < $o.fifo & + tee_pid=$! o=$o.fifo ;; esac @@ -2910,6 +2912,11 @@ capture() # file command ... if test "$exit_status" -gt "$error_status" then error_status=$exit_status fi + case $tee_pid in + ?*) # allow 'tee' to catch up before returning to prompt + wait "$tee_pid" + ;; + esac } make_recurse() # dir diff --git a/src/cmd/INIT/package.sh b/src/cmd/INIT/package.sh index a5b421804..64110f394 100644 --- a/src/cmd/INIT/package.sh +++ b/src/cmd/INIT/package.sh @@ -2821,6 +2821,7 @@ showenv() capture() # file command ... { + tee_pid= case $make:$noexec in :) case $action in install|make|view) @@ -2883,7 +2884,7 @@ capture() # file command ... then TEE=tee fi # Connect 'tee' to a FIFO instead of a pipe, so that we can obtain - # the build's exit status with 'wait' and use it for $error_status + # the build's exit status and use it for $error_status rm -f $o.fifo mkfifo -m 600 $o.fifo || exit ( @@ -2892,6 +2893,7 @@ capture() # file command ... exec rm $o.fifo ) & $TEE -a $o < $o.fifo & + tee_pid=$! o=$o.fifo ;; esac @@ -2910,6 +2912,11 @@ capture() # file command ... if test "$exit_status" -gt "$error_status" then error_status=$exit_status fi + case $tee_pid in + ?*) # allow 'tee' to catch up before returning to prompt + wait "$tee_pid" + ;; + esac } make_recurse() # dir