Browse code

Merge "Unbuffer log output"

Jenkins authored on 2014/02/27 09:39:32
Showing 2 changed files
... ...
@@ -222,6 +222,8 @@ function die() {
222 222
     fi
223 223
     backtrace 2
224 224
     err $line "$*"
225
+    # Give buffers a second to flush
226
+    sleep 1
225 227
     exit $exitcode
226 228
 }
227 229
 
... ...
@@ -526,7 +526,7 @@ if [[ -n "$LOGFILE" ]]; then
526 526
     exec 3>&1
527 527
     if [[ "$VERBOSE" == "True" ]]; then
528 528
         # Redirect stdout/stderr to tee to write the log file
529
-        exec 1> >( awk '
529
+        exec 1> >( awk -v logfile=${LOGFILE} '
530 530
                 /((set \+o$)|xtrace)/ { next }
531 531
                 {
532 532
                     cmd ="date +\"%Y-%m-%d %H:%M:%S.%3N | \""
... ...
@@ -534,8 +534,9 @@ if [[ -n "$LOGFILE" ]]; then
534 534
                     close("date +\"%Y-%m-%d %H:%M:%S.%3N | \"")
535 535
                     sub(/^/, now)
536 536
                     print
537
-                    fflush()
538
-                }' | tee "${LOGFILE}" ) 2>&1
537
+                    print > logfile
538
+                    fflush("")
539
+                }' ) 2>&1
539 540
         # Set up a second fd for output
540 541
         exec 6> >( tee "${SUMFILE}" )
541 542
     else
... ...
@@ -583,21 +584,24 @@ fi
583 583
 # -----------------------
584 584
 
585 585
 # Kill background processes on exit
586
-trap clean EXIT
587
-clean() {
586
+trap exit_trap EXIT
587
+function exit_trap {
588 588
     local r=$?
589
-    kill >/dev/null 2>&1 $(jobs -p)
589
+    echo "exit_trap called, cleaning up child processes"
590
+    kill 2>&1 $(jobs -p)
590 591
     exit $r
591 592
 }
592 593
 
593
-
594 594
 # Exit on any errors so that errors don't compound
595
-trap failed ERR
596
-failed() {
595
+trap err_trap ERR
596
+function err_trap {
597 597
     local r=$?
598
-    kill >/dev/null 2>&1 $(jobs -p)
599 598
     set +o xtrace
600
-    [ -n "$LOGFILE" ] && echo "${0##*/} failed: full log in $LOGFILE"
599
+    if [[ -n "$LOGFILE" ]]; then
600
+        echo "${0##*/} failed: full log in $LOGFILE"
601
+    else
602
+        echo "${0##*/} failed"
603
+    fi
601 604
     exit $r
602 605
 }
603 606