]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
watchdog/module-setup.sh: rewrite
authorHarald Hoyer <harald@redhat.com>
Fri, 15 Apr 2016 09:27:20 +0000 (11:27 +0200)
committerPratyush Anand <panand@redhat.com>
Tue, 5 Jul 2016 07:22:16 +0000 (12:52 +0530)
- 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

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

index 6b35f9f5ccd31bd6e9a1f298bdf94758147edf6e..31102f4ec6b005ce845b47e750b07d4c302e272f 100755 (executable)
@@ -13,54 +13,64 @@ depends() {
 install() {
     # Do not add watchdog hooks if systemd module is included
     # In that case, systemd will manage watchdog kick
-    if dracut_module_included "systemd"; then
-           return
+    if ! dracut_module_included "systemd"; then
+        inst_hook cmdline   00 "$moddir/watchdog.sh"
+        inst_hook cmdline   50 "$moddir/watchdog.sh"
+        inst_hook pre-trigger 00 "$moddir/watchdog.sh"
+        inst_hook initqueue 00 "$moddir/watchdog.sh"
+        inst_hook mount     00 "$moddir/watchdog.sh"
+        inst_hook mount     50 "$moddir/watchdog.sh"
+        inst_hook mount     99 "$moddir/watchdog.sh"
+        inst_hook pre-pivot 00 "$moddir/watchdog.sh"
+        inst_hook pre-pivot 99 "$moddir/watchdog.sh"
+        inst_hook cleanup   00 "$moddir/watchdog.sh"
+        inst_hook cleanup   99 "$moddir/watchdog.sh"
     fi
-    inst_hook cmdline   00 "$moddir/watchdog.sh"
-    inst_hook cmdline   50 "$moddir/watchdog.sh"
-    inst_hook pre-trigger 00 "$moddir/watchdog.sh"
-    inst_hook initqueue 00 "$moddir/watchdog.sh"
-    inst_hook mount     00 "$moddir/watchdog.sh"
-    inst_hook mount     50 "$moddir/watchdog.sh"
-    inst_hook mount     99 "$moddir/watchdog.sh"
-    inst_hook pre-pivot 00 "$moddir/watchdog.sh"
-    inst_hook pre-pivot 99 "$moddir/watchdog.sh"
-    inst_hook cleanup   00 "$moddir/watchdog.sh"
-    inst_hook cleanup   99 "$moddir/watchdog.sh"
     inst_hook emergency 02 "$moddir/watchdog-stop.sh"
     inst_multiple -o wdctl
 }
 
 installkernel() {
+    local -A _drivers
+    local _alldrivers _active _wdtdrv _wdtppath _dir
     [[ -d /sys/class/watchdog/ ]] || return
-    wdtcmdline=""
-    for dir in /sys/class/watchdog/*; do
-           [[ -d "$dir" ]] || continue
-           [[ -f "$dir/state" ]] || continue
-           active=$(< "$dir/state")
-           ! [[ $hostonly ]] || [[ "$active" =  "active" ]] || continue
-           # device/modalias will return driver of this device
-           wdtdrv=$(< "$dir/device/modalias")
-           # There can be more than one module represented by same
-           # modalias. Currently load all of them.
-           # TODO: Need to find a way to avoid any unwanted module
-           # represented by modalias
-           wdtdrv=$(modprobe -R $wdtdrv)
-           instmods $wdtdrv
-           wdtcmdline="$wdtcmdline$(echo $wdtdrv | tr " " ","),"
-           # however in some cases, we also need to check that if there is
-           # a specific driver for the parent bus/device.  In such cases
-           # we also need to enable driver for parent bus/device.
-           wdtppath=$(readlink -f "$dir/device/..")
-           while [ -f "$wdtppath/modalias" ]
-           do
-                   wdtpdrv=$(< "$wdtppath/modalias")
-                   wdtpdrv=$(modprobe -R $wdtpdrv)
-                   instmods $wdtpdrv
-                   wdtcmdline="$wdtcmdline$(echo $wdtpdrv | tr " " ","),"
-                   wdtppath=$(readlink -f "$wdtppath/..")
-           done
+    for _dir in /sys/class/watchdog/*; do
+        [[ -d "$_dir" ]] || continue
+        [[ -f "$_dir/state" ]] || continue
+        _active=$(< "$_dir/state")
+        ! [[ $hostonly ]] || [[ "$_active" =  "active" ]] || continue
+        # device/modalias will return driver of this device
+        _wdtdrv=$(< "$_dir/device/modalias")
+        # There can be more than one module represented by same
+        # modalias. Currently load all of them.
+        # TODO: Need to find a way to avoid any unwanted module
+        # represented by modalias
+        _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
+        if [[ $_wdtdrv ]]; then
+            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
+        # a specific driver for the parent bus/device.  In such cases
+        # we also need to enable driver for parent bus/device.
+        _wdtppath=$(readlink -f "$_dir/device/..")
+        while [[ -d "$_wdtppath" ]] && [[ "$_wdtppath" != "/sys" ]]; do
+            _wdtppath=$(readlink -f "$_wdtppath/..")
+            [[ -f "$_wdtppath/modalias" ]] || continue
+
+            _wdtdrv=$(< "$_wdtppath/modalias")
+            _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
+            if [[ $_wdtdrv ]]; then
+                instmods $_wdtdrv
+                for i in $_wdtdrv; do
+                    _drivers[$i]=1
+                done
+            fi
+        done
     done
     # 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
 }