From 5b8d29d3589119c8b4b58877809093251018aae3 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Tue, 16 Mar 2021 12:54:38 +0000 Subject: [PATCH] package: don't exit prematurely (re: 3e140727, 936802f9, d18469d6) Sometimes the shell returned to the prompt before bin/package was finished writing all of its output. The problem was that 'tee', which is used to write the output to both the terminal and the log in arch/*lib/package/gen/make.out, hadn't caught up yet. bin/package, src/cmd/INIT/package.sh: - Run the build itself in the background and 'tee' in the foreground. This way, the script will not terminate until 'tee' is finished. The build's exit status is obtained with 'wait'. --- bin/package | 11 ++++++----- src/cmd/INIT/package.sh | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/bin/package b/bin/package index 9b0ded895..55135b6b9 100755 --- a/bin/package +++ b/bin/package @@ -4008,8 +4008,8 @@ capture() # file command ... 0) if executable ! $TEE then TEE=tee fi - # Connect 'tee' to a FIFO instead of a pipe, so that the build is invoked from - # the main shell environment and its exit status can be used for $error_status + # 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 rm -f $o.fifo mkfifo -m 600 $o.fifo || exit ( @@ -4017,14 +4017,15 @@ capture() # file command ... # unlink early exec rm $o.fifo ) & - $TEE -a $o < $o.fifo & - { + ( case $s in ?*) echo "$s" ;; esac showenv $action "$@" - } < /dev/null > $o.fifo 2>&1 + ) < /dev/null > $o.fifo 2>&1 & + $TEE -a $o < $o.fifo + wait $! # obtain exit status from build ;; *) { case $s in diff --git a/src/cmd/INIT/package.sh b/src/cmd/INIT/package.sh index 9b0ded895..55135b6b9 100644 --- a/src/cmd/INIT/package.sh +++ b/src/cmd/INIT/package.sh @@ -4008,8 +4008,8 @@ capture() # file command ... 0) if executable ! $TEE then TEE=tee fi - # Connect 'tee' to a FIFO instead of a pipe, so that the build is invoked from - # the main shell environment and its exit status can be used for $error_status + # 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 rm -f $o.fifo mkfifo -m 600 $o.fifo || exit ( @@ -4017,14 +4017,15 @@ capture() # file command ... # unlink early exec rm $o.fifo ) & - $TEE -a $o < $o.fifo & - { + ( case $s in ?*) echo "$s" ;; esac showenv $action "$@" - } < /dev/null > $o.fifo 2>&1 + ) < /dev/null > $o.fifo 2>&1 & + $TEE -a $o < $o.fifo + wait $! # obtain exit status from build ;; *) { case $s in