bash scripts: fix redundant exit code check

upstream: fedora
resolves: bz2003832
conflict: none

commit a4648fc851
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Sep 8 17:23:16 2021 +0800

    bash scripts: fix redundant exit code check

    As suggested by:
    https://github.com/koalaman/shellcheck/wiki/SC2181

    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:
Tao Liu 2021-11-09 21:35:45 +08:00
parent bf4667b866
commit f6d6b60a6a
3 changed files with 61 additions and 132 deletions

View File

@ -255,8 +255,7 @@ kdump_static_ip() {
_gateway="[$_gateway]" _gateway="[$_gateway]"
else else
_prefix=$(cut -d'/' -f2 <<< "$_ipaddr") _prefix=$(cut -d'/' -f2 <<< "$_ipaddr")
_netmask=$(cal_netmask_by_prefix "$_prefix" "$_ipv6_flag") if ! _netmask=$(cal_netmask_by_prefix "$_prefix" "$_ipv6_flag"); then
if [[ "$?" -ne 0 ]]; then
derror "Failed to calculate netmask for $_ipaddr" derror "Failed to calculate netmask for $_ipaddr"
exit 1 exit 1
fi fi
@ -359,10 +358,7 @@ kdump_setup_bridge() {
_dev=${_dev##*/} _dev=${_dev##*/}
_kdumpdev=$_dev _kdumpdev=$_dev
if kdump_is_bond "$_dev"; then if kdump_is_bond "$_dev"; then
(kdump_setup_bond "$_dev" "$(get_nmcli_connection_show_cmd_by_ifname "$_dev")") (kdump_setup_bond "$_dev" "$(get_nmcli_connection_show_cmd_by_ifname "$_dev")") || exit 1
if [[ $? != 0 ]]; then
exit 1
fi
elif kdump_is_team "$_dev"; then elif kdump_is_team "$_dev"; then
kdump_setup_team "$_dev" kdump_setup_team "$_dev"
elif kdump_is_vlan "$_dev"; then elif kdump_is_vlan "$_dev"; then
@ -420,9 +416,7 @@ kdump_setup_team() {
echo " team=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/44team.conf" echo " team=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/44team.conf"
#Buggy version teamdctl outputs to stderr! #Buggy version teamdctl outputs to stderr!
#Try to use the latest version of teamd. #Try to use the latest version of teamd.
teamdctl "$_netdev" config dump > "${initdir}/tmp/$$-$_netdev.conf" if ! teamdctl "$_netdev" config dump > "${initdir}/tmp/$$-$_netdev.conf"; then
if [[ $? -ne 0 ]]
then
derror "teamdctl failed." derror "teamdctl failed."
exit 1 exit 1
fi fi
@ -442,10 +436,7 @@ kdump_setup_vlan() {
derror "Vlan over bridge is not supported!" derror "Vlan over bridge is not supported!"
exit 1 exit 1
elif kdump_is_bond "$_phydev"; then elif kdump_is_bond "$_phydev"; then
(kdump_setup_bond "$_phydev" "$(get_nmcli_connection_show_cmd_by_ifname "$_phydev")") (kdump_setup_bond "$_phydev" "$(get_nmcli_connection_show_cmd_by_ifname "$_phydev")") || exit 1
if [[ $? != 0 ]]; then
exit 1
fi
echo " vlan=$(kdump_setup_ifname "$_netdev"):$_phydev" > "${initdir}/etc/cmdline.d/43vlan.conf" echo " vlan=$(kdump_setup_ifname "$_netdev"):$_phydev" > "${initdir}/etc/cmdline.d/43vlan.conf"
else else
_kdumpdev="$(kdump_setup_ifname "$_phydev")" _kdumpdev="$(kdump_setup_ifname "$_phydev")"
@ -516,8 +507,8 @@ kdump_setup_znet() {
kdump_get_ip_route() kdump_get_ip_route()
{ {
local _route=$(/sbin/ip -o route get to "$1" 2>&1) local _route
if [[ $? != 0 ]]; then if ! _route=$(/sbin/ip -o route get to "$1" 2>&1); then
derror "Bad kdump network destination: $1" derror "Bad kdump network destination: $1"
exit 1 exit 1
fi fi
@ -561,8 +552,7 @@ kdump_install_net() {
_znet_netdev=$(find_online_znet_device) _znet_netdev=$(find_online_znet_device)
if [[ -n "$_znet_netdev" ]]; then if [[ -n "$_znet_netdev" ]]; then
_nm_show_cmd_znet=$(get_nmcli_connection_show_cmd_by_ifname "$_znet_netdev") _nm_show_cmd_znet=$(get_nmcli_connection_show_cmd_by_ifname "$_znet_netdev")
(kdump_setup_znet "$_znet_netdev" "$_nm_show_cmd_znet") if ! (kdump_setup_znet "$_znet_netdev" "$_nm_show_cmd_znet"); then
if [[ $? != 0 ]]; then
derror "Failed to set up znet" derror "Failed to set up znet"
exit 1 exit 1
fi fi
@ -592,10 +582,7 @@ kdump_install_net() {
if kdump_is_bridge "$_netdev"; then if kdump_is_bridge "$_netdev"; then
kdump_setup_bridge "$_netdev" kdump_setup_bridge "$_netdev"
elif kdump_is_bond "$_netdev"; then elif kdump_is_bond "$_netdev"; then
(kdump_setup_bond "$_netdev" "$_nm_show_cmd") (kdump_setup_bond "$_netdev" "$_nm_show_cmd") || exit 1
if [[ $? != 0 ]]; then
exit 1
fi
elif kdump_is_team "$_netdev"; then elif kdump_is_team "$_netdev"; then
kdump_setup_team "$_netdev" kdump_setup_team "$_netdev"
elif kdump_is_vlan "$_netdev"; then elif kdump_is_vlan "$_netdev"; then
@ -837,8 +824,10 @@ kdump_setup_iscsi_device() {
fi fi
# Setup initator # Setup initator
initiator_str=$(kdump_get_iscsi_initiator) if ! initiator_str=$(kdump_get_iscsi_initiator); then
[[ $? -ne "0" ]] && derror "Failed to get initiator name" && return 1 derror "Failed to get initiator name"
return 1
fi
# If initiator details do not exist already, append. # If initiator details do not exist already, append.
if ! grep -q "$initiator_str" "$netroot_conf"; then if ! grep -q "$initiator_str" "$netroot_conf"; then
@ -878,8 +867,7 @@ get_alias() {
for ip in $ips for ip in $ips
do do
# in /etc/hosts, alias can come at the 2nd column # in /etc/hosts, alias can come at the 2nd column
entries=$(grep "$ip" /etc/hosts | awk '{ $1=""; print $0 }') if entries=$(grep "$ip" /etc/hosts | awk '{ $1=""; print $0 }'); then
if [[ $? -eq 0 ]]; then
alias_set="$alias_set $entries" alias_set="$alias_set $entries"
fi fi
done done
@ -1004,8 +992,7 @@ kdump_install_random_seed() {
kdump_install_systemd_conf() { kdump_install_systemd_conf() {
# Kdump turns out to require longer default systemd mount timeout # Kdump turns out to require longer default systemd mount timeout
# than 1st kernel(90s by default), we use default 300s for kdump. # than 1st kernel(90s by default), we use default 300s for kdump.
grep -r "^[[:space:]]*DefaultTimeoutStartSec=" "${initdir}/etc/systemd/system.conf"* &>/dev/null if ! grep -q -r "^[[:space:]]*DefaultTimeoutStartSec=" "${initdir}/etc/systemd/system.conf"*; then
if [[ $? -ne 0 ]]; then
mkdir -p "${initdir}/etc/systemd/system.conf.d" mkdir -p "${initdir}/etc/systemd/system.conf.d"
echo "[Manager]" > "${initdir}/etc/systemd/system.conf.d/kdump.conf" echo "[Manager]" > "${initdir}/etc/systemd/system.conf.d/kdump.conf"
echo "DefaultTimeoutStartSec=300s" >> "${initdir}/etc/systemd/system.conf.d/kdump.conf" echo "DefaultTimeoutStartSec=300s" >> "${initdir}/etc/systemd/system.conf.d/kdump.conf"

112
kdumpctl
View File

@ -37,8 +37,7 @@ fi
. /lib/kdump/kdump-logger.sh . /lib/kdump/kdump-logger.sh
#initiate the kdump logger #initiate the kdump logger
dlog_init if ! dlog_init; then
if [[ $? -ne 0 ]]; then
echo "failed to initiate the kdump logger." echo "failed to initiate the kdump logger."
exit 1 exit 1
fi fi
@ -47,8 +46,7 @@ single_instance_lock()
{ {
local rc timeout=5 local rc timeout=5
exec 9>/var/lock/kdump if ! exec 9>/var/lock/kdump; then
if [[ $? -ne 0 ]]; then
derror "Create file lock failed" derror "Create file lock failed"
exit 1 exit 1
fi fi
@ -80,8 +78,7 @@ save_core()
mkdir -p "$coredir" mkdir -p "$coredir"
ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete" ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete"
cp --sparse=always /proc/vmcore "$coredir/vmcore-incomplete" if cp --sparse=always /proc/vmcore "$coredir/vmcore-incomplete"; then
if [[ $? == 0 ]]; then
mv "$coredir/vmcore-incomplete" "$coredir/vmcore" mv "$coredir/vmcore-incomplete" "$coredir/vmcore"
dinfo "saved a vmcore to $coredir" dinfo "saved a vmcore to $coredir"
else else
@ -95,8 +92,7 @@ save_core()
ddebug "makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg" ddebug "makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg"
makedumpfile --dump-dmesg "$coredir/vmcore" "$coredir/dmesg" >/dev/null 2>&1 makedumpfile --dump-dmesg "$coredir/vmcore" "$coredir/dmesg" >/dev/null 2>&1
ddebug "dumpoops -d $coredir/dmesg" ddebug "dumpoops -d $coredir/dmesg"
dumpoops -d "$coredir/dmesg" >/dev/null 2>&1 if dumpoops -d "$coredir/dmesg" >/dev/null 2>&1; then
if [[ $? == 0 ]]; then
dinfo "kernel oops has been collected by abrt tool" dinfo "kernel oops has been collected by abrt tool"
fi fi
fi fi
@ -121,8 +117,7 @@ check_earlykdump_is_enabled()
rebuild_kdump_initrd() rebuild_kdump_initrd()
{ {
ddebug "rebuild kdump initrd: $MKDUMPRD $TARGET_INITRD $KDUMP_KERNELVER" ddebug "rebuild kdump initrd: $MKDUMPRD $TARGET_INITRD $KDUMP_KERNELVER"
$MKDUMPRD "$TARGET_INITRD" "$KDUMP_KERNELVER" if ! $MKDUMPRD "$TARGET_INITRD" "$KDUMP_KERNELVER"; then
if [[ $? != 0 ]]; then
derror "mkdumprd: failed to make kdump initrd" derror "mkdumprd: failed to make kdump initrd"
return 1 return 1
fi fi
@ -184,8 +179,7 @@ backup_default_initrd()
dinfo "Backing up $DEFAULT_INITRD before rebuild." dinfo "Backing up $DEFAULT_INITRD before rebuild."
# save checksum to verify before restoring # save checksum to verify before restoring
sha1sum "$DEFAULT_INITRD" > "$INITRD_CHECKSUM_LOCATION" sha1sum "$DEFAULT_INITRD" > "$INITRD_CHECKSUM_LOCATION"
cp "$DEFAULT_INITRD" "$DEFAULT_INITRD_BAK" if ! cp "$DEFAULT_INITRD" "$DEFAULT_INITRD_BAK"; then
if [[ $? -ne 0 ]]; then
dwarn "WARNING: failed to backup $DEFAULT_INITRD." dwarn "WARNING: failed to backup $DEFAULT_INITRD."
rm -f "$DEFAULT_INITRD_BAK" rm -f "$DEFAULT_INITRD_BAK"
fi fi
@ -210,8 +204,7 @@ restore_default_initrd()
dwarn "WARNING: checksum mismatch! Can't restore original initrd.." dwarn "WARNING: checksum mismatch! Can't restore original initrd.."
else else
rm -f $INITRD_CHECKSUM_LOCATION rm -f $INITRD_CHECKSUM_LOCATION
mv "$DEFAULT_INITRD_BAK" "$DEFAULT_INITRD" if mv "$DEFAULT_INITRD_BAK" "$DEFAULT_INITRD"; then
if [[ $? -eq 0 ]]; then
derror "Restoring original initrd as fadump mode is disabled." derror "Restoring original initrd as fadump mode is disabled."
sync sync
fi fi
@ -308,8 +301,7 @@ get_pcs_cluster_modified_files()
setup_initrd() setup_initrd()
{ {
prepare_kdump_bootinfo if ! prepare_kdump_bootinfo; then
if [[ $? -ne 0 ]]; then
derror "failed to prepare for kdump bootinfo." derror "failed to prepare for kdump bootinfo."
return 1 return 1
fi fi
@ -372,8 +364,7 @@ check_files_modified()
files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep" files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep"
fi fi
for _module in $EXTRA_MODULES; do for _module in $EXTRA_MODULES; do
_module_file="$(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_module" 2>/dev/null)" if _module_file="$(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_module" 2>/dev/null)"; then
if [[ $? -eq 0 ]]; then
files="$files $_module_file" files="$files $_module_file"
for _dep_modules in $(modinfo -F depends "$_module" | tr ',' ' '); do for _dep_modules in $(modinfo -F depends "$_module" | tr ',' ' '); do
files="$files $(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_dep_modules" 2>/dev/null)" files="$files $(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_dep_modules" 2>/dev/null)"
@ -389,8 +380,7 @@ check_files_modified()
# HOOKS is mandatory and need to check the modification time # HOOKS is mandatory and need to check the modification time
files="$files $HOOKS" files="$files $HOOKS"
check_exist "$files" && check_executable "$EXTRA_BINS" check_exist "$files" && check_executable "$EXTRA_BINS" || return 2
[[ $? -ne 0 ]] && return 2
for file in $files; do for file in $files; do
if [[ -e "$file" ]]; then if [[ -e "$file" ]]; then
@ -455,7 +445,7 @@ check_drivers_modified()
# Skip deprecated/invalid driver name or built-in module # Skip deprecated/invalid driver name or built-in module
_module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name "$_driver" 2>/dev/null) _module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name "$_driver" 2>/dev/null)
_module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n "$_driver" 2>/dev/null) _module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n "$_driver" 2>/dev/null)
if [[ $? -ne 0 ]] || [[ -z "$_module_name" ]] || [[ "$_module_filename" = *"(builtin)"* ]]; then if [[ -z "$_module_name" ]] || [[ -z "$_module_filename" ]] || [[ "$_module_filename" = *"(builtin)"* ]]; then
continue continue
fi fi
if ! [[ " $_old_drivers " == *" $_module_name "* ]]; then if ! [[ " $_old_drivers " == *" $_module_name "* ]]; then
@ -505,8 +495,7 @@ check_fs_modified()
# if --mount argument present then match old and new target, mount # if --mount argument present then match old and new target, mount
# point and file system. If any of them mismatches then rebuild # point and file system. If any of them mismatches then rebuild
echo "$_dracut_args" | grep -q "\-\-mount" if echo "$_dracut_args" | grep -q "\-\-mount"; then
if [[ $? -eq 0 ]];then
# shellcheck disable=SC2046 # shellcheck disable=SC2046
set -- $(echo "$_dracut_args" | awk -F "--mount '" '{print $2}' | cut -d' ' -f1,2,3) set -- $(echo "$_dracut_args" | awk -F "--mount '" '{print $2}' | cut -d' ' -f1,2,3)
_old_dev=$1 _old_dev=$1
@ -558,11 +547,7 @@ check_rebuild()
local force_rebuild force_no_rebuild local force_rebuild force_no_rebuild
local ret system_modified="0" local ret system_modified="0"
setup_initrd setup_initrd || return 1
if [[ $? -ne 0 ]]; then
return 1
fi
force_no_rebuild=$(kdump_get_conf_val force_no_rebuild) force_no_rebuild=$(kdump_get_conf_val force_no_rebuild)
force_no_rebuild=${force_no_rebuild:-0} force_no_rebuild=${force_no_rebuild:-0}
@ -730,8 +715,7 @@ check_and_wait_network_ready()
# if server removes the authorized_keys or, no /root/.ssh/kdump_id_rsa # if server removes the authorized_keys or, no /root/.ssh/kdump_id_rsa
ddebug "$errmsg" ddebug "$errmsg"
echo "$errmsg" | grep -q "Permission denied\|No such file or directory\|Host key verification failed" if echo "$errmsg" | grep -q "Permission denied\|No such file or directory\|Host key verification failed"; then
if [[ $? -eq 0 ]]; then
derror "Could not create $DUMP_TARGET:$SAVE_PATH, you probably need to run \"kdumpctl propagate\"" derror "Could not create $DUMP_TARGET:$SAVE_PATH, you probably need to run \"kdumpctl propagate\""
return 1 return 1
fi fi
@ -757,16 +741,11 @@ check_and_wait_network_ready()
check_ssh_target() check_ssh_target()
{ {
check_and_wait_network_ready check_and_wait_network_ready
if [[ $? -ne 0 ]]; then
return 1
fi
return 0
} }
propagate_ssh_key() propagate_ssh_key()
{ {
check_ssh_config if ! check_ssh_config; then
if [[ $? -ne 0 ]]; then
derror "No ssh config specified in $KDUMP_CONFIG_FILE. Can't propagate" derror "No ssh config specified in $KDUMP_CONFIG_FILE. Can't propagate"
exit 1 exit 1
fi fi
@ -873,8 +852,7 @@ local_fs_dump_target()
{ {
local _target local _target
_target=$(grep -E "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf) if _target=$(grep -E "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf); then
if [[ $? -eq 0 ]]; then
echo "$_target" | awk '{print $2}' echo "$_target" | awk '{print $2}'
fi fi
} }
@ -936,8 +914,7 @@ check_fence_kdump_config()
return 1 return 1
fi fi
# node can be ipaddr # node can be ipaddr
echo "$ipaddrs " | grep -q "$node " if echo "$ipaddrs " | grep -q "$node "; then
if [[ $? -eq 0 ]]; then
derror "Option fence_kdump_nodes cannot contain $node" derror "Option fence_kdump_nodes cannot contain $node"
return 1 return 1
fi fi
@ -1031,14 +1008,12 @@ check_final_action_config()
start() start()
{ {
check_dump_feasibility if ! check_dump_feasibility; then
if [[ $? -ne 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
check_config if ! check_config; then
if [[ $? -ne 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
@ -1047,14 +1022,12 @@ start()
selinux_relabel selinux_relabel
fi fi
save_raw if ! save_raw; then
if [[ $? -ne 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
check_current_status if check_current_status; then
if [[ $? == 0 ]]; then
dwarn "Kdump already running: [WARNING]" dwarn "Kdump already running: [WARNING]"
return 0 return 0
fi fi
@ -1066,14 +1039,12 @@ start()
fi fi
fi fi
check_rebuild if ! check_rebuild; then
if [[ $? != 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
start_dump if ! start_dump; then
if [[ $? != 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
@ -1083,8 +1054,7 @@ start()
reload() reload()
{ {
check_current_status if ! check_current_status; then
if [[ $? -ne 0 ]]; then
dwarn "Kdump was not running: [WARNING]" dwarn "Kdump was not running: [WARNING]"
fi fi
@ -1092,24 +1062,20 @@ reload()
reload_fadump reload_fadump
return $? return $?
else else
stop_kdump if ! stop_kdump; then
fi derror "Stopping kdump: [FAILED]"
return 1
if [[ $? -ne 0 ]]; then fi
derror "Stopping kdump: [FAILED]"
return 1
fi fi
dinfo "Stopping kdump: [OK]" dinfo "Stopping kdump: [OK]"
setup_initrd if ! setup_initrd; then
if [[ $? -ne 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
start_dump if ! start_dump; then
if [[ $? -ne 0 ]]; then
derror "Starting kdump: [FAILED]" derror "Starting kdump: [FAILED]"
return 1 return 1
fi fi
@ -1137,6 +1103,7 @@ stop_kdump()
$KEXEC -p -u $KEXEC -p -u
fi fi
# shellcheck disable=SC2181
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
derror "kexec: failed to unload kdump kernel" derror "kexec: failed to unload kdump kernel"
return 1 return 1
@ -1148,16 +1115,14 @@ stop_kdump()
reload_fadump() reload_fadump()
{ {
echo 1 > $FADUMP_REGISTER_SYS_NODE if echo 1 > $FADUMP_REGISTER_SYS_NODE; then
if [[ $? == 0 ]]; then
dinfo "fadump: re-registered successfully" dinfo "fadump: re-registered successfully"
return 0 return 0
else else
# FADump could fail on older kernel where re-register # FADump could fail on older kernel where re-register
# support is not enabled. Try stop/start from userspace # support is not enabled. Try stop/start from userspace
# to handle such scenario. # to handle such scenario.
stop_fadump if stop_fadump; then
if [[ $? == 0 ]]; then
start_fadump start_fadump
return $? return $?
fi fi
@ -1174,6 +1139,7 @@ stop()
stop_kdump stop_kdump
fi fi
# shellcheck disable=SC2181
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
derror "Stopping kdump: [FAILED]" derror "Stopping kdump: [FAILED]"
return 1 return 1
@ -1184,10 +1150,7 @@ stop()
} }
rebuild() { rebuild() {
check_config check_config || return 1
if [[ $? -ne 0 ]]; then
return 1
fi
if check_ssh_config; then if check_ssh_config; then
if ! check_ssh_target; then if ! check_ssh_target; then
@ -1195,10 +1158,7 @@ rebuild() {
fi fi
fi fi
setup_initrd setup_initrd || return 1
if [[ $? -ne 0 ]]; then
return 1
fi
dinfo "Rebuilding $TARGET_INITRD" dinfo "Rebuilding $TARGET_INITRD"
rebuild_initrd rebuild_initrd

View File

@ -17,8 +17,7 @@ fi
export IN_KDUMP=1 export IN_KDUMP=1
#initiate the kdump logger #initiate the kdump logger
dlog_init if ! dlog_init; then
if [[ $? -ne 0 ]]; then
echo "failed to initiate the kdump logger." echo "failed to initiate the kdump logger."
exit 1 exit 1
fi fi
@ -114,18 +113,12 @@ mkdir_save_path_ssh()
{ {
local _opt _dir local _opt _dir
_opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes) _opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes)
ssh -qn "${_opt[@]}" "$1" mkdir -p "$SAVE_PATH" 2>&1 > /dev/null ssh -qn "${_opt[@]}" "$1" mkdir -p "$SAVE_PATH" &>/dev/null || \
_ret=$?
if [[ $_ret -ne 0 ]]; then
perror_exit "mkdir failed on $1:$SAVE_PATH" perror_exit "mkdir failed on $1:$SAVE_PATH"
fi
#check whether user has write permission on $1:$SAVE_PATH # check whether user has write permission on $1:$SAVE_PATH
_dir=$(ssh -qn "${_opt[@]}" "$1" mktemp -dqp "$SAVE_PATH" 2>/dev/null) _dir=$(ssh -qn "${_opt[@]}" "$1" mktemp -dqp "$SAVE_PATH" 2>/dev/null) || \
_ret=$?
if [[ $_ret -ne 0 ]]; then
perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination" perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination"
fi
ssh -qn "${_opt[@]}" "$1" rmdir "$_dir" ssh -qn "${_opt[@]}" "$1" rmdir "$_dir"
return 0 return 0
@ -162,11 +155,7 @@ check_size() {
;; ;;
*) *)
return return
esac esac || perror_exit "Check dump target size failed"
if [[ $? -ne 0 ]]; then
perror_exit "Check dump target size failed"
fi
if [[ "$avail" -lt "$memtotal" ]]; then if [[ "$avail" -lt "$memtotal" ]]; then
dwarn "Warning: There might not be enough space to save a vmcore." dwarn "Warning: There might not be enough space to save a vmcore."
@ -227,8 +216,7 @@ check_user_configured_target()
if [[ -n "$_mnt" ]]; then if [[ -n "$_mnt" ]]; then
if ! is_mounted "$_mnt"; then if ! is_mounted "$_mnt"; then
if [[ $_opt = *",noauto"* ]]; then if [[ $_opt = *",noauto"* ]]; then
mount "$_mnt" mount "$_mnt" || mount_failure "$_target" "$_mnt" "$_fstype"
[[ $? -ne 0 ]] && mount_failure "$_target" "$_mnt" "$_fstype"
_mounted=$_mnt _mounted=$_mnt
else else
perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\"" perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\""
@ -237,8 +225,7 @@ check_user_configured_target()
else else
_mnt=$MKDUMPRD_TMPMNT _mnt=$MKDUMPRD_TMPMNT
mkdir -p "$_mnt" mkdir -p "$_mnt"
mount "$_target" "$_mnt" -t "$_fstype" -o defaults mount "$_target" "$_mnt" -t "$_fstype" -o defaults || mount_failure "$_target" "" "$_fstype"
[[ $? -ne 0 ]] && mount_failure "$_target" "" "$_fstype"
_mounted=$_mnt _mounted=$_mnt
fi fi
@ -283,11 +270,9 @@ verify_core_collector() {
} }
add_mount() { add_mount() {
local _mnt=$(to_mount "$@") local _mnt
if [[ $? -ne 0 ]]; then _mnt=$(to_mount "$@") || exit 1
exit 1
fi
add_dracut_mount "$_mnt" add_dracut_mount "$_mnt"
} }
@ -349,7 +334,7 @@ is_unresettable()
#return true if resettable #return true if resettable
check_resettable() check_resettable()
{ {
local _ret _target _override_resettable local _target _override_resettable
_override_resettable=$(kdump_get_conf_val override_resettable) _override_resettable=$(kdump_get_conf_val override_resettable)
OVERRIDE_RESETTABLE=${_override_resettable:-$OVERRIDE_RESETTABLE} OVERRIDE_RESETTABLE=${_override_resettable:-$OVERRIDE_RESETTABLE}
@ -357,10 +342,7 @@ check_resettable()
perror_exit "override_resettable value '$OVERRIDE_RESETTABLE' is invalid" perror_exit "override_resettable value '$OVERRIDE_RESETTABLE' is invalid"
fi fi
for_each_block_target is_unresettable for_each_block_target is_unresettable && return
_ret=$?
[[ $_ret -eq 0 ]] && return
return 1 return 1
} }