Browse Source

watchdog/module-setup.sh: rewrite

- use local variables with _
- use associative array for the kernel modules
- install emergency hook even in the systemd case
- follow device path until /sys is reached
- set kernel version for modprobe checking
master
Harald Hoyer 9 years ago
parent
commit
74e2d1e69f
  1. 54
      modules.d/04watchdog/module-setup.sh

54
modules.d/04watchdog/module-setup.sh

@ -14,9 +14,7 @@ depends() {
install() { install() {
# Do not add watchdog hooks if systemd module is included # Do not add watchdog hooks if systemd module is included
# In that case, systemd will manage watchdog kick # In that case, systemd will manage watchdog kick
if dracut_module_included "systemd"; then if ! dracut_module_included "systemd"; then
return
fi
inst_hook cmdline 00 "$moddir/watchdog.sh" inst_hook cmdline 00 "$moddir/watchdog.sh"
inst_hook cmdline 50 "$moddir/watchdog.sh" inst_hook cmdline 50 "$moddir/watchdog.sh"
inst_hook pre-trigger 00 "$moddir/watchdog.sh" inst_hook pre-trigger 00 "$moddir/watchdog.sh"
@ -28,40 +26,52 @@ install() {
inst_hook pre-pivot 99 "$moddir/watchdog.sh" inst_hook pre-pivot 99 "$moddir/watchdog.sh"
inst_hook cleanup 00 "$moddir/watchdog.sh" inst_hook cleanup 00 "$moddir/watchdog.sh"
inst_hook cleanup 99 "$moddir/watchdog.sh" inst_hook cleanup 99 "$moddir/watchdog.sh"
fi
inst_hook emergency 02 "$moddir/watchdog-stop.sh" inst_hook emergency 02 "$moddir/watchdog-stop.sh"
inst_multiple -o wdctl inst_multiple -o wdctl
} }


installkernel() { installkernel() {
local -A _drivers
local _alldrivers _active _wdtdrv _wdtppath _dir
[[ -d /sys/class/watchdog/ ]] || return [[ -d /sys/class/watchdog/ ]] || return
wdtcmdline="" for _dir in /sys/class/watchdog/*; do
for dir in /sys/class/watchdog/*; do [[ -d "$_dir" ]] || continue
[[ -d "$dir" ]] || continue [[ -f "$_dir/state" ]] || continue
[[ -f "$dir/state" ]] || continue _active=$(< "$_dir/state")
active=$(< "$dir/state") ! [[ $hostonly ]] || [[ "$_active" = "active" ]] || continue
! [[ $hostonly ]] || [[ "$active" = "active" ]] || continue
# device/modalias will return driver of this device # device/modalias will return driver of this device
wdtdrv=$(< "$dir/device/modalias") _wdtdrv=$(< "$_dir/device/modalias")
# There can be more than one module represented by same # There can be more than one module represented by same
# modalias. Currently load all of them. # modalias. Currently load all of them.
# TODO: Need to find a way to avoid any unwanted module # TODO: Need to find a way to avoid any unwanted module
# represented by modalias # represented by modalias
wdtdrv=$(modprobe -R $wdtdrv) _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
instmods $wdtdrv if [[ $_wdtdrv ]]; then
wdtcmdline="$wdtcmdline$(echo $wdtdrv | tr " " ",")," instmods $_wdtdrv
for i in $_wdtdrv; do
_drivers[$i]=1
done
fi
# however in some cases, we also need to check that if there is # however in some cases, we also need to check that if there is
# a specific driver for the parent bus/device. In such cases # a specific driver for the parent bus/device. In such cases
# we also need to enable driver for parent bus/device. # we also need to enable driver for parent bus/device.
wdtppath=$(readlink -f "$dir/device/..") _wdtppath=$(readlink -f "$_dir/device/..")
while [ -f "$wdtppath/modalias" ] while [[ -d "$_wdtppath" ]] && [[ "$_wdtppath" != "/sys" ]]; do
do _wdtppath=$(readlink -f "$_wdtppath/..")
wdtpdrv=$(< "$wdtppath/modalias") [[ -f "$_wdtppath/modalias" ]] || continue
wdtpdrv=$(modprobe -R $wdtpdrv)
instmods $wdtpdrv _wdtdrv=$(< "$_wdtppath/modalias")
wdtcmdline="$wdtcmdline$(echo $wdtpdrv | tr " " ",")," _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
wdtppath=$(readlink -f "$wdtppath/..") if [[ $_wdtdrv ]]; then
instmods $_wdtdrv
for i in $_wdtdrv; do
_drivers[$i]=1
done
fi
done done
done done
# ensure that watchdog module is loaded as early as possible # ensure that watchdog module is loaded as early as possible
[[ $wdtcmdline = "" ]] || echo "rd.driver.pre=$wdtcmdline" > ${initdir}/etc/cmdline.d/00-watchdog.conf _alldrivers="${!_drivers[*]}"
[[ $_alldrivers ]] && echo "rd.driver.pre=${_alldrivers// /,}" > ${initdir}/etc/cmdline.d/00-watchdog.conf
} }

Loading…
Cancel
Save