Skip to content

Commit 6fc3099

Browse files
nabijaczlewelibehlendorf
authored andcommitted
Trim excess shellcheck annotations. Widen to all non-Korn scripts
Before, make shellcheck checked scripts/{commitcheck,make_gitrev,man-dates,paxcheck,zfs-helpers,zfs, zfs-tests,zimport,zloop}.sh cmd/zed/zed.d/{{all-debug,all-syslog,data-notify,generic-notify, resilver_finish-start-scrub,scrub_finish-notify, statechange-led,statechange-notify,trim_finish-notify, zed-functions}.sh,history_event-zfs-list-cacher.sh.in} cmd/zpool/zpool.d/{dm-deps,iostat,lsblk,media,ses,smart,upath} now it also checks contrib/dracut/{02zfsexpandknowledge/module-setup, 90zfs/{export-zfs,parse-zfs,zfs-needshutdown, zfs-load-key,zfs-lib,module-setup, mount-zfs,zfs-generator}}.sh.in cmd/zed/zed.d/{pool_import-led,vdev_attach-led, resilver_finish-notify,vdev_clear-led}.sh contrib/initramfs/{zfsunlock,hooks/zfs.in,scripts/local-top/zfs} tests/zfs-tests/tests/perf/scripts/prefetch_io.sh scripts/common.sh.in contrib/bpftrace/zfs-trace.sh autogen.sh Reviewed-by: John Kennedy <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #12042
1 parent 2ca7798 commit 6fc3099

File tree

18 files changed

+75
-89
lines changed

18 files changed

+75
-89
lines changed

