Skip to content

Commit 2ca7798

Browse files
nabijaczlewelibehlendorf
authored andcommitted
Fix SC2181 ("[ $?") outside tests/
Reviewed-by: John Kennedy <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #12042
1 parent 1d106ab commit 2ca7798

File tree

11 files changed

+29
-52
lines changed

11 files changed

+29
-52
lines changed

cmd/zed/zed.d/zed-functions.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ zed_lock()
127127
# Obtain a lock on the file bound to the given file descriptor.
128128
#
129129
eval "exec ${fd}> '${lockfile}'"
130-
err="$(flock --exclusive "${fd}" 2>&1)"
131-
# shellcheck disable=SC2181
132-
if [ $? -ne 0 ]; then
130+
if ! err="$(flock --exclusive "${fd}" 2>&1)"; then
133131
zed_log_err "failed to lock \"${lockfile}\": ${err}"
134132
fi
135133

@@ -165,9 +163,7 @@ zed_unlock()
165163
fi
166164

167165
# Release the lock and close the file descriptor.
168-
err="$(flock --unlock "${fd}" 2>&1)"
169-
# shellcheck disable=SC2181
170-
if [ $? -ne 0 ]; then
166+
if ! err="$(flock --unlock "${fd}" 2>&1)"; then
171167
zed_log_err "failed to unlock \"${lockfile}\": ${err}"
172168
fi
173169
eval "exec ${fd}>&-"

