]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make runtime/tests.sh shellcheck and set -e clean
authorOndřej Surý <ondrej@sury.org>
Sat, 16 Nov 2019 05:36:23 +0000 (13:36 +0800)
committerMichał Kępień <michal@isc.org>
Wed, 8 Jan 2020 12:07:40 +0000 (13:07 +0100)
This mostly comprises of:

* changing the directories in subshell and not ignoring `cd` return code
* handling every error gracefully instead of ignoring the return code

(cherry picked from commit 57b6aeabd5e3d379f06dfc61d2fefb54240b3f4c)

bin/tests/system/runtime/tests.sh

index 81eb6d1e5da0f523d3b49b6b3ffb22fcd3397bcf..fe6adaa04faf8511860c462c2c1fe09b8a46ac5a 100644 (file)
@@ -9,8 +9,11 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
+# shellcheck source=conf.sh
 SYSTEMTESTTOP=..
-. $SYSTEMTESTTOP/conf.sh
+. "$SYSTEMTESTTOP/conf.sh"
+
+set -e
 
 RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s"
 
@@ -44,20 +47,20 @@ kill_named() {
 status=0
 n=0
 
-n=`expr $n + 1`
+n=$((n+1))
 echo_i "verifying that named started normally ($n)"
 ret=0
 [ -s ns2/named.pid ] || ret=1
 grep "unable to listen on any configured interface" ns2/named.run > /dev/null && ret=1
 grep "another named process" ns2/named.run > /dev/null && ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
-status=`expr $status + $ret`
+status=$((status+ret))
 
 if [ ! "$CYGWIN" ]; then
-    n=`expr $n + 1`
+    n=$((n+1))
     echo_i "verifying that named checks for conflicting listeners ($n)"
     ret=0
-    (cd ns2; $NAMED -c named-alt1.conf -D ns2-extra-1 -X other.lock -m record,size,mctx -d 99 -g -U 4 >> named2.run 2>&1 & )
+    (cd ns2 && $NAMED -c named-alt1.conf -D ns2-extra-1 -X other.lock -m record,size,mctx -d 99 -g -U 4 >> named2.run 2>&1 & )
     for i in 1 2 3 4 5 6 7 8 9
     do
         grep "unable to listen on any configured interface" ns2/named2.run > /dev/null && break
@@ -71,64 +74,64 @@ if [ ! "$CYGWIN" ]; then
     done
     kill_named named.pid && ret=1
     if [ $ret != 0 ]; then echo_i "failed"; fi
-    status=`expr $status + $ret`
+    status=$((status+ret))
 fi
 
-n=`expr $n + 1`
+n=$((n+1))
 echo_i "verifying that named checks for conflicting named processes ($n)"
 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 & )
+(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
 if [ $ret != 0 ]; then echo_i "failed"; fi
-status=`expr $status + $ret`
+status=$((status+ret))
 
-n=`expr $n + 1`
+n=$((n+1))
 echo_i "verifying that 'lock-file none' disables process check ($n)"
 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 & )
+(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
 kill_named ns2/named-alt3.pid || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
-status=`expr $status + $ret`
+status=$((status+ret))
 
 if $SHELL ../testcrypto.sh -q
 then
-    n=`expr $n + 1`
+    n=$((n+1))
     echo_i "checking that named refuses to reconfigure if managed-keys-directory is set and not writable ($n)"
     ret=0
     copy_setports ns2/named-alt4.conf.in ns2/named.conf
-    $RNDCCMD 10.53.0.2 reconfig > rndc.out.$n 2>&1
+    $RNDCCMD 10.53.0.2 reconfig > rndc.out.$n 2>&1 && ret=1
     grep "failed: permission denied" rndc.out.$n > /dev/null 2>&1 || ret=1
     sleep 1
     grep "managed-keys-directory '.*' is not writable" ns2/named.run > /dev/null 2>&1 || ret=1
     if [ $ret != 0 ]; then echo_i "failed"; fi
-    status=`expr $status + $ret`
+    status=$((status+ret))
 
-    n=`expr $n + 1`
+    n=$((n+1))
     echo_i "checking that named refuses to reconfigure if managed-keys-directory is unset and working directory is not writable ($n)"
     ret=0
     copy_setports ns2/named-alt5.conf.in ns2/named.conf
-    $RNDCCMD 10.53.0.2 reconfig > rndc.out.$n 2>&1
+    $RNDCCMD 10.53.0.2 reconfig > rndc.out.$n 2>&1 && ret=1
     grep "failed: permission denied" rndc.out.$n > /dev/null 2>&1 || ret=1
     sleep 1
     grep "working directory '.*' is not writable" ns2/named.run > /dev/null 2>&1 || ret=1
     if [ $ret != 0 ]; then echo_i "failed"; fi
-    status=`expr $status + $ret`
+    status=$((status+ret))
 
-    n=`expr $n + 1`
+    n=$((n+1))
     echo_i "checking that named reconfigures if working directory is not writable but managed-keys-directory is ($n)"
     ret=0
     copy_setports ns2/named-alt6.conf.in ns2/named.conf
-    $RNDCCMD 10.53.0.2 reconfig > rndc.out.$n 2>&1
+    $RNDCCMD 10.53.0.2 reconfig > rndc.out.$n 2>&1 || ret=1
     grep "failed: permission denied" rndc.out.$n > /dev/null 2>&1 && ret=1
     kill_named ns2/named.pid || ret=1
     if [ $ret != 0 ]; then echo_i "failed"; fi
-    status=`expr $status + $ret`
+    status=$((status+ret))
 fi
 
-n=`expr $n + 1`
+n=$((n+1))
 echo_i "checking that named refuses to start if managed-keys-directory is set and not writable ($n)"
 ret=0
 (cd ns2 && $NAMED -c named-alt4.conf -D runtime-ns2-extra-4 -d 99 -g > named4.run 2>&1 &)
@@ -137,9 +140,9 @@ grep "managed-keys-directory '.*' is not writable" ns2/named4.run > /dev/null 2>
 grep "exiting (due to fatal error)" ns2/named4.run > /dev/null || ret=1
 kill_named ns2/named.pid && ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
-status=`expr $status + $ret`
+status=$((status+ret))
 
-n=`expr $n + 1`
+n=$((n+1))
 echo_i "checking that named refuses to start if managed-keys-directory is unset and working directory is not writable ($n)"
 ret=0
 (cd ns2 && $NAMED -c named-alt5.conf -D runtime-ns2-extra-5 -d 99 -g > named5.run 2>&1 &)
@@ -148,18 +151,16 @@ grep "working directory '.*' is not writable" ns2/named5.run > /dev/null 2>&1 ||
 grep "exiting (due to fatal error)" ns2/named5.run > /dev/null || ret=1
 kill_named ns2/named.pid && ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
-status=`expr $status + $ret`
+status=$((status+ret))
 
-n=`expr $n + 1`
+n=$((n+1))
 echo_i "checking that named starts if managed-keys-directory is writable and working directory is not writable ($n)"
 ret=0
-cd ns2/nope
-$NAMED -c ../named-alt6.conf -D runtime-ns2-extra-6 -d 99 -g > ../named6.run 2>&1 &
+(cd ns2/nope && $NAMED -c ../named-alt6.conf -D runtime-ns2-extra-6 -d 99 -g > ../named6.run 2>&1 &)
 sleep 2
-kill_named ../named.pid || ret=1
-cd ..
+kill_named ns2/named.pid || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
-status=`expr $status + $ret`
+status=$((status+ret))
 
 n=`expr $n + 1`
 echo_i "verifying that named switches UID ($n)"