From ae66d3aa90f66943ca726fa2ea7e038175aab6cf Mon Sep 17 00:00:00 2001 From: Damian Szuberski Date: Thu, 6 Jan 2022 23:36:04 +0100 Subject: [PATCH] Add ShellCheck's `--enable=all` inside `etc/` Strengthen static code analysis for shell scripts. Reviewed-by: Brian Behlendorf Reviewed-by: John Kennedy Signed-off-by: szubersk Closes #12913 --- etc/Makefile.am | 5 +++-- etc/default/Makefile.am | 3 ++- etc/default/zfs.in | 1 + etc/init.d/Makefile.am | 3 ++- etc/init.d/zfs-import.in | 1 + etc/init.d/zfs-load-key.in | 1 + etc/init.d/zfs-mount.in | 3 ++- etc/init.d/zfs-share.in | 1 + etc/init.d/zfs-zed.in | 1 + etc/zfs/Makefile.am | 3 ++- etc/zfs/zfs-functions.in | 7 ++++--- 11 files changed, 20 insertions(+), 9 deletions(-) diff --git a/etc/Makefile.am b/etc/Makefile.am index aa9ff182c8..4d20020361 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -1,9 +1,10 @@ include $(top_srcdir)/config/Shellcheck.am SUBDIRS = zfs sudoers.d -SHELLCHECKDIRS = zfs +SHELLCHECKDIRS = default $(ZFS_INIT_SYSV) zfs +SHELLCHECK_OPTS = --enable=all + if BUILD_LINUX -SHELLCHECKDIRS += default $(ZFS_INIT_SYSV) SUBDIRS += default $(ZFS_INIT_SYSTEMD) $(ZFS_INIT_SYSV) $(ZFS_MODULE_LOAD) endif DIST_SUBDIRS = default init.d zfs systemd modules-load.d sudoers.d diff --git a/etc/default/Makefile.am b/etc/default/Makefile.am index 0f7c96698d..74a4edd628 100644 --- a/etc/default/Makefile.am +++ b/etc/default/Makefile.am @@ -5,4 +5,5 @@ initconf_SCRIPTS = zfs SUBSTFILES += $(initconf_SCRIPTS) -SHELLCHECK_SHELL = sh +SHELLCHECK_SHELL = dash +SHELLCHECK_OPTS = --enable=all diff --git a/etc/default/zfs.in b/etc/default/zfs.in index fb4a1b65e3..ae813e9de9 100644 --- a/etc/default/zfs.in +++ b/etc/default/zfs.in @@ -1,4 +1,5 @@ # OpenZFS userland configuration. +# shellcheck disable=SC2154 # NOTE: This file is intended for sysv init and initramfs. # Changing some of these settings may not make any difference on diff --git a/etc/init.d/Makefile.am b/etc/init.d/Makefile.am index 658623fda4..c336d60755 100644 --- a/etc/init.d/Makefile.am +++ b/etc/init.d/Makefile.am @@ -7,4 +7,5 @@ init_SCRIPTS = zfs-import zfs-load-key zfs-mount zfs-share zfs-zed SUBSTFILES += $(init_SCRIPTS) -SHELLCHECK_SHELL = dash # local variables +SHELLCHECK_SHELL = dash +SHELLCHECK_OPTS = --enable=all diff --git a/etc/init.d/zfs-import.in b/etc/init.d/zfs-import.in index 130174f74d..a9a0604f81 100755 --- a/etc/init.d/zfs-import.in +++ b/etc/init.d/zfs-import.in @@ -1,4 +1,5 @@ #!@DEFAULT_INIT_SHELL@ +# shellcheck disable=SC2154 # # zfs-import This script will import ZFS pools # diff --git a/etc/init.d/zfs-load-key.in b/etc/init.d/zfs-load-key.in index 2f8deffdc8..53c7766b79 100755 --- a/etc/init.d/zfs-load-key.in +++ b/etc/init.d/zfs-load-key.in @@ -1,4 +1,5 @@ #!@DEFAULT_INIT_SHELL@ +# shellcheck disable=SC2154 # # zfs-load-key This script will load/unload the zfs filesystems keys. # diff --git a/etc/init.d/zfs-mount.in b/etc/init.d/zfs-mount.in index 000619b671..d196d1555a 100755 --- a/etc/init.d/zfs-mount.in +++ b/etc/init.d/zfs-mount.in @@ -1,4 +1,5 @@ #!@DEFAULT_INIT_SHELL@ +# shellcheck disable=SC2154 # # zfs-mount This script will mount/umount the zfs filesystems. # @@ -68,7 +69,7 @@ do_mount() check_boolean "$DO_OVERLAY_MOUNTS" && overlay=O zfs_action "Mounting ZFS filesystem(s)" \ - "$ZFS" mount -a$verbose$overlay "$MOUNT_EXTRA_OPTIONS" + "$ZFS" mount "-a$verbose$overlay" "$MOUNT_EXTRA_OPTIONS" # Require each volume/filesystem to have 'noauto' and no fsck # option. This shouldn't really be necessary, as long as one diff --git a/etc/init.d/zfs-share.in b/etc/init.d/zfs-share.in index ef628fe463..88978071cb 100755 --- a/etc/init.d/zfs-share.in +++ b/etc/init.d/zfs-share.in @@ -1,4 +1,5 @@ #!@DEFAULT_INIT_SHELL@ +# shellcheck disable=SC2154 # # zfs-share This script will network share zfs filesystems and volumes. # diff --git a/etc/init.d/zfs-zed.in b/etc/init.d/zfs-zed.in index e5256cbc62..47f742259b 100755 --- a/etc/init.d/zfs-zed.in +++ b/etc/init.d/zfs-zed.in @@ -1,4 +1,5 @@ #!@DEFAULT_INIT_SHELL@ +# shellcheck disable=SC2154 # # zfs-zed # diff --git a/etc/zfs/Makefile.am b/etc/zfs/Makefile.am index 3dee81c758..b7dbd33ccf 100644 --- a/etc/zfs/Makefile.am +++ b/etc/zfs/Makefile.am @@ -15,4 +15,5 @@ pkgsysconf_SCRIPTS = \ SUBSTFILES += $(pkgsysconf_SCRIPTS) -SHELLCHECK_SHELL = dash # local variables +SHELLCHECK_OPTS = --enable=all +SHELLCHECK_SHELL = dash diff --git a/etc/zfs/zfs-functions.in b/etc/zfs/zfs-functions.in index 30441dc35d..2ff1a18618 100644 --- a/etc/zfs/zfs-functions.in +++ b/etc/zfs/zfs-functions.in @@ -46,6 +46,7 @@ elif type success > /dev/null 2>&1 ; then zfs_log_begin_msg() { printf "%s" "$1 "; } zfs_log_end_msg() { + # shellcheck disable=SC2154 zfs_set_ifs "$OLD_IFS" if [ "$1" -eq 0 ]; then success @@ -119,12 +120,12 @@ zfs_action() $CMD ret=$? if [ "$ret" -eq 0 ]; then - zfs_log_end_msg $ret + zfs_log_end_msg "$ret" else - zfs_log_failure_msg $ret + zfs_log_failure_msg "$ret" fi - return $ret + return "$ret" } # Returns