Browse code

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 <adalbas@linux.vnet.ibm.com>

Fixes bug 1302112

Change-Id: I2d5b27971889b672361e9173bf6faf38fb1a1ec6

Roger Luethi authored on 2014/04/26 21:21:33
Showing 1 changed files
... ...
@@ -494,14 +494,18 @@ function spinner {
494 494
     done
495 495
 }
496 496
 
497
+function kill_spinner {
498
+    if [ ! -z "$LAST_SPINNER_PID" ]; then
499
+        kill >/dev/null 2>&1 $LAST_SPINNER_PID
500
+        printf "\b\b\bdone\n" >&3
501
+    fi
502
+}
503
+
497 504
 # Echo text to the log file, summary log file and stdout
498 505
 # echo_summary "something to say"
499 506
 function echo_summary {
500 507
     if [[ -t 3 && "$VERBOSE" != "True" ]]; then
501
-        kill >/dev/null 2>&1 $LAST_SPINNER_PID
502
-        if [ ! -z "$LAST_SPINNER_PID" ]; then
503
-            printf "\b\b\bdone\n" >&3
504
-        fi
508
+        kill_spinner
505 509
         echo -n -e $@ >&6
506 510
         spinner &
507 511
         LAST_SPINNER_PID=$!
... ...
@@ -612,6 +616,10 @@ function exit_trap {
612 612
         echo "exit_trap: cleaning up child processes"
613 613
         kill 2>&1 $jobs
614 614
     fi
615
+
616
+    # Kill the last spinner process
617
+    kill_spinner
618
+
615 619
     exit $r
616 620
 }
617 621