Browse Source

fix(shutdown): shellcheck for modules.d/99shutdown

master
Harald Hoyer 4 years ago committed by Harald Hoyer
parent
commit
56ea45bd5a
  1. 0
      modules.d/99shutdown/.shchkdir
  2. 8
      modules.d/99shutdown/module-setup.sh
  3. 21
      modules.d/99shutdown/shutdown.sh

0
modules.d/99shutdown/.shchkdir

8
modules.d/99shutdown/module-setup.sh

@ -17,10 +17,10 @@ install() {
inst_multiple umount poweroff reboot halt losetup stat sleep timeout inst_multiple umount poweroff reboot halt losetup stat sleep timeout
inst_multiple -o kexec inst_multiple -o kexec
inst "$moddir/shutdown.sh" "$prefix/shutdown" inst "$moddir/shutdown.sh" "$prefix/shutdown"
[ -e "${initdir}/lib" ] || mkdir -m 0755 -p ${initdir}/lib [ -e "${initdir}/lib" ] || mkdir -m 0755 -p "${initdir}"/lib
mkdir -m 0755 -p ${initdir}/lib/dracut mkdir -m 0755 -p "${initdir}"/lib/dracut
mkdir -m 0755 -p ${initdir}/lib/dracut/hooks mkdir -m 0755 -p "${initdir}"/lib/dracut/hooks
for _d in $hookdirs shutdown shutdown-emergency; do 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 done
} }

21
modules.d/99shutdown/shutdown.sh

@ -10,6 +10,7 @@ ACTION="$1"
# and that it can actually be used. When console=null is used, # and that it can actually be used. When console=null is used,
# echo will fail. We do the check in a subshell, because otherwise # echo will fail. We do the check in a subshell, because otherwise
# the process will be killed when when running as PID 1. # the process will be killed when when running as PID 1.
# shellcheck disable=SC2217
[ -w /dev/console ] \ [ -w /dev/console ] \
&& (echo < /dev/console &> /dev/null) \ && (echo < /dev/console &> /dev/null) \
&& exec < /dev/console >> /dev/console 2>> /dev/console && exec < /dev/console >> /dev/console 2>> /dev/console
@ -62,7 +63,7 @@ umount_a() {
fi fi


local _did_umount="n" local _did_umount="n"
while read a mp a || [ -n "$mp" ]; do while read -r _ mp _ || [ -n "$mp" ]; do
strstr "$mp" oldroot || continue strstr "$mp" oldroot || continue
strstr "$_timed_out_umounts" " $mp " && continue strstr "$_timed_out_umounts" " $mp " && continue


@ -108,18 +109,20 @@ if strstr "$(cat /proc/mounts)" "/oldroot"; then
case $_pid in case $_pid in
*[!0-9]*) continue ;; *[!0-9]*) continue ;;
esac esac
[ $_pid -eq $$ ] && continue [ "$_pid" -eq $$ ] && continue


[ -e "/proc/$_pid/exe" ] || continue [ -e "/proc/$_pid/exe" ] || continue
[ -e "/proc/$_pid/root" ] || continue [ -e "/proc/$_pid/root" ] || continue


if strstr "$(ls -l /proc/$_pid /proc/$_pid/fd 2> /dev/null)" "oldroot"; then if strstr "$(ls -l /proc/"$_pid" /proc/"$_pid"/fd 2> /dev/null)" "oldroot"; then
warn "Blocking umount of /oldroot [$_pid] $(cat /proc/$_pid/cmdline)" warn "Blocking umount of /oldroot [$_pid] $(cat /proc/"$_pid"/cmdline)"
else else
warn "Still running [$_pid] $(cat /proc/$_pid/cmdline)" warn "Still running [$_pid] $(cat /proc/"$_pid"/cmdline)"
fi fi


# shellcheck disable=SC2012
ls -l "/proc/$_pid/exe" 2>&1 | vwarn ls -l "/proc/$_pid/exe" 2>&1 | vwarn
# shellcheck disable=SC2012
ls -l "/proc/$_pid/fd" 2>&1 | vwarn ls -l "/proc/$_pid/fd" 2>&1 | vwarn
done done
fi fi
@ -127,11 +130,11 @@ fi
_check_shutdown() { _check_shutdown() {
local __f local __f
local __s=0 local __s=0
for __f in $hookdir/shutdown/*.sh; do for __f in "$hookdir"/shutdown/*.sh; do
[ -e "$__f" ] || continue [ -e "$__f" ] || continue
(. "$__f" $1) # shellcheck disable=SC1090 disable=SC2240
if [ $? -eq 0 ]; then if (final="$1" . "$__f" "$1"); then
rm -f -- $__f rm -f -- "$__f"
else else
__s=1 __s=1
fi fi

Loading…
Cancel
Save