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

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