Blame SOURCES/0439-watchdog-module-setup.sh-rewrite.patch

18971c
From 4c83fd10ab2a43272eab59719486064085beb2df Mon Sep 17 00:00:00 2001
18971c
From: Harald Hoyer <harald@redhat.com>
18971c
Date: Fri, 15 Apr 2016 11:27:20 +0200
18971c
Subject: [PATCH] watchdog/module-setup.sh: rewrite
18971c
18971c
- use local variables with _
18971c
- use associative array for the kernel modules
18971c
- install emergency hook even in the systemd case
18971c
- follow device path until /sys is reached
18971c
- set kernel version for modprobe checking
18971c
---
18971c
 modules.d/04watchdog/module-setup.sh | 92 +++++++++++++++-------------
18971c
 1 file changed, 51 insertions(+), 41 deletions(-)
18971c
18971c
diff --git a/modules.d/04watchdog/module-setup.sh b/modules.d/04watchdog/module-setup.sh
18971c
index 6b35f9f5..31102f4e 100755
18971c
--- a/modules.d/04watchdog/module-setup.sh
18971c
+++ b/modules.d/04watchdog/module-setup.sh
18971c
@@ -13,54 +13,64 @@ depends() {
18971c
 install() {
18971c
     # Do not add watchdog hooks if systemd module is included
18971c
     # In that case, systemd will manage watchdog kick
18971c
-    if dracut_module_included "systemd"; then
18971c
-	    return
18971c
+    if ! dracut_module_included "systemd"; then
18971c
+        inst_hook cmdline   00 "$moddir/watchdog.sh"
18971c
+        inst_hook cmdline   50 "$moddir/watchdog.sh"
18971c
+        inst_hook pre-trigger 00 "$moddir/watchdog.sh"
18971c
+        inst_hook initqueue 00 "$moddir/watchdog.sh"
18971c
+        inst_hook mount     00 "$moddir/watchdog.sh"
18971c
+        inst_hook mount     50 "$moddir/watchdog.sh"
18971c
+        inst_hook mount     99 "$moddir/watchdog.sh"
18971c
+        inst_hook pre-pivot 00 "$moddir/watchdog.sh"
18971c
+        inst_hook pre-pivot 99 "$moddir/watchdog.sh"
18971c
+        inst_hook cleanup   00 "$moddir/watchdog.sh"
18971c
+        inst_hook cleanup   99 "$moddir/watchdog.sh"
18971c
     fi
18971c
-    inst_hook cmdline   00 "$moddir/watchdog.sh"
18971c
-    inst_hook cmdline   50 "$moddir/watchdog.sh"
18971c
-    inst_hook pre-trigger 00 "$moddir/watchdog.sh"
18971c
-    inst_hook initqueue 00 "$moddir/watchdog.sh"
18971c
-    inst_hook mount     00 "$moddir/watchdog.sh"
18971c
-    inst_hook mount     50 "$moddir/watchdog.sh"
18971c
-    inst_hook mount     99 "$moddir/watchdog.sh"
18971c
-    inst_hook pre-pivot 00 "$moddir/watchdog.sh"
18971c
-    inst_hook pre-pivot 99 "$moddir/watchdog.sh"
18971c
-    inst_hook cleanup   00 "$moddir/watchdog.sh"
18971c
-    inst_hook cleanup   99 "$moddir/watchdog.sh"
18971c
     inst_hook emergency 02 "$moddir/watchdog-stop.sh"
18971c
     inst_multiple -o wdctl
18971c
 }
18971c
 
18971c
 installkernel() {
18971c
+    local -A _drivers
18971c
+    local _alldrivers _active _wdtdrv _wdtppath _dir
18971c
     [[ -d /sys/class/watchdog/ ]] || return
18971c
-    wdtcmdline=""
18971c
-    for dir in /sys/class/watchdog/*; do
18971c
-	    [[ -d "$dir" ]] || continue
18971c
-	    [[ -f "$dir/state" ]] || continue
18971c
-	    active=$(< "$dir/state")
18971c
-	    ! [[ $hostonly ]] || [[ "$active" =  "active" ]] || continue
18971c
-	    # device/modalias will return driver of this device
18971c
-	    wdtdrv=$(< "$dir/device/modalias")
18971c
-	    # There can be more than one module represented by same
18971c
-	    # modalias. Currently load all of them.
18971c
-	    # TODO: Need to find a way to avoid any unwanted module
18971c
-	    # represented by modalias
18971c
-	    wdtdrv=$(modprobe -R $wdtdrv)
18971c
-	    instmods $wdtdrv
18971c
-	    wdtcmdline="$wdtcmdline$(echo $wdtdrv | tr " " ","),"
18971c
-	    # however in some cases, we also need to check that if there is
18971c
-	    # a specific driver for the parent bus/device.  In such cases
18971c
-	    # we also need to enable driver for parent bus/device.
18971c
-	    wdtppath=$(readlink -f "$dir/device/..")
18971c
-	    while [ -f "$wdtppath/modalias" ]
18971c
-	    do
18971c
-		    wdtpdrv=$(< "$wdtppath/modalias")
18971c
-		    wdtpdrv=$(modprobe -R $wdtpdrv)
18971c
-		    instmods $wdtpdrv
18971c
-		    wdtcmdline="$wdtcmdline$(echo $wdtpdrv | tr " " ","),"
18971c
-		    wdtppath=$(readlink -f "$wdtppath/..")
18971c
-	    done
18971c
+    for _dir in /sys/class/watchdog/*; do
18971c
+        [[ -d "$_dir" ]] || continue
18971c
+        [[ -f "$_dir/state" ]] || continue
18971c
+        _active=$(< "$_dir/state")
18971c
+        ! [[ $hostonly ]] || [[ "$_active" =  "active" ]] || continue
18971c
+        # device/modalias will return driver of this device
18971c
+        _wdtdrv=$(< "$_dir/device/modalias")
18971c
+        # There can be more than one module represented by same
18971c
+        # modalias. Currently load all of them.
18971c
+        # TODO: Need to find a way to avoid any unwanted module
18971c
+        # represented by modalias
18971c
+        _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
18971c
+        if [[ $_wdtdrv ]]; then
18971c
+            instmods $_wdtdrv
18971c
+            for i in $_wdtdrv; do
18971c
+                _drivers[$i]=1
18971c
+            done
18971c
+        fi
18971c
+        # however in some cases, we also need to check that if there is
18971c
+        # a specific driver for the parent bus/device.  In such cases
18971c
+        # we also need to enable driver for parent bus/device.
18971c
+        _wdtppath=$(readlink -f "$_dir/device/..")
18971c
+        while [[ -d "$_wdtppath" ]] && [[ "$_wdtppath" != "/sys" ]]; do
18971c
+            _wdtppath=$(readlink -f "$_wdtppath/..")
18971c
+            [[ -f "$_wdtppath/modalias" ]] || continue
18971c
+
18971c
+            _wdtdrv=$(< "$_wdtppath/modalias")
18971c
+            _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
18971c
+            if [[ $_wdtdrv ]]; then
18971c
+                instmods $_wdtdrv
18971c
+                for i in $_wdtdrv; do
18971c
+                    _drivers[$i]=1
18971c
+                done
18971c
+            fi
18971c
+        done
18971c
     done
18971c
     # ensure that watchdog module is loaded as early as possible
18971c
-    [[ $wdtcmdline = "" ]] || echo "rd.driver.pre=$wdtcmdline" > ${initdir}/etc/cmdline.d/00-watchdog.conf
18971c
+    _alldrivers="${!_drivers[*]}"
18971c
+    [[ $_alldrivers ]] && echo "rd.driver.pre=${_alldrivers// /,}" > ${initdir}/etc/cmdline.d/00-watchdog.conf
18971c
 }