1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

ctdb-scripts: Avoid shellcheck warning SC2154 (unassigned variables)

SC2154: VAR is referenced but not assigned.

Change ctdb_setup_service_state_dir(), ctdb_get_pnn() and
ctdb_get_ip_address() to print the value so it can be assigned to a
variable.  The performance gain from avoiding the sub-shells when
calling these functions is close to zero.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2016-07-06 17:41:55 +10:00 committed by Amitay Isaacs
parent 9255d645f3
commit b208ae73d1
13 changed files with 37 additions and 43 deletions

View File

@ -10,8 +10,6 @@
loadconfig
ctdb_setup_service_state_dir "ctdb"
############################################################
select_tdb_checker ()

View File

@ -8,7 +8,7 @@
loadconfig
ctdb_setup_service_state_dir "system-monitoring"
service_state_dir=$(ctdb_setup_service_state_dir "system-monitoring") || exit $?
validate_percentage ()
{

View File

@ -11,7 +11,7 @@
service_name="nfs"
loadconfig
ctdb_setup_service_state_dir
service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
######################################################################
@ -25,7 +25,7 @@ nfs_callout_pre ()
######################################################################
nfs_callout_init
nfs_callout_init "$service_state_dir"
ctdb_start_stop_service

View File

@ -27,15 +27,15 @@ fi
takeover_assigned_ips ()
{
ctdb_get_pnn
_pnn=$(ctdb_get_pnn)
$CTDB -X ip |
awk -F'|' '{print $2}' |
while read ip ; do
_ip_details=$(ip_maskbits_iface "$ip")
if [ -n "$_ip_details" ] ; then
echo "Assigning $ip to this node ($pnn)"
$CTDB moveip "$ip" "$pnn"
echo "Assigning $ip to this node (${_pnn})"
$CTDB moveip "$ip" "$_pnn"
fi
done
}

View File

@ -19,7 +19,7 @@ loadconfig
[ -n "$CTDB_NATGW_NODES" ] || exit 0
export CTDB_NATGW_NODES
ctdb_setup_service_state_dir
service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
natgw_cfg_new="${service_state_dir}/cfg_new"
natgw_cfg_old="${service_state_dir}/cfg_old"
@ -27,9 +27,9 @@ natgw_master_old="${service_state_dir}/master_old"
ctdb_natgw_slave_only ()
{
ctdb_get_ip_address
_ip_address=$(ctdb_get_ip_address)
awk -v my_ip="$ip_address" \
awk -v my_ip="$_ip_address" \
'$1 == my_ip { if ($2 ~ "slave-only") { exit 0 } else { exit 1 } }' \
"$CTDB_NATGW_NODES"
}
@ -209,14 +209,13 @@ startup)
updatenatgw|ipreallocated)
natgw_check_config
ctdb_get_pnn
natgw_ensure_master
natgw_config_has_changed || natgw_master_has_changed || exit 0
natgw_clear
pnn=$(ctdb_get_pnn)
if [ "$pnn" = "$natgwmaster" ]; then
natgw_set_master
else

View File

@ -19,7 +19,7 @@ loadconfig
[ -n "$CTDB_MONITOR_MPDEVICES" ] || exit 0
ctdb_setup_service_state_dir
service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
multipath_fail="${service_state_dir}/fail"

View File

