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

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