Blame SOURCES/0535-dracut.sh-workaround-broken-read-from-proc-modules.patch

0903d0
From f264cfbe8a9fa36765c918db9d7074a89eedbcd6 Mon Sep 17 00:00:00 2001
be3c34
From: Lukas Nykryn <lnykryn@redhat.com>
be3c34
Date: Mon, 11 Jun 2018 11:07:59 +0200
be3c34
Subject: [PATCH] dracut.sh: workaround broken read from /proc/modules
be3c34
be3c34
RHEL-only (upstream is using libkmod)
be3c34
Resolves: #1578222
be3c34
---
be3c34
 dracut.sh | 21 +++++++++++++++++----
be3c34
 1 file changed, 17 insertions(+), 4 deletions(-)
be3c34
be3c34
diff --git a/dracut.sh b/dracut.sh
0903d0
index 873274c0..9dadece0 100755
be3c34
--- a/dracut.sh
be3c34
+++ b/dracut.sh
be3c34
@@ -1145,10 +1145,23 @@ if [[ $hostonly ]]; then
be3c34
 
be3c34
     # check /proc/modules
be3c34
     declare -A host_modules
be3c34
-    while read m rest; do
be3c34
-        [ -z "$m" ] && continue
be3c34
-        host_modules["$m"]=1
be3c34
-    done 
be3c34
+    declare new_module_found=1
be3c34
+    declare tmpmodules=$(mktemp --tmpdir="$TMPDIR/" -t proc_modules.XXXXXX)
be3c34
+    while [[ $new_module_found ]]; do
be3c34
+        new_module_found=
be3c34
+        sleep 0.1
be3c34
+        #reading from procfs can be broken, so copy the file elsewhere
be3c34
+        cp -f /proc/modules "$tmpmodules"
be3c34
+        while read m rest; do
be3c34
+            [ -z "$m" ] && continue
be3c34
+            [[ ${host_modules["$m"]} ]] && continue
be3c34
+            host_modules["$m"]=1
be3c34
+            new_module_found=1
be3c34
+        done < "$tmpmodules"
be3c34
+    done
be3c34
+    rm "$tmpmodules"
be3c34
+    unset new_module_found
be3c34
+    unset tmpmodules
be3c34
 fi
be3c34
 
be3c34
 unset m