From 82c692233074c70aaf370c245cfd52d4e333d6c0 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Wed, 17 Mar 2021 10:09:57 +0000 Subject: [PATCH] package: fix SIGINT and SIGHUP handling The package script was not well behaved with these. When you pressed Ctrl+C, on some shells (including ksh) both the SIGINT (2) and EXIT (0) traps are activated, showing a double 'make done' message. The exit status also wasn't > 128 to indicate a signal. bin/package, src/cmd/INIT/package.sh: - Be UNIXly well-behaved. Signals should be passed on after handling, so when one is caught, make the trap handlers print their message and then unset both itself and EXIT/0 before resending the signal to self. --- bin/package | 7 +++++-- src/cmd/INIT/package.sh | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/package b/bin/package index 55135b6b9..ebb2e6aa5 100755 --- a/bin/package +++ b/bin/package @@ -3999,9 +3999,12 @@ capture() # file command ... note $action output captured in $o s="$command: $action start at `date` in $INSTALLROOT" case $quiet in - 0) trap "echo \"$command: $action done at \`date\`\" in $INSTALLROOT 2>&1 | \$TEE -a $o" 0 1 2 ;; - *) trap "echo \"$command: $action done at \`date\`\" in $INSTALLROOT >> $o" 0 1 2 ;; + 0) cmd="echo \"$command: $action done at \`date\`\" in $INSTALLROOT 2>&1 | \$TEE -a $o" ;; + *) cmd="echo \"$command: $action done at \`date\`\" in $INSTALLROOT >> $o" ;; esac + trap "$cmd" 0 + trap "$cmd; trap 1 0; kill -1 $$" 1 + trap "$cmd; trap 2 0; kill -2 $$" 2 ;; esac case $quiet in diff --git a/src/cmd/INIT/package.sh b/src/cmd/INIT/package.sh index 55135b6b9..ebb2e6aa5 100644 --- a/src/cmd/INIT/package.sh +++ b/src/cmd/INIT/package.sh @@ -3999,9 +3999,12 @@ capture() # file command ... note $action output captured in $o s="$command: $action start at `date` in $INSTALLROOT" case $quiet in - 0) trap "echo \"$command: $action done at \`date\`\" in $INSTALLROOT 2>&1 | \$TEE -a $o" 0 1 2 ;; - *) trap "echo \"$command: $action done at \`date\`\" in $INSTALLROOT >> $o" 0 1 2 ;; + 0) cmd="echo \"$command: $action done at \`date\`\" in $INSTALLROOT 2>&1 | \$TEE -a $o" ;; + *) cmd="echo \"$command: $action done at \`date\`\" in $INSTALLROOT >> $o" ;; esac + trap "$cmd" 0 + trap "$cmd; trap 1 0; kill -1 $$" 1 + trap "$cmd; trap 2 0; kill -2 $$" 2 ;; esac case $quiet in