aboutsummaryrefslogtreecommitdiffstats
path: root/etc/zfs
diff options
context:
space:
mode:
authorнаб <[email protected]>2021-05-21 23:43:38 +0200
committerBrian Behlendorf <[email protected]>2021-06-01 11:38:49 -0700
commitc3ef9f7528d160faa08bbddfa29d7ad58835e1bd (patch)
tree92908b88b6e62697da5156129e2fe4b929411e64 /etc/zfs
parentd3858ab78894cbd6d2b63d350a25dfa7ab378ce7 (diff)
Turn shellcheck into a normal make target. Fix new files it caught
This checks every file it checked (and a few more), but explicitly instead of "if it works it works" best-effort (which wasn't that good anyway) Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #10512 Closes #12101
Diffstat (limited to 'etc/zfs')
-rw-r--r--etc/zfs/Makefile.am3
-rw-r--r--etc/zfs/zfs-functions.in35
2 files changed, 23 insertions, 15 deletions
diff --git a/etc/zfs/Makefile.am b/etc/zfs/Makefile.am
index b9123c176..3dee81c75 100644
--- a/etc/zfs/Makefile.am
+++ b/etc/zfs/Makefile.am
@@ -1,4 +1,5 @@
include $(top_srcdir)/config/Substfiles.am
+include $(top_srcdir)/config/Shellcheck.am
pkgsysconfdir = $(sysconfdir)/zfs
@@ -13,3 +14,5 @@ pkgsysconf_SCRIPTS = \
zfs-functions
SUBSTFILES += $(pkgsysconf_SCRIPTS)
+
+SHELLCHECK_SHELL = dash # local variables
diff --git a/etc/zfs/zfs-functions.in b/etc/zfs/zfs-functions.in
index a07cce60d..2fb065afd 100644
--- a/etc/zfs/zfs-functions.in
+++ b/etc/zfs/zfs-functions.in
@@ -44,7 +44,7 @@ elif type success > /dev/null 2>&1 ; then
fi
}
- zfs_log_begin_msg() { echo -n "$1 "; }
+ zfs_log_begin_msg() { printf "%s" "$1 "; }
zfs_log_end_msg() {
zfs_set_ifs "$OLD_IFS"
if [ "$1" -eq 0 ]; then
@@ -61,17 +61,17 @@ elif type success > /dev/null 2>&1 ; then
echo
zfs_set_ifs "$TMP_IFS"
}
- zfs_log_progress_msg() { echo -n "$""$1"; }
+ zfs_log_progress_msg() { printf "%s" "$""$1"; }
elif type einfo > /dev/null 2>&1 ; then
# Gentoo functions
zfs_log_begin_msg() { ebegin "$1"; }
zfs_log_end_msg() { eend "$1"; }
zfs_log_failure_msg() { eend "$1"; }
-# zfs_log_progress_msg() { echo -n "$1"; }
- zfs_log_progress_msg() { echo -n; }
+# zfs_log_progress_msg() { printf "%s" "$1"; }
+ zfs_log_progress_msg() { :; }
else
# Unknown - simple substitutes.
- zfs_log_begin_msg() { echo -n "$1"; }
+ zfs_log_begin_msg() { printf "%s" "$1"; }
zfs_log_end_msg() {
ret=$1
if [ "$ret" -ge 1 ]; then
@@ -82,7 +82,7 @@ else
return "$ret"
}
zfs_log_failure_msg() { echo "$1"; }
- zfs_log_progress_msg() { echo -n "$1"; }
+ zfs_log_progress_msg() { printf "%s" "$1"; }
fi
# Paths to what we need
@@ -134,15 +134,15 @@ zfs_daemon_start()
{
local PIDFILE="$1"; shift
local DAEMON_BIN="$1"; shift
- local DAEMON_ARGS="$*"
if type start-stop-daemon > /dev/null 2>&1 ; then
# LSB functions
start-stop-daemon --start --quiet --pidfile "$PIDFILE" \
--exec "$DAEMON_BIN" --test > /dev/null || return 1
- start-stop-daemon --start --quiet --exec "$DAEMON_BIN" -- \
- $DAEMON_ARGS || return 2
+ # shellcheck disable=SC2086
+ start-stop-daemon --start --quiet --exec "$DAEMON_BIN" -- \
+ "$@" || return 2
# On Debian, there's a 'sendsigs' script that will
# kill basically everything quite early and zed is stopped
@@ -153,8 +153,9 @@ zfs_daemon_start()
ln -sf "$PIDFILE" /run/sendsigs.omit.d/zed
fi
elif type daemon > /dev/null 2>&1 ; then
- # Fedora/RedHat functions
- daemon --pidfile "$PIDFILE" "$DAEMON_BIN" $DAEMON_ARGS
+ # Fedora/RedHat functions
+ # shellcheck disable=SC2086
+ daemon --pidfile "$PIDFILE" "$DAEMON_BIN" "$@"
return $?
else
# Unsupported
@@ -234,7 +235,7 @@ zfs_daemon_reload()
return $?
elif type killproc > /dev/null 2>&1 ; then
# Fedora/RedHat functions
- killproc -p "$PIDFILE" "$DAEMON_NAME" -HUP
+ killproc -p "$PIDFILE" "$DAEMON_NAME" -HUP
return $?
else
# Unsupported
@@ -287,6 +288,7 @@ checksystem()
# HOWEVER, only do this if we're called at the boot up
# (from init), not if we're running interactively (as in
# from the shell - we know what we're doing).
+ # shellcheck disable=SC2154
[ -n "$init" ] && exit 3
fi
@@ -301,6 +303,7 @@ checksystem()
get_root_pool()
{
+ # shellcheck disable=SC2046
set -- $(mount | grep ' on / ')
[ "$5" = "zfs" ] && echo "${1%%/*}"
}
@@ -338,9 +341,10 @@ load_module()
read_mtab()
{
local match="$1"
- local fs mntpnt fstype opts rest TMPFILE
+ local fs mntpnt fstype opts rest
# Unset all MTAB_* variables
+ # shellcheck disable=SC2046
unset $(env | grep ^MTAB_ | sed 's,=.*,,')
while read -r fs mntpnt fstype opts rest; do
@@ -352,8 +356,8 @@ read_mtab()
# * We need to use the external echo, because the
# internal one would interpret the backslash code
# (incorrectly), giving us a  instead.
- mntpnt=$(/bin/echo "$mntpnt" | sed "s,\\\0,\\\00,g")
- fs=$(/bin/echo "$fs" | sed "s,\\\0,\\\00,")
+ mntpnt=$(/bin/echo "$mntpnt" | sed 's,\\0,\\00,g')
+ fs=$(/bin/echo "$fs" | sed 's,\\0,\\00,')
# Remove 'unwanted' characters.
mntpnt=$(printf '%b\n' "$mntpnt" | sed -e 's,/,,g' \
@@ -386,6 +390,7 @@ read_fstab()
local i var
# Unset all FSTAB_* variables
+ # shellcheck disable=SC2046
unset $(env | grep ^FSTAB_ | sed 's,=.*,,')
i=0