Makefile.am

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ filter_executable = -exec test -x '{}' \; -print
126126
PHONY += shellcheck
127127
shellcheck:
128128
@if type shellcheck > /dev/null 2>&1; then \
129-
shellcheck --exclude=SC1090 --exclude=SC1117 --format=gcc \
130-
$$(find ${top_srcdir}/scripts/*.sh -type f) \
131-
$$(find ${top_srcdir}/cmd/zed/zed.d/*.sh -type f) \
129+
shellcheck --exclude=SC1090,SC1117,SC1091 --format=gcc \
130+
$$(find ${top_srcdir} -name "config*" -prune -name tests -prune \
131+
-o -name "*.sh" -o -name "*.sh.in" -type f) \
132132
$$(find ${top_srcdir}/cmd/zpool/zpool.d/* \
133133
-type f ${filter_executable}); \
134134
else \

cmd/fsck_zfs/fsck.zfs.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ for dataset in "$@"; do
2626

2727
case "$(@sbindir@/zpool list -Ho health "$pool")" in
2828
DEGRADED)
29-
ret=$(( $ret | 4 ))
29+
ret=$(( ret | 4 ))
3030
;;
3131
FAULTED)
3232
awk '!/^([[:space:]]*#.*)?$/ && $1 == "'"$dataset"'" && $3 == "zfs" {exit 1}' /etc/fstab || \
33-
ret=$(( $ret | 8 ))
33+
ret=$(( ret | 8 ))
3434
;;
3535
"")
3636
# Pool not found, error printed by zpool(8)
37-
ret=$(( $ret | 8 ))
37+
ret=$(( ret | 8 ))
3838
;;
3939
*)
4040
;;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ zed_notify_email()
267267
-e "s/@SUBJECT@/${subject}/g")"
268268

269269
# shellcheck disable=SC2086
270-
eval "${ZED_EMAIL_PROG}" ${ZED_EMAIL_OPTS} < "${pathname}" >/dev/null 2>&1
270+
${ZED_EMAIL_PROG} ${ZED_EMAIL_OPTS} < "${pathname}" >/dev/null 2>&1
271271
rv=$?
272272
if [ "${rv}" -ne 0 ]; then
273273
zed_log_err "$(basename "${ZED_EMAIL_PROG}") exit=${rv}"

cmd/zvol_wait/zvol_wait

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ filter_out_deleted_zvols() {
2020
OIFS="$IFS"
2121
IFS="
2222
"
23+
# shellcheck disable=SC2086
2324
zfs list -H -o name $zvols 2>/dev/null
2425
IFS="$OIFS"
2526
}

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

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,16 @@ get_pool_devices() {
1414
local poolconfigtemp
1515
local poolconfigoutput
1616
local pooldev
17-
local prefix
1817
local resolved
19-
poolconfigtemp=`mktemp`
18+
poolconfigtemp="$(mktemp)"
2019
if ! @sbindir@/zpool list -v -H -P "$1" > "$poolconfigtemp" 2>&1 ; then
21-
poolconfigoutput=$(cat "$poolconfigtemp")
20+
poolconfigoutput="$(cat "$poolconfigtemp")"
2221
dinfo "zfsexpandknowledge: pool $1 cannot be listed: $poolconfigoutput"
2322
else
24-
cat "$poolconfigtemp" | awk -F '\t' '/\t\/dev/ { print $2 }' | \
25-
while read pooldev ; do
26-
if [ -n "$pooldev" -a -e "$pooldev" ] ; then
27-
if [ -h "$pooldev" ] ; then
28-
resolved=`readlink -f "$pooldev"`
29-
else
30-
resolved="$pooldev"
31-
fi
23+
awk -F '\t' '/\t\/dev/ { print $2 }' "$poolconfigtemp" | \
24+
while read -r pooldev ; do
25+
if [ -e "$pooldev" ] ; then
26+
resolved="$(readlink -f "$pooldev")"
3227
dinfo "zfsexpandknowledge: pool $1 has device $pooldev (which resolves to $resolved)"
3328
echo "$resolved"
3429
fi
@@ -39,22 +34,20 @@ get_pool_devices() {
3934

4035
find_zfs_block_devices() {
4136
local dev
42-
local blockdev
4337
local mp
4438
local fstype
4539
local pool
46-
local key
47-
local n
48-
local poolconfigoutput
49-
numfields=`head -1 /proc/self/mountinfo | awk '{print NF}'`
50-
if [ "$numfields" == "10" ] ; then
51-
fields="n n n n mp n n fstype dev n"
40+
local _
41+
numfields="$(awk '{print NF; exit}' /proc/self/mountinfo)"
42+
if [ "$numfields" = "10" ] ; then
43+
fields="_ _ _ _ mp _ _ fstype dev _"
5244
else
53-
fields="n n n n mp n n n fstype dev n"
45+
fields="_ _ _ _ mp _ _ _ fstype dev _"
5446
fi
55-
while read $fields ; do
56-
if [ "$fstype" != "zfs" ]; then continue ; fi
57-
if [ "$mp" == "$1" ]; then
47+
# shellcheck disable=SC2086
48+
while read -r ${fields?} ; do
49+
[ "$fstype" = "zfs" ] || continue
50+
if [ "$mp" = "$1" ]; then
5851
pool=$(echo "$dev" | cut -d / -f 1)
5952
get_pool_devices "$pool"
6053
fi
@@ -76,10 +69,9 @@ check() {
7669
local _depdev
7770
local _depdevname
7871
local _depdevtype
79-
local _depmajmin
80-
local _dev
8172

82-
if [[ $hostonly ]]; then
73+
# shellcheck disable=SC2154
74+
if [ -n "$hostonly" ]; then
8375

8476
for mp in \
8577
"/" \
@@ -106,13 +98,12 @@ if [[ $hostonly ]]; then
10698
fstype=$(get_devtype "$dev")
10799
host_fs_types["$dev"]="$fstype"
108100
majmin=$(get_maj_min "$dev")
109-
if [[ -d /sys/dev/block/$majmin/slaves ]] ; then
110-
for _depdev in /sys/dev/block/$majmin/slaves/*; do
101+
if [ -d "/sys/dev/block/$majmin/slaves" ] ; then
102+
for _depdev in "/sys/dev/block/$majmin/slaves"/*; do
111103
[[ -f $_depdev/dev ]] || continue
112104
_depdev=/dev/$(basename "$_depdev")
113105
_depdevname=$(udevadm info --query=property --name="$_depdev" | grep "^DEVNAME=" | sed 's|^DEVNAME=||')
114106
_depdevtype=$(get_devtype "$_depdevname")
115-
_depmajmin=$(get_maj_min "$_depdevname")
116107
dinfo "zfsexpandknowledge: underlying block device backing ZFS dataset $mp: ${_depdevname//$'\n'/ }"
117108
array_contains "$_depdevname" "${host_devs[@]}" || host_devs+=("$_depdevname")
118109
host_fs_types["$_depdevname"]="$_depdevtype"

contrib/dracut/90zfs/module-setup.sh.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
# shellcheck disable=SC2154
23

34
check() {
45
# We depend on udev-rules being loaded
@@ -56,6 +57,7 @@ install() {
5657
# Fallback: Guess the path and include all matches
5758
dracut_install /usr/lib/gcc/*/*/libgcc_s.so*
5859
fi
60+
# shellcheck disable=SC2050
5961
if [ @LIBFETCH_DYNAMIC@ != 0 ]; then
6062
for d in $libdirs; do
6163
[ -e "$d"/@LIBFETCH_SONAME@ ] && dracut_install "$d"/@LIBFETCH_SONAME@

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
2+
# shellcheck disable=SC2034,SC2154
23

34
. /lib/dracut-zfs-lib.sh
45

@@ -39,6 +40,7 @@ udevadm settle
3940

4041
if [ "${root}" = "zfs:AUTO" ] ; then
4142
if ! ZFS_DATASET="$(find_bootfs)" ; then
43+
# shellcheck disable=SC2086
4244
zpool import -N -a ${ZPOOL_IMPORT_OPTS}
4345
if ! ZFS_DATASET="$(find_bootfs)" ; then
4446
warn "ZFS: No bootfs attribute found in importable pools."

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
2+
# shellcheck disable=SC2034,SC2154
23

34
. /lib/dracut-lib.sh
45

@@ -28,7 +29,7 @@ case "${root}" in
2829
info "ZFS: Enabling autodetection of bootfs after udev settles."
2930
;;
3031

31-
ZFS\=*|zfs:*|zfs:FILESYSTEM\=*|FILESYSTEM\=*)
32+
ZFS=*|zfs:*|FILESYSTEM=*)
3233
# root is explicit ZFS root. Parse it now. We can handle
3334
# a root=... param in any of the following formats:
3435
# root=ZFS=rpool/ROOT

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
2+
# shellcheck disable=SC2016,SC1004
23