config/ax_python_devel.m4

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ variable to configure. See ``configure --help'' for reference.
148148
# Check if you have distutils, else fail
149149
#
150150
AC_MSG_CHECKING([for the distutils Python package])
151-
ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
152-
if test $? -eq 0; then
151+
if ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`; then
153152
AC_MSG_RESULT([yes])
154153
else
155154
AC_MSG_RESULT([no])

contrib/dracut/02zfsexpandknowledge/module-setup.sh.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ get_pool_devices() {
1717
local prefix
1818
local resolved
1919
poolconfigtemp=`mktemp`
20-
@sbindir@/zpool list -v -H -P "$1" > "$poolconfigtemp" 2>&1
21-
if [ "$?" != "0" ] ; then
20+
if ! @sbindir@/zpool list -v -H -P "$1" > "$poolconfigtemp" 2>&1 ; then
2221
poolconfigoutput=$(cat "$poolconfigtemp")
2322
dinfo "zfsexpandknowledge: pool $1 cannot be listed: $poolconfigoutput"
2423
else

contrib/dracut/90zfs/mount-zfs.sh.in

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ modprobe zfs 2>/dev/null
3838
udevadm settle
3939

4040
if [ "${root}" = "zfs:AUTO" ] ; then
41-
ZFS_DATASET="$(find_bootfs)"
42-
if [ $? -ne 0 ] ; then
41+
if ! ZFS_DATASET="$(find_bootfs)" ; then
4342
zpool import -N -a ${ZPOOL_IMPORT_OPTS}
44-
ZFS_DATASET="$(find_bootfs)"
45-
if [ $? -ne 0 ] ; then
43+
if ! ZFS_DATASET="$(find_bootfs)" ; then
4644
warn "ZFS: No bootfs attribute found in importable pools."
4745
export_all -F
4846

contrib/dracut/90zfs/zfs-lib.sh.in

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ command -v getargbool >/dev/null || {
55
# Compatibility with older Dracut versions.
66
# With apologies to the Dracut developers.
77
getargbool() {
8-
if ! [ -z "$_b" ]; then
9-
unset _b
10-
fi
118
_default="$1"; shift
12-
_b=$(getarg "$@")
13-
[ $? -ne 0 ] && [ -z "$_b" ] && _b="$_default"
9+
! _b=$(getarg "$@") && [ -z "$_b" ] && _b="$_default"
1410
if [ -n "$_b" ]; then
1511
[ "$_b" = "0" ] && return 1
1612
[ "$_b" = "no" ] && return 1

etc/init.d/zfs-zed.in

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,16 @@ do_stop()
6161
check_module_loaded "zfs" || exit 0
6262

6363
zfs_action "Stopping ZFS Event Daemon" zfs_daemon_stop \
64-
"$ZED_PIDFILE" "$ZED" "$ZED_NAME"
65-
if [ "$?" -eq "0" ]
64+
"$ZED_PIDFILE" "$ZED" "$ZED_NAME" || return "$?"
65+
66+
# Let's see if we have any pools imported
67+
pools=$("$ZPOOL" list -H -oname)
68+
if [ -z "$pools" ]
6669
then
67-
# Let's see if we have any pools imported
68-
pools=$("$ZPOOL" list -H -oname)
69-
if [ -z "$pools" ]
70-
then
71-
# No pools imported, it is/should be safe/possible to
72-
# unload modules.
73-
zfs_action "Unloading modules" rmmod zfs zunicode \
74-
zavl zcommon znvpair zlua spl
75-
return "$?"
76-
fi
77-
else
70+
# No pools imported, it is/should be safe/possible to
71+
# unload modules.
72+
zfs_action "Unloading modules" rmmod zfs zunicode \
73+
zavl zcommon znvpair zlua spl
7874
return "$?"
7975
fi
8076
}

etc/zfs/zfs-functions.in

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,17 @@ zfs_daemon_stop()
182182
# LSB functions
183183
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
184184
--pidfile "$PIDFILE" --name "$DAEMON_NAME"
185-
[ "$?" = 0 ] && rm -f "$PIDFILE"
185+
ret="$?"
186+
[ "$ret" = 0 ] && rm -f "$PIDFILE"
186187

187-
return $?
188+
return "$ret"
188189
elif type killproc > /dev/null 2>&1 ; then
189190
# Fedora/RedHat functions
190191
killproc -p "$PIDFILE" "$DAEMON_NAME"
191-
[ "$?" = 0 ] && rm -f "$PIDFILE"
192+
ret="$?"
193+
[ "$ret" = 0 ] && rm -f "$PIDFILE"
192194

193-
return $?
195+
return "$ret"
194196
else
195197
# Unsupported
196198
return 3
@@ -371,7 +373,7 @@ in_mtab()
371373
local mntpnt="$1"
372374
# Remove 'unwanted' characters.
373375
mntpnt=$(printf '%b\n' "$mntpnt" | sed -e 's,/,,g' \
374-
-e 's,-,,g' -e 's,\.,,g' -e 's, ,,g')
376+
-e 's,-,,g' -e 's,\.,,g' -e 's, ,,g')
375377
local var
376378

377379
var="$(eval echo MTAB_$mntpnt)"

scripts/commitcheck.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ coverity_fix_commit()
8787
IFS='
8888
'
8989
for line in $(git log -n 1 --pretty=%b "$REF" | grep -E '^CID'); do
90-
echo "$line" | grep -E '^CID [[:digit:]]+: ([[:graph:]]+|[[:space:]])+ \(([[:upper:]]|\_)+\)' > /dev/null
91-
# shellcheck disable=SC2181
92-
if [ $? -ne 0 ]; then
90+
if ! echo "$line" | grep -qE '^CID [[:digit:]]+: ([[:graph:]]+|[[:space:]])+ \(([[:upper:]]|\_)+\)'; then
9391
echo "error: commit message has an improperly formatted CID defect line"
9492
error=1
9593
fi

scripts/zfs.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ load_module_linux() {
120120
echo "Loading: $FILE ($VERSION)"
121121
fi
122122

123-
$LDMOD "$KMOD" >/dev/null 2>&1
124-
# shellcheck disable=SC2181
125-
if [ $? -ne 0 ]; then
123+
if ! $LDMOD "$KMOD" >/dev/null 2>&1; then
126124
echo "Failed to load $KMOD"
127125
return 1
128126
fi

scripts/zimport.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,8 @@ for TAG in $POOL_TAGS; do
491491
POOL_NAME=$($ZPOOL_CMD import -d "$POOL_DIR_COPY" | \
492492
awk '/pool:/ { print $2; exit 0 }')
493493

494-
$ZPOOL_CMD import -N -d "$POOL_DIR_COPY" \
495-
"$POOL_NAME" &>/dev/null
496-
# shellcheck disable=SC2181
497-
if [ $? -ne 0 ]; then
494+
if ! $ZPOOL_CMD import -N -d "$POOL_DIR_COPY"
495+
"$POOL_NAME" &>/dev/null; then
498496
fail_nonewline
499497
ERROR=1
500498
else

scripts/zloop.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ function usage
6262
function or_die
6363
{
6464
# shellcheck disable=SC2068
65-
$@
66-
# shellcheck disable=SC2181
67-
if [[ $? -ne 0 ]]; then
68-
# shellcheck disable=SC2145
69-
echo "Command failed: $@"
65+
if ! $@; then
66+
echo "Command failed: $*"
7067
exit 1
7168
fi
7269
}

0 commit comments

Comments
 (0)