@ -14,8 +14,6 @@ service_name="winbind"
loadconfig
ctdb_setup_service_state_dir
service_start ()
{
service "$CTDB_SERVICE_WINBIND" stop >/dev/null 2>&1

View File

@ -30,7 +30,7 @@ service_name="samba"
loadconfig
ctdb_setup_service_state_dir
service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
service_start ()
{

View File

@ -11,7 +11,7 @@
service_name="nfs"
loadconfig
ctdb_setup_service_state_dir
service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
######################################################################
@ -248,7 +248,7 @@ nfs_update_lock_info ()
######################################################################
nfs_callout_init
nfs_callout_init "$service_state_dir"
ctdb_start_stop_service

View File

@ -51,7 +51,7 @@ EOF
# Stop iSCSI daemon
killall -9 tgtd >/dev/null 2>/dev/null
ctdb_get_pnn
pnn=$(ctdb_get_pnn)
[ -n "$pnn" ] || die "Failed to get node pnn"
# Start iSCSI daemon

View File

@ -19,9 +19,8 @@ fi
lvs_slave_only ()
{
ctdb_get_ip_address
awk -v my_ip="$ip_address" \
_ip_address=$(ctdb_get_ip_address)
awk -v my_ip="$_ip_address" \
'$1 == my_ip { if ($2 ~ "slave-only") { exit 0 } else { exit 1 } }' \
"$CTDB_LVS_NODES"
}
@ -80,7 +79,7 @@ ipreallocated)
kill_tcp_connections_local_only \
"$CTDB_LVS_PUBLIC_IFACE" "$CTDB_LVS_PUBLIC_IP"
ctdb_get_pnn
pnn=$(ctdb_get_pnn)
lvsmaster=$("${CTDB_HELPER_BINDIR}/ctdb_lvs" master)
if [ "$pnn" != "$lvsmaster" ] ; then
# This node is not the LVS master so change the IP address

View File

@ -245,7 +245,6 @@ nice_service()
######################################################
# Cached retrieval of PNN from local node. This never changes so why
# open a client connection to the server each time this is needed?
# This sets $pnn - this avoid an unnecessary subprocess.
ctdb_get_pnn ()
{
_pnn_file="${CTDB_SCRIPT_VARDIR}/my-pnn"
@ -253,11 +252,11 @@ ctdb_get_pnn ()
$CTDB pnn | sed -e 's@.*:@@' >"$_pnn_file"
fi
read pnn <"$_pnn_file"
cat "$_pnn_file"
}
# Cached retrieval of private IP address from local node. This never
# changes. Sets $ip_address to avoid an unnecessary subprocess.
# changes.
ctdb_get_ip_address ()
{
_ip_addr_file="${CTDB_SCRIPT_VARDIR}/my-ip-address"
@ -268,7 +267,7 @@ ctdb_get_ip_address ()
# ip_address is used by caller
# shellcheck disable=SC2034
read ip_address <"$_ip_addr_file"
cat "$_ip_addr_file"
}
######################################################
@ -782,11 +781,13 @@ ctdb_counter_get () {
ctdb_setup_service_state_dir ()
{
service_state_dir="${CTDB_SCRIPT_VARDIR}/service_state/${1:-${service_name}}"
mkdir -p "$service_state_dir" || {
echo "Error creating state dir \"$service_state_dir\""
exit 1
}
_s="${1:-${service_name}}"
_service_state_dir="${CTDB_SCRIPT_VARDIR}/service_state/${_s}"
mkdir -p "$_service_state_dir" ||
die "Error creating state dir \"${_service_state_dir}\""
echo "$_service_state_dir"
}
########################################################
@ -1161,6 +1162,8 @@ fi
nfs_callout_init ()
{
_state_dir="$1"
if [ -z "$CTDB_NFS_CALLOUT" ] ; then
CTDB_NFS_CALLOUT="${CTDB_BASE}/nfs-linux-kernel-callout"
fi
@ -1168,7 +1171,7 @@ nfs_callout_init ()
export CTDB_NFS_CALLOUT
# If the callout wants to use this then it must create it
export CTDB_NFS_CALLOUT_STATE_DIR="${service_state_dir}/callout-state"
export CTDB_NFS_CALLOUT_STATE_DIR="${_state_dir}/callout-state"
# Export, if set, for use by clustered NFS callouts
if [ -n "$CTDB_NFS_STATE_FS_TYPE" ] ; then
@ -1178,7 +1181,7 @@ nfs_callout_init ()
export CTDB_NFS_STATE_MNT
fi
nfs_callout_cache="${service_state_dir}/nfs_callout_cache"
nfs_callout_cache="${_state_dir}/nfs_callout_cache"
nfs_callout_cache_callout="${nfs_callout_cache}/CTDB_NFS_CALLOUT"
nfs_callout_cache_ops="${nfs_callout_cache}/ops"
}
@ -1230,10 +1233,9 @@ update_tickles ()
tickledir="${CTDB_SCRIPT_VARDIR}/tickles"
mkdir -p "$tickledir"
ctdb_get_pnn
# What public IPs do I hold?
_ips=$($CTDB -X ip | awk -F'|' -v pnn="$pnn" '$3 == pnn {print $2}')
_pnn=$(ctdb_get_pnn)
_ips=$($CTDB -X ip | awk -F'|' -v pnn="$_pnn" '$3 == pnn {print $2}')
# IPs and port as ss filters
_ip_filter=""

View File

@ -30,11 +30,13 @@ loadconfig nfs
nl="
"
ctdb_setup_service_state_dir "statd-callout"
service_state_dir=$(ctdb_setup_service_state_dir "statd-callout") || exit $?
cd "$service_state_dir" || \
die "Failed to change directory to \"${service_state_dir}\""
pnn=$(ctdb_get_pnn)
case "$1" in
# Keep a single file to keep track of the last "add-client" or
# "del-client'. These get pushed to ctdb.tdb during "update",
@ -47,7 +49,6 @@ case "$1" in
# statd does not tell us to which IP the client connected so
# we must add it to all the IPs that we serve
cip="$2"
ctdb_get_pnn
date=$(date '+%s')
# x is intentionally ignored
# shellcheck disable=SC2034
@ -64,7 +65,6 @@ case "$1" in
# statd does not tell us from which IP the client disconnected
# so we must add it to all the IPs that we serve
cip="$2"
ctdb_get_pnn
# x is intentionally ignored
# shellcheck disable=SC2034
$CTDB ip -X |
@ -84,7 +84,6 @@ case "$1" in
fi
# Filter out lines for any IP addresses that are not currently
# hosted public IP addresses.
ctdb_get_pnn
ctdb_ips=$($CTDB ip | tail -n +2)
sed_expr=$(echo "$ctdb_ips" |
awk -v pnn="$pnn" 'pnn == $2 { \
@ -160,7 +159,6 @@ case "$1" in
# probability that the client will accept the statd notify packet and
# not just ignore it.
# For all IPs we serve, collect info and push to the config database
ctdb_get_pnn
# Construct a sed expression to take catdb output and produce pairs of:
# server-IP client-IP