]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Avoid shellcheck warnings in remaining test stubs
authorMartin Schwenke <martin@meltin.net>
Wed, 17 Aug 2022 22:59:28 +0000 (08:59 +1000)
committerAmitay Isaacs <amitay@samba.org>
Fri, 16 Sep 2022 03:36:32 +0000 (03:36 +0000)
A small amount of effort...

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/UNIT/eventscripts/stubs/ctdb
ctdb/tests/UNIT/eventscripts/stubs/ctdb_killtcp
ctdb/tests/UNIT/eventscripts/stubs/ctdb_lvs
ctdb/tests/UNIT/eventscripts/stubs/ctdb_natgw
ctdb/tests/UNIT/eventscripts/stubs/df
ctdb/tests/UNIT/eventscripts/stubs/ipvsadm
ctdb/tests/UNIT/eventscripts/stubs/rpcinfo
ctdb/tests/UNIT/eventscripts/stubs/smnotify
ctdb/tests/UNIT/eventscripts/stubs/ss
ctdb/tests/UNIT/eventscripts/stubs/tdbtool

index fc7bd4fdd841ee645326af2814dd84d9329935d8..a1d1e2f47595533f7d4af4b08848b6864f6a08b3 100755 (executable)
@@ -5,7 +5,7 @@ prog="ctdb"
 # Print a message and exit.
 die ()
 {
-    echo "$1" >&2 ; exit ${2:-1}
+    echo "$1" >&2 ; exit "${2:-1}"
 }
 
 not_implemented_exit_code=1
@@ -55,13 +55,15 @@ while [ $# -gt 0 ] ; do
 done
 
 [ -n "$args" ] || usage
+# Want word splitting
+# shellcheck disable=SC2086
 set -- $args
 
 setup_tickles ()
 {
     # Make sure tickles file exists.
     tickles_file="${CTDB_TEST_TMP_DIR}/fake-ctdb/tickles"
-    mkdir -p $(dirname "$tickles_file")
+    mkdir -p "$(dirname "$tickles_file")"
     touch "$tickles_file"
 }
 
@@ -73,9 +75,9 @@ ctdb_gettickles ()
     setup_tickles
 
     echo "|source ip|port|destination ip|port|"
-    while read _src _dst ; do
-       if [ -z "$_ip" -o "$_ip" = "${_dst%:*}" ] ; then
-           if [ -z "$_port" -o "$_port" = "${_dst##*:}" ] ; then
+    while read -r _src _dst ; do
+       if [ -z "$_ip" ] || [ "$_ip" = "${_dst%:*}" ] ; then
+           if [ -z "$_port" ] || [ "$_port" = "${_dst##*:}" ] ; then
                echo "|${_src%:*}|${_src##*:}|${_dst%:*}|${_dst##*:}|"
            fi
        fi
@@ -107,7 +109,7 @@ ctdb_deltickle ()
        _t=$(grep -F -v "${_src} $${_dst}" "$tickles_file")
     else
        _t=$(cat "$tickles_file")
-       while read _src _dst ; do
+       while read -r _src _dst ; do
            _t=$(echo "$_t" | grep -F -v "${_src} ${_dst}")
        done
     fi
@@ -119,9 +121,9 @@ parse_nodespec ()
     if [ "$nodespec" = "all" ] ; then
        nodes="$(seq 0 $((FAKE_CTDB_NUMNODES - 1)) )"
     elif [ -n "$nodespec" ] ; then
-       nodes="$(echo $nodespec | sed -e 's@,@ @g')"
+       nodes="$(echo "$nodespec" | sed -e 's@,@ @g')"
     else
-       node=$(ctdb_pnn)
+       nodes=$(ctdb_pnn)
     fi
 }
 
