From 56ea45bd5a8b460a89c670114c1ba43e0d3c1032 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 26 Mar 2021 10:29:35 +0100 Subject: [PATCH] fix(shutdown): shellcheck for modules.d/99shutdown --- modules.d/99shutdown/.shchkdir | 0 modules.d/99shutdown/module-setup.sh | 8 ++++---- modules.d/99shutdown/shutdown.sh | 21 ++++++++++++--------- 3 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 modules.d/99shutdown/.shchkdir diff --git a/modules.d/99shutdown/.shchkdir b/modules.d/99shutdown/.shchkdir new file mode 100644 index 00000000..e69de29b diff --git a/modules.d/99shutdown/module-setup.sh b/modules.d/99shutdown/module-setup.sh index 973ab519..2b999024 100755 --- a/modules.d/99shutdown/module-setup.sh +++ b/modules.d/99shutdown/module-setup.sh @@ -17,10 +17,10 @@ install() { inst_multiple umount poweroff reboot halt losetup stat sleep timeout inst_multiple -o kexec inst "$moddir/shutdown.sh" "$prefix/shutdown" - [ -e "${initdir}/lib" ] || mkdir -m 0755 -p ${initdir}/lib - mkdir -m 0755 -p ${initdir}/lib/dracut - mkdir -m 0755 -p ${initdir}/lib/dracut/hooks + [ -e "${initdir}/lib" ] || mkdir -m 0755 -p "${initdir}"/lib + mkdir -m 0755 -p "${initdir}"/lib/dracut + mkdir -m 0755 -p "${initdir}"/lib/dracut/hooks for _d in $hookdirs shutdown shutdown-emergency; do - mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d + mkdir -m 0755 -p "${initdir}"/lib/dracut/hooks/"$_d" done } diff --git a/modules.d/99shutdown/shutdown.sh b/modules.d/99shutdown/shutdown.sh index ac23de51..ea597794 100755 --- a/modules.d/99shutdown/shutdown.sh +++ b/modules.d/99shutdown/shutdown.sh @@ -10,6 +10,7 @@ ACTION="$1" # and that it can actually be used. When console=null is used, # echo will fail. We do the check in a subshell, because otherwise # the process will be killed when when running as PID 1. +# shellcheck disable=SC2217 [ -w /dev/console ] \ && (echo < /dev/console &> /dev/null) \ && exec < /dev/console >> /dev/console 2>> /dev/console @@ -62,7 +63,7 @@ umount_a() { fi local _did_umount="n" - while read a mp a || [ -n "$mp" ]; do + while read -r _ mp _ || [ -n "$mp" ]; do strstr "$mp" oldroot || continue strstr "$_timed_out_umounts" " $mp " && continue @@ -108,18 +109,20 @@ if strstr "$(cat /proc/mounts)" "/oldroot"; then case $_pid in *[!0-9]*) continue ;; esac - [ $_pid -eq $$ ] && continue + [ "$_pid" -eq $$ ] && continue [ -e "/proc/$_pid/exe" ] || continue [ -e "/proc/$_pid/root" ] || continue - if strstr "$(ls -l /proc/$_pid /proc/$_pid/fd 2> /dev/null)" "oldroot"; then - warn "Blocking umount of /oldroot [$_pid] $(cat /proc/$_pid/cmdline)" + if strstr "$(ls -l /proc/"$_pid" /proc/"$_pid"/fd 2> /dev/null)" "oldroot"; then + warn "Blocking umount of /oldroot [$_pid] $(cat /proc/"$_pid"/cmdline)" else - warn "Still running [$_pid] $(cat /proc/$_pid/cmdline)" + warn "Still running [$_pid] $(cat /proc/"$_pid"/cmdline)" fi + # shellcheck disable=SC2012 ls -l "/proc/$_pid/exe" 2>&1 | vwarn + # shellcheck disable=SC2012 ls -l "/proc/$_pid/fd" 2>&1 | vwarn done fi @@ -127,11 +130,11 @@ fi _check_shutdown() { local __f local __s=0 - for __f in $hookdir/shutdown/*.sh; do + for __f in "$hookdir"/shutdown/*.sh; do [ -e "$__f" ] || continue - (. "$__f" $1) - if [ $? -eq 0 ]; then - rm -f -- $__f + # shellcheck disable=SC1090 disable=SC2240 + if (final="$1" . "$__f" "$1"); then + rm -f -- "$__f" else __s=1 fi