]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
runtime test: use helper function that kills named and waits for the finish
authorOndřej Surý <ondrej@sury.org>
Sat, 16 Nov 2019 08:33:47 +0000 (16:33 +0800)
committerMichał Kępień <michal@isc.org>
Wed, 8 Jan 2020 08:22:59 +0000 (09:22 +0100)
(cherry picked from commit e9fa7b831b9c2d672d5fbdc4fd981ac18d284c50)

bin/tests/system/runtime/tests.sh

index 0dd9a29cfd3b4e43b526e8bec2413122be501eea..22b04321066ba9fb6a6a4db5627a3fc978e3dd35 100644 (file)
@@ -17,6 +17,33 @@ RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s"
 status=0
 n=0
 
+kill_named() {
+       pidfile="${1}"
+       if [ ! -r "${pidfile}" ]; then
+               return 1
+       fi
+
+       pid=$(cat "${pidfile}" 2>/dev/null)
+       if test "${pid:+set}" = "set"; then
+               $KILL -15 "${pid}" >/dev/null 2>&1
+               retries=10
+               while [ "$retries" -gt 0 ]; do
+                       if ! $KILL -0 "${pid}" >/dev/null 2>&1; then
+                               break
+                       fi
+                       sleep 1
+                       retries=$((retries-1))
+               done
+               # Timed-out
+               if [ "$retries" -eq 0 ]; then
+                       echo_i "failed to kill named ($pidfile)"
+                       return 1
+               fi
+       fi
+       rm -f "${pidfile}"
+       return 0
+}
+
 n=`expr $n + 1`
 echo_i "verifying that named started normally ($n)"
 ret=0
@@ -32,8 +59,7 @@ ret=0
 (cd ns2; $NAMED -c named-alt2.conf -D runtime-ns2-extra-2 -X named.lock -m record,size,mctx -d 99 -g -U 4 >> named3.run 2>&1 & )
 sleep 2
 grep "another named process" ns2/named3.run > /dev/null || ret=1
-pid=`cat ns2/named3.pid 2>/dev/null`
-test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
+kill_named ns2/named3.pid && ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`
 
@@ -43,8 +69,7 @@ ret=0
 (cd ns2; $NAMED -c named-alt3.conf -D runtime-ns2-extra-3 -m record,size,mctx -d 99 -g -U 4 >> named4.run 2>&1 & )
 sleep 2
 grep "another named process" ns2/named4.run > /dev/null && ret=1
-pid=`cat ns2/named4.pid 2>/dev/null`
-test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
+kill_named ns2/named4.pid || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`
 
@@ -88,12 +113,7 @@ cd ns2
 $NAMED -c named-alt4.conf -D runtime-ns2-extra-4 -d 99 -g > named4.run 2>&1 &
 sleep 2
 grep "exiting (due to fatal error)" named4.run > /dev/null || ret=1
-# pidfile could be in either place depending on whether the directory
-# successfully changed.
-pid=`cat named.pid 2>/dev/null`
-test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
-pid=`cat ../named.pid 2>/dev/null`
-test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
+kill_named named.pid && ret=1
 cd ..
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`
@@ -105,12 +125,7 @@ cd ns2
 $NAMED -c named-alt5.conf -D runtime-ns2-extra-5 -d 99 -g > named5.run 2>&1 &
 sleep 2
 grep "exiting (due to fatal error)" named5.run > /dev/null || ret=1
-# pidfile could be in either place depending on whether the directory
-# successfully changed.
-pid=`cat named.pid 2>/dev/null`
-test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
-pid=`cat ../named.pid 2>/dev/null`
-test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
+kill_named named.pid && ret=1
 cd ..
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`