@@ -153,6 +155,8 @@ ip_reallocate ()
 {
     touch "$FAKE_CTDB_IP_LAYOUT"
 
+    # ShellCheck doesn't understand this flock pattern
+    # shellcheck disable=SC2094
     (
        flock 0
 
@@ -173,7 +177,7 @@ ip_reallocate ()
                for _j in "$FAKE_CTDB_STATE/node-state/"*"/$_i" ; do
                    _tf="${_j%/*}" # dirname
                    _f="${_tf##*/}" # basename
-                   _this=$(( $_this | $_f ))
+                   _this=$(( _this | _f ))
                done
            else
                _this="0"
@@ -209,7 +213,7 @@ ctdb_ip ()
     # process output line by line...
     _pa="${CTDB_BASE}/public_addresses"
     sed -e 's@/@ @' "$_pa" | sort | join - "$FAKE_CTDB_IP_LAYOUT" |
-    while read _ip _bit _ifaces _pnn ; do
+    while read -r _ip _ _ifaces _pnn ; do
        if $verbose ; then
            # If more than 1 interface, assume all addresses are on the 1st.
            _first_iface="${_ifaces%%,*}"
@@ -240,12 +244,14 @@ ctdb_moveip ()
 
     ip_reallocate  # should be harmless and ensures we have good state
 
+    # ShellCheck doesn't understand this flock pattern
+    # shellcheck disable=SC2094
     (
        flock 0
 
        _t="${FAKE_CTDB_IP_LAYOUT}.new"
 
-       while read _i _pnn ; do
+       while read -r _i _pnn ; do
            if [ "$_ip" = "$_i" ] ; then
                echo "$_i $_target"
            else
@@ -261,7 +267,7 @@ ctdb_moveip ()
 ctdb_enable ()
 {
     parse_nodespec
-    
+
     for _i in $nodes ; do
        rm -f "${FAKE_CTDB_NODES_DISABLED}/${_i}"
     done
@@ -298,7 +304,7 @@ ctdb_shutdown ()
 ctdb_nodestatus ()
 {
     echo '|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|'
-    _line=$(( $FAKE_CTDB_PNN + 1 ))
+    _line=$(( FAKE_CTDB_PNN + 1 ))
     _ip=$(sed -e "${_line}p" "${CTDB_NATGW_NODES:-${CTDB_LVS_NODES}}")
     echo "|${FAKE_CTDB_PNN}|${_ip}|0|0|0|0|0|0|0|Y|"
 }
@@ -371,10 +377,10 @@ ctdb_ptrans ()
 {
     _t_setup "$1"
 
-    while IFS="" read _line ; do
+    while IFS="" read -r _line ; do
        _k=$(echo "$_line" | sed -n -e 's@^"\([^"]*\)" "[^"]*"$@\1@p')
        _v=$(echo "$_line" | sed -e 's@^"[^"]*" "\([^"]*\)"$@\1@')
-       [ -n "$_k" ] || die "ctdb ptrans: bad line \"${line}\""
+       [ -n "$_k" ] || die "ctdb ptrans: bad line \"${_line}\""
        if [ -n "$_v" ] ; then
            _t_put "$_k" "$_v"
        else
@@ -394,8 +400,8 @@ ctdb_catdb ()
        [ -r "$_i" ] || continue
        _k="${_i##*/}" # basename
        _v=$(_t_get "$_k")
-       _kn=$(echo -n "$_k" | wc -c)
-       _vn=$(echo -n "$_v" | wc -c)
+       _kn=$(printf '%s' "$_k" | wc -c)
+       _vn=$(printf '%s' "$_v" | wc -c)
        cat <<EOF
 key(${_kn}) = "${_k}"
 dmaster: 0
@@ -403,7 +409,7 @@ rsn: 1
 data(${_vn}) = "${_v}"
 
 EOF
-       _count=$(($_count + 1))
+       _count=$((_count + 1))
     done
 
     echo "Dumped ${_count} records"
@@ -424,7 +430,7 @@ ctdb_ifaces()
 
        # Assume -Y.
        echo "|Name|LinkStatus|References|"
-       while read _ip _iface ; do
+       while read -r _ip _iface ; do
                case "$_ip" in
                \#*) : ;;
                *)
index cb5b6e573743db4e2bb98bbf0eb2eed620fe73e6..0f40058ee57b29b34166a5c87dda192fec9f8da3 100755 (executable)
@@ -2,8 +2,9 @@
 
 # Only supports reading from stdin
 
+# shellcheck disable=SC2034
 iface="$1"  # ignored
 
-while read src dst ; do
+while read -r src dst; do
        sed -i -e "/^${dst} ${src}\$/d" "$FAKE_NETSTAT_TCP_ESTABLISHED_FILE"
 done
index 85e005c0b365b7131d1d9c10d73211450388d917..3a90d00581f331f1aff2e68ff88e24a21e2ac4a9 100755 (executable)
@@ -5,7 +5,7 @@ prog="ctdb_lvs"
 # Print a message and exit.
 die ()
 {
-    echo "$1" >&2 ; exit ${2:-1}
+    echo "$1" >&2 ; exit "${2:-1}"
 }
 
 not_implemented_exit_code=1
@@ -37,9 +37,9 @@ ctdb_lvs_leader ()
 ctdb_lvs_list ()
 {
        _pnn=0
-       while read _ip _opts ; do
+       while read -r _ip _ ; do
                echo "${_pnn} ${_ip}"
-               _pnn=$(($_pnn + 1))
+               _pnn=$((_pnn + 1))
        done <"$CTDB_LVS_NODES"
 }
 
index e64a95695bb7448ee3367a9a77db9d4289759f79..83ba59c555d5004d71b028bd84c00296e5d395bb 100755 (executable)
@@ -18,12 +18,12 @@ ctdb_natgw_leader ()
     # Determine the leader node
     _leader="-1 0.0.0.0"
     _pnn=0
-    while read _ip ; do
+    while read -r _ip ; do
        if [ "$FAKE_CTDB_NATGW_LEADER" = "$_ip" ] ; then
            _leader="${_pnn} ${_ip}"
            break
        fi
-       _pnn=$(($_pnn + 1))
+       _pnn=$((_pnn + 1))
     done <"$CTDB_NATGW_NODES"
     echo "$_leader"
 }
index a2e7093293d0b5ad463c4d504d3162cc959955f3..8abad178ffcb654623d957b16c7ba08d21c6280c 100755 (executable)
@@ -19,7 +19,7 @@ fs="${1:-/}"
 # Anything starting with CTDB_DBDIR_BASE gets canonicalised to
 # CTDB_DBDIR_BASE.  This helps with the setting of defaults for the
 # filesystem checks.
-if [ "${fs#${CTDB_DBDIR_BASE}}" != "$fs" ] ; then
+if [ "${fs#"${CTDB_DBDIR_BASE}"}" != "$fs" ] ; then
     fs="$CTDB_DBDIR_BASE"
 fi
 
@@ -31,8 +31,8 @@ fi
 echo "Filesystem             1024-blocks      Used Available Capacity Mounted on"
 
 blocks="1000000"
-used=$(($blocks * $FAKE_FS_USE / 100))
-available=$(($blocks - $used))
+used=$((blocks * FAKE_FS_USE / 100))
+available=$((blocks - used))
 
 printf "%-36s %10d %10d %10d %10d%% %s\n" \
        "/dev/sda1" "$blocks" "$used" "$available" "$FAKE_FS_USE" "$fs"
index 0567f881e544902826e64c579354a3d9271ae574..226d7b4d9a824de82b67871ec6244ffce0ea0a3d 100755 (executable)
@@ -3,7 +3,7 @@
 die ()
 {
        echo "$1" >&2
-       exit ${2:-1}
+       exit "${2:-1}"
 }
 
 
@@ -103,16 +103,15 @@ IP Virtual Server version 1.2.1 (size=4096)
 Prot LocalAddress:Port Scheduler Flags
   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
 EOF
-       [ -d "$FAKE_LVS_STATE_DIR" ] || exit 0
+       cd "$FAKE_LVS_STATE_DIR" || exit 0
        (
-               cd "$FAKE_LVS_STATE_DIR"
                for d in *; do
                        [ -d "$d" ] || continue
-                       echo -n "$d "
+                       printf '%s ' "$d"
                        cat "${d}/.info"
                        for f in "${d}/"* ; do
                                [ -f "$f" ] || continue
-                               read forwarding_method <"$f"
+                               read -r forwarding_method <"$f"
                                printf "  -> %-28s %-7s %-6s %-10s %-10s\n" \
                                       "${f##*/}" "$forwarding_method" 1 0 0
                        done
index dd6de3b1826b3dbf6552424364edbed76213f9cb..45e4a97ca56b30a66a3de94f0609ff6de4f9512c 100755 (executable)
@@ -27,9 +27,11 @@ parse_options ()
        [ "$netid" = "tcp" ] || usage
 
        host="$1" ; shift
-       [ "$host" = "localhost" -o "$host" = "127.0.0.1" ] || usage
+       [ "$host" = "localhost" ] || [ "$host" = "127.0.0.1" ] || usage
 
-       [ 1 -le $# -a $# -le 2 ] || usage
+       if [ $# -lt 1 ] || [ $# -gt 2 ]; then
+               usage
+       fi
 
        p="$1"
        v="$2"
@@ -41,12 +43,14 @@ for i in ${FAKE_RPCINFO_SERVICES} ; do
     # This is stupidly cummulative, but needs to happen after the
     # initial split of the list above.
     IFS="${IFS}:"
+    # Want glob expansion
+    # shellcheck disable=SC2086
     set -- $i
     # $1 = program, $2 = low version, $3 = high version
 
     if [ "$1" = "$p" ] ; then
        if [ -n "$v" ] ; then
-           if [ "$2" -le "$v" -a "$v" -le "$3" ] ; then
+           if [ "$2" -le "$v" ] && [ "$v" -le "$3" ] ; then
                echo "program ${p} version ${v} ready and waiting"
                exit 0
            else
@@ -55,7 +59,7 @@ for i in ${FAKE_RPCINFO_SERVICES} ; do
                exit 1
            fi
        else
-           for j in $(seq $2 $3) ; do
+           for j in $(seq "$2" "$3") ; do
                echo "program ${p} version ${j} ready and waiting"
            done
            exit 0
index 78710346998860d02501935d59bef162f9f5cedd..c3b9f80c69b5feeb99fff48547a7b030e6b19997 100755 (executable)
@@ -31,7 +31,7 @@ while [ $# -gt 0 ] ; do
 done
 [ $# -eq 0 ] || usage
 
-if [ -z "$cip" -o -z "$sip" -o -z "$mon_name" -o -z "$state" ] ; then
+if [ -z "$cip" ] || [ -z "$sip" ] || [ -z "$mon_name" ] || [ -z "$state" ]; then
        usage
 fi
 
index 54ff436edd7e169469c053a53cfa632e83e9728d..b174243cd6ff282a1a4cc79f0f94e9c298011968 100755 (executable)
@@ -82,10 +82,11 @@ filter_socket ()
     ip="${socket%:*}"
     port="${socket##*:}"
 
-    if [ "$ok_ports" != "|" -a "${ok_ports#*|${port}|}" = "$ok_ports" ] ; then
+    if [ "$ok_ports" != "|" ] &&
+              [ "${ok_ports#*|"${port}"|}" = "$ok_ports" ]; then
        return 1
     fi
-    if [ "$ok_ips" != "|" -a "${ok_ips#*|${ip}|}" = "$ok_ips" ] ; then
+    if [ "$ok_ips" != "|" ] && [ "${ok_ips#*|"${ip}"|}" = "$ok_ips" ]; then
        return 1
     fi
 
@@ -98,6 +99,8 @@ ss_tcp_established ()
        echo "Recv-Q Send-Q Local Address:Port Peer Address:Port"
     fi
 
+    # Yes, lose the quoting so we can do a hacky parsing job
+    # shellcheck disable=SC2048,SC2086
     parse_filter $*
 
     for i in $FAKE_NETSTAT_TCP_ESTABLISHED ; do
@@ -111,7 +114,7 @@ ss_tcp_established ()
     if [ -z "$FAKE_NETSTAT_TCP_ESTABLISHED_FILE" ] ; then
            return
     fi
-    while read src dst ; do
+    while read -r src dst ; do
        if filter_socket "$srcs" "$sports" "$src" ; then
            echo 0 0 "$src" "$dst"
        fi
@@ -128,6 +131,8 @@ Netid State Recv-Q Send-Q   Local Address:Port   Peer Address:Port"
 EOF
        fi
 
+       # Yes, lose the quoting so we can do a hacky parsing job
+       # shellcheck disable=SC2048,SC2086
        parse_filter $*
 
        _n=12345
@@ -167,15 +172,19 @@ done
 shift $((OPTIND - 1))
 
 $tcp || $unix || not_supported "$*"
+if [ -z "$all" ]; then
+       nosupported "$*"
+fi
 
 if $tcp ; then
-       if [ "$1" != "state" -o "$2" != "established" ] || $listen ; then
+       if [ "$1" != "state" ] || [ "$2" != "established" ] || $listen; then
                usage
        fi
 
        shift 2
 
        # Yes, lose the quoting so we can do a hacky parsing job
+       # shellcheck disable=SC2048,SC2086
        ss_tcp_established $*
 
        exit
@@ -187,6 +196,7 @@ if $unix ; then
        fi
 
        # Yes, lose the quoting so we can do a hacky parsing job
+       # shellcheck disable=SC2048,SC2086
        unix_listen $*
 
        exit
index 816df3b3f581556f6cde46237e5ae9716eb6a759..c88615d35e3fcedcf9dc633b77b16e935298cb54 100755 (executable)
@@ -23,11 +23,11 @@ do_cmd ()
     case "$*" in
        *check) do_check ;;
        help) do_help ;;
-       "") read tdb_cmd && [ -n "$tdb_cmd" ] && do_cmd $tdb_cmd ;;
+       "") read -r tdb_cmd && [ -n "$tdb_cmd" ] && do_cmd "$tdb_cmd" ;;
        *) echo "$0: Not implemented: $*" ; exit 1 ;;
     esac
 }
 
-do_cmd $*
+do_cmd "$@"
 
 exit 0