On Thu, 12 Aug 2021 13:47:43 +0800
Kairui Song <kasong(a)redhat.com> wrote:
https://github.com/koalaman/shellcheck/wiki/SC2181
Signed-off-by: Kairui Song <kasong(a)redhat.com>
---
dracut-module-setup.sh | 41 ++++++---------
kdumpctl | 112 +++++++++++++----------------------------
mkdumprd | 38 ++++----------
3 files changed, 60 insertions(+), 131 deletions(-)
[...]
diff --git a/mkdumprd b/mkdumprd
index e80ef1b1..0ef358d2 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -17,8 +17,7 @@ fi
export IN_KDUMP=1
#initiate the kdump logger
-dlog_init
-if [[ $? -ne 0 ]]; then
+if ! dlog_init; then
echo "failed to initiate the kdump logger."
exit 1
fi
@@ -115,19 +114,13 @@ mkdir_save_path_ssh()
local _opt _dir
_opt="-i $SSH_KEY_LOCATION -o BatchMode=yes -o StrictHostKeyChecking=yes"
not actually part of the patch but convert to array like in
patch 9/SC2086?
Thanks
Philipp
# shellcheck disable=SC2086
- ssh -qn $_opt "$1" mkdir -p "$SAVE_PATH" 2>&1 >
/dev/null
- _ret=$?
- if [[ $_ret -ne 0 ]]; then
+ ssh -qn $_opt "$1" mkdir -p "$SAVE_PATH" &>/dev/null ||
\
perror_exit "mkdir failed on $1:$SAVE_PATH"
- fi
#check whether user has write permission on $1:$SAVE_PATH
# shellcheck disable=SC2086
- _dir=$(ssh -qn $_opt "$1" mktemp -dqp "$SAVE_PATH"
2>/dev/null)
- _ret=$?
- if [[ $_ret -ne 0 ]]; then
+ _dir=$(ssh -qn $_opt "$1" mktemp -dqp "$SAVE_PATH"
2>/dev/null) || \
perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make
sure user has write permission on destination"
- fi
# shellcheck disable=SC2086
ssh -qn $_opt "$1" rmdir "$_dir"
@@ -165,11 +158,7 @@ check_size() {
;;
*)
return
- esac
-
- if [[ $? -ne 0 ]]; then
- perror_exit "Check dump target size failed"
- fi
+ esac || perror_exit "Check dump target size failed"
if [[ "$avail" -lt "$memtotal" ]]; then
dwarn "Warning: There might not be enough space to save a vmcore."
@@ -230,8 +219,7 @@ check_user_configured_target()
if [[ -n "$_mnt" ]]; then
if ! is_mounted "$_mnt"; then
if [[ $_opt = *",noauto"* ]]; then
- mount "$_mnt"
- [[ $? -ne 0 ]] && mount_failure "$_target"
"$_mnt" "$_fstype"
+ mount "$_mnt" || mount_failure "$_target"
"$_mnt" "$_fstype"
_mounted=$_mnt
else
perror_exit "Dump target \"$_target\" is neither mounted
nor configured as \"noauto\""
@@ -240,8 +228,7 @@ check_user_configured_target()
else
_mnt=$MKDUMPRD_TMPMNT
mkdir -p "$_mnt"
- mount "$_target" "$_mnt" -t "$_fstype" -o
defaults
- [[ $? -ne 0 ]] && mount_failure "$_target" ""
"$_fstype"
+ mount "$_target" "$_mnt" -t "$_fstype" -o defaults
|| mount_failure "$_target" "" "$_fstype"
_mounted=$_mnt
fi
@@ -286,11 +273,9 @@ verify_core_collector() {
}
add_mount() {
- local _mnt=$(to_mount "$@")
+ local _mnt
- if [[ $? -ne 0 ]]; then
- exit 1
- fi
+ _mnt=$(to_mount "$@") || exit 1
add_dracut_mount "$_mnt"
}
@@ -352,15 +337,12 @@ is_unresettable()
#return true if resettable
check_resettable()
{
- local _ret _target _override_resettable
+ local _target _override_resettable
_override_resettable=$(kdump_get_conf_val override_resettable)
OVERRIDE_RESETTABLE=${_override_resettable:-$OVERRIDE_RESETTABLE}
- for_each_block_target is_unresettable
- _ret=$?
-
- [[ $_ret -eq 0 ]] && return
+ for_each_block_target is_unresettable && return
return 1
}