From 9ec9e6f77ba0dcb9af169d90879e4e78e4b65812 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 29 Jun 2016 18:11:44 +1000 Subject: [PATCH] ctdb-scripts: Quote some variable expansions This avoids relevant shellcheck warnings. This is most of the shellcheck low hanging fruit in the non-test code. Many of the other warnings produced by shellcheck are either false positives, are non-trivial to fix or a fix may result in worse code. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs Autobuild-User(master): Amitay Isaacs Autobuild-Date(master): Wed Jul 6 08:15:49 CEST 2016 on sn-devel-144 --- ctdb/config/ctdbd_wrapper | 3 +- ctdb/config/debug-hung-script.sh | 2 +- ctdb/config/debug_locks.sh | 8 ++--- ctdb/config/events.d/00.ctdb | 2 +- ctdb/config/events.d/01.reclock | 2 +- ctdb/config/events.d/10.interface | 20 ++++++----- ctdb/config/events.d/11.natgw | 16 ++++----- ctdb/config/events.d/11.routing | 2 +- ctdb/config/events.d/13.per_ip_routing | 2 +- ctdb/config/events.d/50.samba | 4 +-- ctdb/config/events.d/60.nfs | 8 ++--- ctdb/config/events.d/70.iscsi | 2 +- ctdb/config/events.d/91.lvs | 4 +-- ctdb/config/functions | 50 +++++++++++++------------- ctdb/config/nfs-linux-kernel-callout | 2 +- ctdb/config/notify.sh | 2 +- ctdb/config/statd-callout | 18 ++++++---- 17 files changed, 77 insertions(+), 70 deletions(-) diff --git a/ctdb/config/ctdbd_wrapper b/ctdb/config/ctdbd_wrapper index c007409cd4a..caeb81a9e74 100755 --- a/ctdb/config/ctdbd_wrapper +++ b/ctdb/config/ctdbd_wrapper @@ -214,7 +214,8 @@ start() ulimit -n $CTDB_MAX_OPEN_FILES fi - mkdir -p $(dirname "$pidfile") + _d=$(dirname "$pidfile") + mkdir -p "$_d" if [ -n "$CTDB_VALGRIND" -a "$CTDB_VALGRIND" != "no" ] ; then if [ "$CTDB_VALGRIND" = "yes" ] ; then diff --git a/ctdb/config/debug-hung-script.sh b/ctdb/config/debug-hung-script.sh index 921683c4669..cdf165763d7 100755 --- a/ctdb/config/debug-hung-script.sh +++ b/ctdb/config/debug-hung-script.sh @@ -25,7 +25,7 @@ fi echo "===== Start of hung script debug for PID=\"$1\", event=\"$2\" =====" echo "pstree -p -a ${1}:" - out=$(pstree -p -a $1) + out=$(pstree -p -a "$1") echo "$out" # Check for processes matching a regular expression and print diff --git a/ctdb/config/debug_locks.sh b/ctdb/config/debug_locks.sh index c0bbfcc2e57..62b67992340 100755 --- a/ctdb/config/debug_locks.sh +++ b/ctdb/config/debug_locks.sh @@ -36,7 +36,7 @@ loadconfig ctdb grep -F "POSIX ADVISORY WRITE" | awk '{ if($2 == "->") { print $6, $7, $8, $9, "W" } else { print $5, $6, $7, $8 } }' | while read pid rest ; do - pname=$(readlink /proc/$pid/exe) + pname=$(readlink "/proc/${pid}/exe") echo $pid $pname $rest done | sed -e "$sed_cmd" | grep "\.tdb" ) @@ -56,7 +56,7 @@ loadconfig ctdb # For each process waiting, log stack trace for pid in $pids ; do echo "----- Stack trace for PID=$pid -----" - read x x state x /dev/null - delete_ip_from_iface $niface $ip $maskbits 2>/dev/null + delete_ip_from_iface "$oiface" "$ip" "$maskbits" 2>/dev/null + delete_ip_from_iface "$niface" "$ip" "$maskbits" 2>/dev/null - add_ip_to_iface $niface $ip $maskbits || { + add_ip_to_iface "$niface" "$ip" "$maskbits" || { ip_unblock "$ip" "$oiface" exit 1 } @@ -234,11 +236,11 @@ case "$1" in flush_route_cache # propagate the new mac address - $CTDB gratiousarp $ip $niface + $CTDB gratiousarp "$ip" "$niface" # tickle all existing connections, so that dropped packets # are retransmited and the tcp streams work - tickle_tcp_connections $ip + tickle_tcp_connections "$ip" ;; monitor) diff --git a/ctdb/config/events.d/11.natgw b/ctdb/config/events.d/11.natgw index 980c4c43deb..04eea81b43d 100755 --- a/ctdb/config/events.d/11.natgw +++ b/ctdb/config/events.d/11.natgw @@ -91,7 +91,7 @@ _natgw_clear () _maskbits="${CTDB_NATGW_PUBLIC_IP#*/}" delete_ip_from_iface \ - $CTDB_NATGW_PUBLIC_IFACE $_ip $_maskbits >/dev/null 2>&1 + "$CTDB_NATGW_PUBLIC_IFACE" "$_ip" "$_maskbits" >/dev/null 2>&1 for _net_gw in $CTDB_NATGW_STATIC_ROUTES ; do _net="${_net_gw%@*}" ip route del "$_net" metric 10 >/dev/null 2>/dev/null @@ -100,16 +100,16 @@ _natgw_clear () # Delete the masquerading setup from a previous iteration where we # were the NAT-GW iptables -D POSTROUTING -t nat \ - -s $CTDB_NATGW_PRIVATE_NETWORK ! -d $CTDB_NATGW_PRIVATE_NETWORK \ + -s "$CTDB_NATGW_PRIVATE_NETWORK" ! -d "$CTDB_NATGW_PRIVATE_NETWORK" \ -j MASQUERADE >/dev/null 2>/dev/null - iptables -D INPUT -p tcp --syn -d $_ip/32 -j REJECT 2>/dev/null + iptables -D INPUT -p tcp --syn -d "${_ip}/32" -j REJECT 2>/dev/null } natgw_clear () { if [ -r "$natgw_cfg_old" ] ; then - (. $natgw_cfg_old ; _natgw_clear) + (. "$natgw_cfg_old" ; _natgw_clear) else _natgw_clear fi @@ -119,17 +119,17 @@ natgw_set_master () { set_proc sys/net/ipv4/ip_forward 1 iptables -A POSTROUTING -t nat \ - -s $CTDB_NATGW_PRIVATE_NETWORK ! -d $CTDB_NATGW_PRIVATE_NETWORK \ + -s "$CTDB_NATGW_PRIVATE_NETWORK" ! -d "$CTDB_NATGW_PRIVATE_NETWORK" \ -j MASQUERADE # block all incoming connections to the NATGW IP address ctdb_natgw_public_ip_host="${CTDB_NATGW_PUBLIC_IP%/*}/32" iptables -D INPUT -p tcp --syn \ - -d $ctdb_natgw_public_ip_host -j REJECT 2>/dev/null + -d "$ctdb_natgw_public_ip_host" -j REJECT 2>/dev/null iptables -I INPUT -p tcp --syn \ - -d $ctdb_natgw_public_ip_host -j REJECT 2>/dev/null + -d "$ctdb_natgw_public_ip_host" -j REJECT 2>/dev/null - ip addr add $CTDB_NATGW_PUBLIC_IP dev $CTDB_NATGW_PUBLIC_IFACE + ip addr add "$CTDB_NATGW_PUBLIC_IP" dev "$CTDB_NATGW_PUBLIC_IFACE" for _net_gw in $CTDB_NATGW_STATIC_ROUTES ; do _net="${_net_gw%@*}" if [ "$_net" != "$_net_gw" ] ; then diff --git a/ctdb/config/events.d/11.routing b/ctdb/config/events.d/11.routing index 20b99730b0c..87c0027124b 100755 --- a/ctdb/config/events.d/11.routing +++ b/ctdb/config/events.d/11.routing @@ -24,7 +24,7 @@ loadconfig -[ -f $CTDB_BASE/static-routes ] || { +[ -f "${CTDB_BASE}/static-routes" ] || { exit 0 } diff --git a/ctdb/config/events.d/13.per_ip_routing b/ctdb/config/events.d/13.per_ip_routing index 5085f37c88a..20f9085383e 100755 --- a/ctdb/config/events.d/13.per_ip_routing +++ b/ctdb/config/events.d/13.per_ip_routing @@ -267,7 +267,7 @@ EOF # is invalid. Therefore, go to a little bit of trouble to indent # the failure message so that it is associated with the above # warning message and doesn't look too nasty. - ip route flush table $_table_id 2>&1 | sed -e 's@^.@ &@' + ip route flush table "$_table_id" 2>&1 | sed -e 's@^.@ &@' } ###################################################################### diff --git a/ctdb/config/events.d/50.samba b/ctdb/config/events.d/50.samba index 3fae7f81613..7c3a804475f 100755 --- a/ctdb/config/events.d/50.samba +++ b/ctdb/config/events.d/50.samba @@ -83,7 +83,7 @@ testparm_foreground_update () _out="${smbconf_cache}.out" _err="${smbconf_cache}.err" - timeout $_timeout testparm -v -s >"$_out" 2>"$_err" + timeout "$_timeout" testparm -v -s >"$_out" 2>"$_err" case $? in 0) : ;; 124) @@ -123,7 +123,7 @@ testparm_background_update () { _timeout="$1" - testparm_foreground_update $_timeout >/dev/null 2>&1 /dev/null 2>&1 &1) ; then + if ! ctdb_check_rpc_out=$(rpcinfo -T "$_family" "$_localhost" \ + "$_progname" $_version 2>&1) ; then ctdb_check_rpc_out="$_progname failed RPC check: $ctdb_check_rpc_out" echo "$ctdb_check_rpc_out" @@ -217,10 +217,10 @@ nfs_check_rpcinfo () for _family in $_families ; do if [ -n "$_versions" ] ; then for _version in $_versions ; do - ctdb_check_rpc $_progname $_version $_family || return $? + ctdb_check_rpc "$_progname" "$_version" "$_family" || return $? done else - ctdb_check_rpc $_progname "" $_family || return $? + ctdb_check_rpc "$_progname" "" "$_family" || return $? fi done } diff --git a/ctdb/config/events.d/70.iscsi b/ctdb/config/events.d/70.iscsi index 7e27a539564..2d9e4a64fa1 100755 --- a/ctdb/config/events.d/70.iscsi +++ b/ctdb/config/events.d/70.iscsi @@ -54,7 +54,7 @@ EOF tgtd >/dev/null 2>&1 # Run a script for each currently hosted public IP address - ips=$(echo "$all_ips" | awk -F'|' -v pnn=$pnn '$3 == pnn {print $2}') + ips=$(echo "$all_ips" | awk -F'|' -v pnn="$pnn" '$3 == pnn {print $2}') for ip in $ips ; do script="${CTDB_START_ISCSI_SCRIPTS}/${ip}.sh" if [ -x "$script" ] ; then diff --git a/ctdb/config/events.d/91.lvs b/ctdb/config/events.d/91.lvs index 1d3f7331fd6..c758b732685 100755 --- a/ctdb/config/events.d/91.lvs +++ b/ctdb/config/events.d/91.lvs @@ -101,8 +101,8 @@ ipreallocated) "${CTDB_HELPER_BINDIR}/ctdb_lvs" list | awk -v pnn="$pnn" '$1 != pnn { print $2 }' | while read ip ; do - ipvsadm -a -t "$CTDB_LVS_PUBLIC_IP" -r $ip -g - ipvsadm -a -u "$CTDB_LVS_PUBLIC_IP" -r $ip -g + ipvsadm -a -t "$CTDB_LVS_PUBLIC_IP" -r "$ip" -g + ipvsadm -a -u "$CTDB_LVS_PUBLIC_IP" -r "$ip" -g done # Add localhost too... diff --git a/ctdb/config/functions b/ctdb/config/functions index d3e422ca6ef..64b7c012d90 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -70,12 +70,12 @@ _loadconfig() { return fi - if [ -f $CTDB_SYS_ETCDIR/sysconfig/$1 ]; then - . $CTDB_SYS_ETCDIR/sysconfig/$1 - elif [ -f $CTDB_SYS_ETCDIR/default/$1 ]; then - . $CTDB_SYS_ETCDIR/default/$1 - elif [ -f $CTDB_BASE/sysconfig/$1 ]; then - . $CTDB_BASE/sysconfig/$1 + if [ -f "${CTDB_SYS_ETCDIR}/sysconfig/$1" ]; then + . "${CTDB_SYS_ETCDIR}/sysconfig/$1" + elif [ -f "${CTDB_SYS_ETCDIR}/default/$1" ]; then + . "${CTDB_SYS_ETCDIR}/default/$1" + elif [ -f "${CTDB_BASE}/sysconfig/$1" ]; then + . "${CTDB_BASE}/sysconfig/$1" fi if [ "$1" = "ctdb" ] ; then @@ -97,7 +97,7 @@ loadconfig () { # configuration file. debug () { - if [ ${CTDB_SCRIPT_DEBUGLEVEL:-2} -ge 4 ] ; then + if [ "${CTDB_SCRIPT_DEBUGLEVEL:-2}" -ge 4 ] ; then # If there are arguments then echo them. Otherwise expect to # use stdin, which allows us to pass lots of debug using a # here document. @@ -146,7 +146,7 @@ script_log () *) # Handle all syslog:* variants here too. There's no tool to do # the lossy things, so just use logger. - logger -t "ctdbd: ${_tag}" $* + logger -t "ctdbd: ${_tag}" "$*" ;; esac } @@ -217,10 +217,10 @@ _service () $_nice /usr/sbin/service "$_service_name" "$_op" elif [ -x /bin/systemctl ]; then $_nice /bin/systemctl "$_op" "$_service_name" - elif [ -x $CTDB_SYS_ETCDIR/init.d/$_service_name ]; then - $_nice $CTDB_SYS_ETCDIR/init.d/$_service_name "$_op" - elif [ -x $CTDB_SYS_ETCDIR/rc.d/init.d/$_service_name ]; then - $_nice $CTDB_SYS_ETCDIR/rc.d/init.d/$_service_name "$_op" + elif [ -x "${CTDB_SYS_ETCDIR}/init.d/${_service_name}" ]; then + $_nice "${CTDB_SYS_ETCDIR}/init.d/${_service_name}" "$_op" + elif [ -x "${CTDB_SYS_ETCDIR}/rc.d/init.d/${_service_name}" ]; then + $_nice "${CTDB_SYS_ETCDIR}/rc.d/init.d/${_service_name}" "$_op" fi } @@ -488,7 +488,7 @@ kill_tcp_connections () return } - _remaining=$(get_tcp_connections_for_ip $_ip | wc -l) + _remaining=$(get_tcp_connections_for_ip "$_ip" | wc -l) if [ $_remaining -eq 0 ] ; then echo "Killed $_killcount TCP connections to released IP $_ip" @@ -521,9 +521,9 @@ tickle_tcp_connections () while read dest src; do echo "Tickle TCP connection $src $dest" - $CTDB tickle $src $dest >/dev/null 2>&1 || _failed=true + $CTDB tickle "$src" "$dest" >/dev/null 2>&1 || _failed=true echo "Tickle TCP connection $dest $src" - $CTDB tickle $dest $src >/dev/null 2>&1 || _failed=true + $CTDB tickle "$dest" "$src" >/dev/null 2>&1 || _failed=true done if $_failed ; then @@ -626,12 +626,12 @@ drop_ip () { _addr="${1%/*}" # Remove optional maskbits - set -- $(ip_maskbits_iface $_addr) + set -- $(ip_maskbits_iface "$_addr") if [ -n "$1" ] ; then _maskbits="$1" _iface="$2" echo "Removing public address $_addr/$_maskbits from device $_iface" - delete_ip_from_iface $_iface $_addr $_maskbits >/dev/null 2>&1 + delete_ip_from_iface "$_iface" "$_addr" "$_maskbits" >/dev/null 2>&1 fi } @@ -1244,7 +1244,7 @@ update_tickles () ctdb_get_pnn # What public IPs do I hold? - _ips=$($CTDB -X ip | awk -F'|' -v pnn=$pnn '$3 == pnn {print $2}') + _ips=$($CTDB -X ip | awk -F'|' -v pnn="$pnn" '$3 == pnn {print $2}') # IPs and port as ss filters _ip_filter="" @@ -1269,7 +1269,7 @@ update_tickles () # Record our current tickles in a temporary file _my_tickles="${tickledir}/${_port}.tickles.$$" for _i in $_ips ; do - $CTDB -X gettickles $_i $_port | + $CTDB -X gettickles "$_i" "$_port" | awk -F'|' 'NR > 1 { printf "%s:%s %s:%s\n", $2, $3, $4, $5 }' done | sort >"$_my_tickles" @@ -1277,13 +1277,13 @@ update_tickles () # Add tickles for connections that we haven't already got tickles for comm -23 "$_my_connections" "$_my_tickles" | while read _src _dst ; do - $CTDB addtickle $_src $_dst + $CTDB addtickle "$_src" "$_dst" done # Remove tickles for connections that are no longer there comm -13 "$_my_connections" "$_my_tickles" | while read _src _dst ; do - $CTDB deltickle $_src $_dst + $CTDB deltickle "$_src" "$_dst" done rm -f "$_my_connections" "$_my_tickles" @@ -1300,12 +1300,12 @@ update_tickles () . "$CTDB_RC_LOCAL" } -[ -x $CTDB_BASE/rc.local ] && { - . $CTDB_BASE/rc.local +[ -x "${CTDB_BASE}/rc.local" ] && { + . "${CTDB_BASE}/rc.local" } -[ -d $CTDB_BASE/rc.local.d ] && { - for i in $CTDB_BASE/rc.local.d/* ; do +[ -d "${CTDB_BASE}/rc.local.d" ] && { + for i in "${CTDB_BASE}/rc.local.d"/* ; do [ -x "$i" ] && . "$i" done } diff --git a/ctdb/config/nfs-linux-kernel-callout b/ctdb/config/nfs-linux-kernel-callout index 3b457be0ba6..9424d9a96cf 100755 --- a/ctdb/config/nfs-linux-kernel-callout +++ b/ctdb/config/nfs-linux-kernel-callout @@ -36,7 +36,7 @@ fi usage () { - _c=$(basename $0) + _c=$(basename "$0") cat <