From 5506c98933ac8f071866d551d6edc22110ce3a85 Mon Sep 17 00:00:00 2001 From: Kees Monshouwer Date: Fri, 10 Jan 2014 21:14:20 +0100 Subject: [PATCH] add trap handler to start-test-stop --- regression-tests/start-test-stop | 85 ++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/regression-tests/start-test-stop b/regression-tests/start-test-stop index a98da1e04..9cd8d1fdf 100755 --- a/regression-tests/start-test-stop +++ b/regression-tests/start-test-stop @@ -13,6 +13,8 @@ MAKE=${MAKE:-make} export ALGORITHM export KEY +trap "kill_process 2" EXIT INT TERM + nsdfix () { sed -e 's/"A very .*"/"shorter"/' < test.com > test.com.nsd @@ -89,7 +91,7 @@ __EOF__ ;; *) echo 'tonsd called with wrong param' - exit 1 + exit esac echo "" >> nsd.conf @@ -173,8 +175,8 @@ __EOF__ cp ${zone}.bind ${zone}.signed ;; *) - echo 'tonsd called with wrong param' - exit 1 + echo 'tobind called with wrong param' + exit esac echo "" >> bind.conf @@ -205,7 +207,7 @@ bindwait () if [ ! -x ../pdns/pdns_control ] then echo "No pdns_control found" - exit 1 + exit fi loopcount=0 @@ -265,19 +267,54 @@ check_process () let loopcount=loopcount+1 done echo "PowerDNS did not start" - exit 1 + exit +} + +kill_process () +{ + set +e + trap - EXIT INT TERM + + pids=$(cat pdns*.pid) + + if [ -n "$pids" ] + then + kill $pids + # make sure they die. + loopcount=0 + done=0 + while [ $loopcount -lt 10 ] && [ $done -eq 0 ] + do + done=1 + for pid in $pids + do + kill -0 $pid > /dev/null 2>&1 + if [ $? -eq 0 ]; + then + done=0 + fi + done + let loopcount=loopcount+1 + sleep 1 + done + + kill -9 $pids + fi + + rm pdns*.pid + exit $1 } if [ ! -x $PDNS ] then echo "$PDNS is not executable binary" - exit 1 + exit fi if [ ! -x $PDNS2 ] then echo "$PDNS2 is not executable binary" - exit 1 + exit fi port=$1 @@ -328,10 +365,10 @@ goracle-nodnssec goracle goracle-nsec3 goracle-nsec3-optout * Specifictest can be used to run only one single test. __EOF__ - exit 1 + exit fi -${MAKE} -C ../pdns sdig nsec3dig || exit 1 +${MAKE} -C ../pdns sdig nsec3dig || exit # Copy original zones because the test might modify them (well only the dyndns stuff, but let's make this work for others as well) for zone in $(grep zone named.conf | cut -f2 -d\") do @@ -932,7 +969,7 @@ __EOF__ ;; *) echo "Invalid usage" - exit 1 + exit ;; esac @@ -1003,7 +1040,7 @@ EOF : > passed_tests echo 'unknown-context-'"$context" > failed_tests ./toxml $context - exit 1 + exit esac if [ "$skiplua" == "1" ]; then @@ -1387,28 +1424,4 @@ then read l fi -pids=$(cat pdns*.pid) - -kill $pids -# make sure they die. -set +e -loopcount=0 -done=0 -while [ $loopcount -lt 10 ] && [ $done -eq 0 ] -do - done=1 - for pid in $pids - do - kill -0 $pid > /dev/null 2>&1 - if [ $? -eq 0 ]; then - done=0 - fi - done - let loopcount=loopcount+1 - sleep 1 -done - -kill -9 $pids - -rm pdns*.pid || true -exit $RETVAL +trap "kill_process $RETVAL" EXIT -- 2.40.0