34
grep -wq debug /proc/cmdline && debug=1
45
[ -n "$debug" ] && echo "zfs-generator: starting" >> /dev/kmsg

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import_pool() {
5959

6060
if ! zpool list -H "${pool}" > /dev/null 2>&1; then
6161
info "ZFS: Importing pool ${pool}..."
62+
# shellcheck disable=SC2086
6263
if ! zpool import -N ${ZPOOL_IMPORT_OPTS} "${pool}" ; then
6364
warn "ZFS: Unable to import pool ${pool}"
6465
return 1
@@ -123,13 +124,12 @@ for_relevant_root_children() {
123124
# export_all OPTS
124125
# exports all imported zfs pools.
125126
export_all() {
126-
opts="${@}"
127127
ret=0
128128

129129
IFS="${NEWLINE}"
130130
for pool in $(zpool list -H -o name) ; do
131131
if zpool list -H "${pool}" > /dev/null 2>&1; then
132-
zpool export "${pool}" ${opts} || ret=$?
132+
zpool export "${pool}" "$@" || ret=$?
133133
fi
134134
done
135135
IFS="${OLDIFS}"

contrib/dracut/90zfs/zfs-load-key.sh.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
2+
# shellcheck disable=SC2154
23

34
# only run this on systemd systems, we handle the decrypt in mount-zfs.sh in the mount hook otherwise
45
[ -e /bin/systemctl ] || [ -e /usr/bin/systemctl ] || return 0

contrib/initramfs/hooks/zfs.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ fi
2626

2727
# We use pthreads, but i-t from buster doesn't automatically
2828
# copy this indirect dependency: this can be removed when buster finally dies.
29-
for libgcc in $(find /lib/ -type f -name libgcc_s.so.[1-9]); do
29+
find /lib/ -type f -name "libgcc_s.so.[1-9]" | while read -r libgcc; do
3030
copy_exec "$libgcc"
3131
done
3232

33+
# shellcheck disable=SC2050
3334
if [ @LIBFETCH_DYNAMIC@ != 0 ]; then
34-
for libfetch in $(find /lib/ -name @LIBFETCH_SONAME@); do
35+
find /lib/ -name @LIBFETCH_SONAME@ | while read -r libfetch; do
3536
copy_exec "$libfetch"
3637
done
3738
fi

contrib/initramfs/scripts/local-top/zfs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
#!/bin/sh
2-
PREREQ="mdadm mdrun multipath"
2+
# shellcheck disable=SC2154
33

4-
prereqs()
5-
{
6-
echo "$PREREQ"
7-
}
84

9-
case $1 in
10-
# get pre-requisites
11-
prereqs)
12-
prereqs
5+
if [ "$1" = "prereqs" ]; then
6+
echo mdadm mdrun multipath
137
exit 0
14-
;;
15-
esac
8+
fi
169

1710

1811
#
1912
# Helper functions
2013
#
2114
message()
2215
{
23-
if [ -x /bin/plymouth ] && plymouth --ping; then
24-
plymouth message --text="$@"
16+
if plymouth --ping 2>/dev/null; then
17+
plymouth message --text="$*"
2518
else
26-
echo "$@" >&2
19+
echo "$*" >&2
2720
fi
2821
return 0
2922
}

scripts/zfs-tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ while getopts 'hvqxkfScn:d:s:r:?t:T:u:I:' OPTION; do
355355
exit 1
356356
;;
357357
v)
358-
# shellcheck disable=SC2034
359358
VERBOSE="yes"
360359
;;
361360
q)

