1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

ctdb-scripts: Silence shellcheck warning SC2166

This covers the following:

  SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
  SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.

POSIX agrees that -a and -o should not be used:

  https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

Fixing these doesn't cause much churn.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2019-09-02 14:58:22 +10:00 committed by Amitay Isaacs
parent 597039daeb
commit 80cbebce71
6 changed files with 15 additions and 21 deletions

View File

@ -39,7 +39,7 @@ updateip)
oiface=$2
niface=$3
while read iface dest gw; do
if [ "$niface" = "$iface" -o "$oiface" = "$iface" ] ; then
if [ "$niface" = "$iface" ] || [ "$oiface" = "$iface" ] ; then
ip route add "$dest" via "$gw" dev "$iface" >/dev/null 2>&1
fi
done <"${CTDB_BASE}/static-routes"

View File

@ -20,8 +20,8 @@ table_id_prefix="ctdb."
[ "$CTDB_PER_IP_ROUTING_TABLE_ID_LOW" -lt "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] 2>/dev/null || \
die "error: CTDB_PER_IP_ROUTING_TABLE_ID_LOW[$CTDB_PER_IP_ROUTING_TABLE_ID_LOW] and/or CTDB_PER_IP_ROUTING_TABLE_ID_HIGH[$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH] improperly configured"
if [ "$CTDB_PER_IP_ROUTING_TABLE_ID_LOW" -le 253 -a \
255 -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] ; then
if [ "$CTDB_PER_IP_ROUTING_TABLE_ID_LOW" -le 253 ] && \
[ 255 -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] ; then
die "error: range CTDB_PER_IP_ROUTING_TABLE_ID_LOW[$CTDB_PER_IP_ROUTING_TABLE_ID_LOW]..CTDB_PER_IP_ROUTING_TABLE_ID_HIGH[$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH] must not include 253-255"
fi
@ -49,7 +49,7 @@ ipv4_is_valid_addr()
for _o in $(export IFS="." ; echo $_ip) ; do
# The 2>/dev/null stops output from failures where an "octet"
# is not numeric. The test will still fail.
if ! [ 0 -le $_o -a $_o -le 255 ] 2>/dev/null ; then
if ! [ 0 -le $_o ] && [ $_o -le 255 ] 2>/dev/null ; then
return 1
fi
_count=$((_count + 1))
@ -149,8 +149,9 @@ ensure_table_id_for_ip ()
fi
# Potentially update the new table id to be used. The
# redirect stops error spam for a non-numeric value.
if [ "$_new" -le "$_t" -a \
"$_t" -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] 2>/dev/null ; then
if [ "$_new" -le "$_t" ] && \
[ "$_t" -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] \
2>/dev/null ; then
_new=$((_t + 1))
fi
done <"$rt_tables"
@ -317,8 +318,8 @@ add_missing_routes ()
[ -n "$_iface" ] || continue
_table_id="${table_id_prefix}${_ip}"
if [ -z "$(ip route show table "$_table_id" 2>/dev/null)" -o \
"$1" = "force" ] ; then
if [ -z "$(ip route show table "$_table_id" 2>/dev/null)" ] || \
[ "$1" = "force" ] ; then
add_routing_for_ip "$_iface" "$_ip"
fi
done

View File

@ -139,7 +139,7 @@ nfs_check_service ()
fi
if $_ok ; then
if [ $unhealthy_after -ne 1 -o $restart_every -ne 0 ] ; then
if [ $unhealthy_after -ne 1 ] || [ $restart_every -ne 0 ] ; then
ctdb_counter_init "$_progname"
fi
exit 0
@ -179,7 +179,7 @@ nfs_check_service ()
# shellcheck disable=SC2031
nfs_restart_service ()
{
if [ -z "$service_stop_cmd" -o -z "$service_start_cmd" ] ; then
if [ -z "$service_stop_cmd" ] || [ -z "$service_start_cmd" ] ; then
die "ERROR: Can not restart service \"${_progname}\" without corresponding service_start_cmd/service_stop_cmd settings"
fi

View File

@ -28,14 +28,7 @@ shellcheck_test ()
# SC2164: Use cd ... || exit in case cd fails.
# - Most hits are on known directories. Too
# much churn, maybe later.
# SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not
# well defined.
# SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not
# well defined.
# - This can cause issues but the number of
# true positives will be very low. Too much
# churn, maybe later.
_excludes="SC1090,SC1091,SC2162,SC2164,SC2166"
_excludes="SC1090,SC1091,SC2162,SC2164"
unit_test shellcheck --exclude="$_excludes" "$@"
else
echo "WARNING: shellcheck not installed, skipping test"

View File

@ -217,7 +217,7 @@ t=$(date +%s)
for i in $nodes; do
t2=$(onnode "$i" date +%s)
d=$((t2 - t))
if [ "$d" -gt 30 -o "$d" -lt -30 ]; then
if [ "$d" -gt 30 ] || [ "$d" -lt -30 ]; then
error "time on node $i differs by $d seconds"
fi
done

View File

@ -106,7 +106,7 @@ echo_nth ()
node="$1"
fi
if [ -n "$node" -a "$node" != "#DEAD" ] ; then
if [ -n "$node" ] && [ "$node" != "#DEAD" ] ; then
echo "$node"
else
echo "${prog}: \"node ${n}\" does not exist" >&2
@ -213,7 +213,7 @@ get_nodes ()
local f="${CTDB_BASE}/nodes"
if [ -n "$ctdb_nodes_file" ] ; then
f="$ctdb_nodes_file"
if [ ! -e "$f" -a "${f#/}" = "$f" ] ; then
if [ ! -e "$f" ] && [ "${f#/}" = "$f" ] ; then
# $f is relative, try in $CTDB_BASE
f="${CTDB_BASE}/${f}"
fi