bash scripts: declare and assign separately
upstream: fedora
resolves: bz2003832
conflict: none
commit 4f75e16700
Author: Kairui Song <kasong@redhat.com>
Date: Wed Aug 18 02:04:45 2021 +0800
bash scripts: declare and assign separately
Declare and assign separately to avoid masking return values:
https://github.com/koalaman/shellcheck/wiki/SC2155
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
Signed-off-by: Tao Liu <ltao@redhat.com>
This commit is contained in:
parent
f6d6b60a6a
commit
63308480fc
@ -321,7 +321,8 @@ kdump_get_mac_addr() {
|
|||||||
#Bonding or team master modifies the mac address
|
#Bonding or team master modifies the mac address
|
||||||
#of its slaves, we should use perm address
|
#of its slaves, we should use perm address
|
||||||
kdump_get_perm_addr() {
|
kdump_get_perm_addr() {
|
||||||
local addr=$(ethtool -P "$1" | sed -e 's/Permanent address: //')
|
local addr
|
||||||
|
addr=$(ethtool -P "$1" | sed -e 's/Permanent address: //')
|
||||||
if [[ -z "$addr" ]] || [[ "$addr" = "00:00:00:00:00:00" ]]
|
if [[ -z "$addr" ]] || [[ "$addr" = "00:00:00:00:00:00" ]]
|
||||||
then
|
then
|
||||||
derror "Can't get the permanent address of $1"
|
derror "Can't get the permanent address of $1"
|
||||||
@ -427,10 +428,13 @@ kdump_setup_team() {
|
|||||||
|
|
||||||
kdump_setup_vlan() {
|
kdump_setup_vlan() {
|
||||||
local _netdev=$1
|
local _netdev=$1
|
||||||
local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")"
|
local _phydev
|
||||||
local _netmac="$(kdump_get_mac_addr "$_phydev")"
|
local _netmac
|
||||||
local _kdumpdev
|
local _kdumpdev
|
||||||
|
|
||||||
|
_phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")"
|
||||||
|
_netmac="$(kdump_get_mac_addr "$_phydev")"
|
||||||
|
|
||||||
#Just support vlan over bond and team
|
#Just support vlan over bond and team
|
||||||
if kdump_is_bridge "$_phydev"; then
|
if kdump_is_bridge "$_phydev"; then
|
||||||
derror "Vlan over bridge is not supported!"
|
derror "Vlan over bridge is not supported!"
|
||||||
@ -522,7 +526,8 @@ kdump_get_ip_route_field()
|
|||||||
|
|
||||||
kdump_get_remote_ip()
|
kdump_get_remote_ip()
|
||||||
{
|
{
|
||||||
local _remote=$(get_remote_host "$1") _remote_temp
|
local _remote _remote_temp
|
||||||
|
_remote=$(get_remote_host "$1")
|
||||||
if is_hostname "$_remote"; then
|
if is_hostname "$_remote"; then
|
||||||
_remote_temp=$(getent ahosts "$_remote" | grep -v : | head -n 1)
|
_remote_temp=$(getent ahosts "$_remote" | grep -v : | head -n 1)
|
||||||
if [[ -z "$_remote_temp" ]]; then
|
if [[ -z "$_remote_temp" ]]; then
|
||||||
@ -876,11 +881,14 @@ get_alias() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
is_localhost() {
|
is_localhost() {
|
||||||
local hostnames=$(hostname -A)
|
local hostnames
|
||||||
local shortnames=$(hostname -A -s)
|
local shortnames
|
||||||
local aliasname=$(get_alias)
|
local aliasname
|
||||||
local nodename=$1
|
local nodename=$1
|
||||||
|
|
||||||
|
hostnames=$(hostname -A)
|
||||||
|
shortnames=$(hostname -A -s)
|
||||||
|
aliasname=$(get_alias)
|
||||||
hostnames="$hostnames $shortnames $aliasname"
|
hostnames="$hostnames $shortnames $aliasname"
|
||||||
|
|
||||||
for name in ${hostnames}; do
|
for name in ${hostnames}; do
|
||||||
|
17
kdumpctl
17
kdumpctl
@ -659,6 +659,8 @@ load_kdump()
|
|||||||
|
|
||||||
check_ssh_config()
|
check_ssh_config()
|
||||||
{
|
{
|
||||||
|
local SSH_TARGET
|
||||||
|
|
||||||
while read -r config_opt config_val; do
|
while read -r config_opt config_val; do
|
||||||
case "$config_opt" in
|
case "$config_opt" in
|
||||||
sshkey)
|
sshkey)
|
||||||
@ -682,7 +684,7 @@ check_ssh_config()
|
|||||||
done <<< "$(kdump_read_conf)"
|
done <<< "$(kdump_read_conf)"
|
||||||
|
|
||||||
#make sure they've configured kdump.conf for ssh dumps
|
#make sure they've configured kdump.conf for ssh dumps
|
||||||
local SSH_TARGET=$(echo -n "$DUMP_TARGET" | sed -n '/.*@/p')
|
SSH_TARGET=$(echo -n "$DUMP_TARGET" | sed -n '/.*@/p')
|
||||||
if [[ -z "$SSH_TARGET" ]]; then
|
if [[ -z "$SSH_TARGET" ]]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -694,13 +696,14 @@ check_ssh_config()
|
|||||||
# by the return val of 'ssh'
|
# by the return val of 'ssh'
|
||||||
check_and_wait_network_ready()
|
check_and_wait_network_ready()
|
||||||
{
|
{
|
||||||
local start_time=$(date +%s)
|
local start_time
|
||||||
local warn_once=1
|
local warn_once=1
|
||||||
local cur
|
local cur
|
||||||
local diff
|
local diff
|
||||||
local retval
|
local retval
|
||||||
local errmsg
|
local errmsg
|
||||||
|
|
||||||
|
start_time=$(date +%s)
|
||||||
while true; do
|
while true; do
|
||||||
errmsg=$(ssh -i "$SSH_KEY_LOCATION" -o BatchMode=yes "$DUMP_TARGET" mkdir -p "$SAVE_PATH" 2>&1)
|
errmsg=$(ssh -i "$SSH_KEY_LOCATION" -o BatchMode=yes "$DUMP_TARGET" mkdir -p "$SAVE_PATH" 2>&1)
|
||||||
retval=$?
|
retval=$?
|
||||||
@ -904,9 +907,13 @@ selinux_relabel()
|
|||||||
|
|
||||||
check_fence_kdump_config()
|
check_fence_kdump_config()
|
||||||
{
|
{
|
||||||
local hostname=$(hostname)
|
local hostname
|
||||||
local ipaddrs=$(hostname -I)
|
local ipaddrs
|
||||||
local nodes=$(kdump_get_conf_val "fence_kdump_nodes")
|
local nodes
|
||||||
|
|
||||||
|
hostname=$(hostname)
|
||||||
|
ipaddrs=$(hostname -I)
|
||||||
|
nodes=$(kdump_get_conf_val "fence_kdump_nodes")
|
||||||
|
|
||||||
for node in $nodes; do
|
for node in $nodes; do
|
||||||
if [[ "$node" = "$hostname" ]]; then
|
if [[ "$node" = "$hostname" ]]; then
|
||||||
|
21
mkdumprd
21
mkdumprd
@ -29,9 +29,9 @@ OVERRIDE_RESETTABLE=0
|
|||||||
extra_modules=""
|
extra_modules=""
|
||||||
dracut_args=( --add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth dash resume ifcfg earlykdump" )
|
dracut_args=( --add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth dash resume ifcfg earlykdump" )
|
||||||
|
|
||||||
readonly MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)"
|
MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)"
|
||||||
[ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed."
|
[ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed."
|
||||||
readonly MKDUMPRD_TMPMNT="$MKDUMPRD_TMPDIR/target"
|
MKDUMPRD_TMPMNT="$MKDUMPRD_TMPDIR/target"
|
||||||
|
|
||||||
trap '
|
trap '
|
||||||
ret=$?;
|
ret=$?;
|
||||||
@ -195,9 +195,11 @@ mount_failure()
|
|||||||
check_user_configured_target()
|
check_user_configured_target()
|
||||||
{
|
{
|
||||||
local _target=$1 _cfg_fs_type=$2 _mounted
|
local _target=$1 _cfg_fs_type=$2 _mounted
|
||||||
local _mnt=$(get_mntpoint_from_target "$_target")
|
local _mnt _opt _fstype
|
||||||
local _opt=$(get_mntopt_from_target "$_target")
|
|
||||||
local _fstype=$(get_fs_type_from_target "$_target")
|
_mnt=$(get_mntpoint_from_target "$_target")
|
||||||
|
_opt=$(get_mntopt_from_target "$_target")
|
||||||
|
_fstype=$(get_fs_type_from_target "$_target")
|
||||||
|
|
||||||
if [[ -n "$_fstype" ]]; then
|
if [[ -n "$_fstype" ]]; then
|
||||||
# In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf
|
# In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf
|
||||||
@ -314,14 +316,13 @@ for_each_block_target()
|
|||||||
#return false if unresettable.
|
#return false if unresettable.
|
||||||
is_unresettable()
|
is_unresettable()
|
||||||
{
|
{
|
||||||
local path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable"
|
local path device resettable=1
|
||||||
local resettable=1
|
|
||||||
|
|
||||||
if [[ -f "$path" ]]
|
path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable"
|
||||||
then
|
if [[ -f "$path" ]]; then
|
||||||
resettable="$(<"$path")"
|
resettable="$(<"$path")"
|
||||||
[[ $resettable -eq 0 ]] && [[ "$OVERRIDE_RESETTABLE" -eq 0 ]] && {
|
[[ $resettable -eq 0 ]] && [[ "$OVERRIDE_RESETTABLE" -eq 0 ]] && {
|
||||||
local device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}')
|
device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}')
|
||||||
derror "Error: Can not save vmcore because device $device is unresettable"
|
derror "Error: Can not save vmcore because device $device is unresettable"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ if ! dlog_init; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
readonly MKFADUMPRD_TMPDIR="$(mktemp -d -t mkfadumprd.XXXXXX)"
|
MKFADUMPRD_TMPDIR="$(mktemp -d -t mkfadumprd.XXXXXX)"
|
||||||
[ -d "$MKFADUMPRD_TMPDIR" ] || perror_exit "mkfadumprd: mktemp -d -t mkfadumprd.XXXXXX failed."
|
[ -d "$MKFADUMPRD_TMPDIR" ] || perror_exit "mkfadumprd: mktemp -d -t mkfadumprd.XXXXXX failed."
|
||||||
trap '
|
trap '
|
||||||
ret=$?;
|
ret=$?;
|
||||||
|
Loading…
Reference in New Issue
Block a user