scripts/zimport.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,13 @@ populate() {
164164
local MAX_DIR_SIZE=$2
165165
local MAX_FILE_SIZE=$3
166166

167-
# shellcheck disable=SC2086
168-
mkdir -p $ROOT/{a,b,c,d,e,f,g}/{h,i}
167+
mkdir -p "$ROOT"/{a,b,c,d,e,f,g}/{h,i}
169168
DIRS=$(find "$ROOT")
170169

171170
for DIR in $DIRS; do
172171
COUNT=$((RANDOM % MAX_DIR_SIZE))
173172

174-
# shellcheck disable=SC2034
175-
for i in $(seq $COUNT); do
173+
for _ in $(seq $COUNT); do
176174
FILE=$(mktemp -p "$DIR")
177175
SIZE=$((RANDOM % MAX_FILE_SIZE))
178176
dd if=/dev/urandom of="$FILE" bs=1k \
@@ -334,9 +332,8 @@ fi
334332
for TAG in $POOL_TAGS; do
335333

336334
if [ "$TAG" = "all" ]; then
337-
# shellcheck disable=SC2010
338-
ALL_TAGS=$(ls "$IMAGES_DIR" | grep "tar.bz2" | \
339-
sed 's/.tar.bz2//' | tr '\n' ' ')
335+
ALL_TAGS=$(echo "$IMAGES_DIR"/*.tar.bz2 | \
336+
sed "s|$IMAGES_DIR/||g;s|.tar.bz2||g")
340337
NEW_TAGS="$NEW_TAGS $ALL_TAGS"
341338
else
342339
NEW_TAGS="$NEW_TAGS $TAG"

scripts/zloop.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,16 @@ esac
9191

9292
function core_file
9393
{
94-
# shellcheck disable=SC2012 disable=2086
95-
printf "%s" "$(ls -tr1 $coreglob 2> /dev/null | head -1)"
94+
# shellcheck disable=SC2012,SC2086
95+
ls -tr1 $coreglob 2>/dev/null | head -1
9696
}
9797

9898
function core_prog
9999
{
100100
prog=$ZTEST
101101
core_id=$($GDB --batch -c "$1" | grep "Core was generated by" | \
102102
tr \' ' ')
103-
# shellcheck disable=SC2076
104-
if [[ "$core_id" =~ "zdb " ]]; then
103+
if [[ "$core_id" == *"zdb "* ]]; then
105104
prog=$ZDB
106105
fi
107106
printf "%s" "$prog"
@@ -303,8 +302,7 @@ while [[ $timeout -eq 0 ]] || [[ $curtime -le $((starttime + timeout)) ]]; do
303302
zopt="$zopt -s $size"
304303
zopt="$zopt -f $workdir"
305304

306-
# shellcheck disable=SC2124
307-
cmd="$ZTEST $zopt $@"
305+
cmd="$ZTEST $zopt $*"
308306
desc="$(date '+%m/%d %T') $cmd"
309307
echo "$desc" | tee -a ztest.history
310308
echo "$desc" >>ztest.out

tests/zfs-tests/tests/functional/cli_root/zpool_events/zpool_events_duplicates.ksh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ function do_dup_test
102102

103103
# Read the file a few times to generate some
104104
# duplicate errors of the same blocks
105-
# shellcheck disable=SC2034
106-
for i in {1..15}; do
105+
for _ in {1..15}; do
107106
dd if=$FILEPATH of=/dev/null bs=128K > /dev/null 2>&1
108107
done
109108
log_must zinject -c all

0 commit comments

Comments
 (0)