From 03208a8de3c04908db3fe11bfe7e8ce3d7c75523 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Fri, 27 Mar 2015 14:55:11 +0000 Subject: [PATCH] Testing script: trap SIGINT in child threads. Now 'Ctrl+C' is handled as in single-threaded script: all threads stop working. --- re2c/run_tests.sh.in | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/re2c/run_tests.sh.in b/re2c/run_tests.sh.in index 545b93d2..06ffaffd 100644 --- a/re2c/run_tests.sh.in +++ b/re2c/run_tests.sh.in @@ -54,8 +54,7 @@ then fi re2c="${valgrind}${re2c}" -run_pack () -{ +run_pack() { local log="$1" shift 1 @@ -118,21 +117,31 @@ run_pack () echo $errcnt > $log } +cleanup() { + rm -f ${logs[@]} + kill ${wait_pids[@]} + wait ${wait_pids[@]} + printf "\nEh...\n" + exit 1 +} + logs=() +wait_pids=() +trap cleanup INT for ((i = 0; i < ${#packs[@]}; i++)) do logs[$i]=`date +%y%m%d%H%M%S`_$i run_pack ${logs[i]} ${packs[i]} & - wait_pids="$wait_pids %$((i + 1))" + wait_pids+=( $! ) done -wait $wait_pids +wait ${wait_pids[@]} errors=0 for ((i = 0; i < ${#logs[@]}; i++)) do error=`cat ${logs[i]}` errors=$((errors + error)) - rm ${logs[i]} + rm -f ${logs[i]} done -- 2.40.0