From de56ee15c7243e74a8ba7c3b3633eccb68630774 Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Sat, 26 Apr 2014 14:21:33 +0200 Subject: [PATCH] Kill spinner process when stack.sh exits The last spinner process active in non-verbose mode does not get killed when stack.sh exits -- the spinner keeps spinning indefinitely. Killing the spinner in err_exit cleans up no matter how the program got terminated. Because the code to kill the spinner is now called regardless of whether spinners are in use, it has to check LAST_SPINNER_PID or the kill command without an argument will trigger the ERR trap (or EXIT with an error status, depending on where program execution stops). This patch resurrects and fixes an abandoned changeset, hence: Co-Authored-By: Adalberto Medeiros Fixes bug 1302112 Change-Id: I2d5b27971889b672361e9173bf6faf38fb1a1ec6 --- stack.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/stack.sh b/stack.sh index dff6bd3cf1..f2c8a9f931 100755 --- a/stack.sh +++ b/stack.sh @@ -494,14 +494,18 @@ function spinner { done } +function kill_spinner { + if [ ! -z "$LAST_SPINNER_PID" ]; then + kill >/dev/null 2>&1 $LAST_SPINNER_PID + printf "\b\b\bdone\n" >&3 + fi +} + # Echo text to the log file, summary log file and stdout # echo_summary "something to say" function echo_summary { if [[ -t 3 && "$VERBOSE" != "True" ]]; then - kill >/dev/null 2>&1 $LAST_SPINNER_PID - if [ ! -z "$LAST_SPINNER_PID" ]; then - printf "\b\b\bdone\n" >&3 - fi + kill_spinner echo -n -e $@ >&6 spinner & LAST_SPINNER_PID=$! @@ -612,6 +616,10 @@ function exit_trap { echo "exit_trap: cleaning up child processes" kill 2>&1 $jobs fi + + # Kill the last spinner process + kill_spinner + exit $r }