[arch-projects] [mkinitcpio] [PATCH 1/4] functions: refactor auto_modules

Dave Reisner d at falconindy.com
Fri Jun 3 14:13:06 EDT 2011


sort/uniq the modaliases files' contents, before passing _all_ of them
to modprobe -a. This cuts back on execution time as well as cleaning up
the resulting list of modules.

Signed-off-by: Dave Reisner <d at falconindy.com>
---
 functions |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/functions b/functions
index 4cd3136..a89fd92 100644
--- a/functions
+++ b/functions
@@ -41,16 +41,13 @@ in_array() {
 
 auto_modules ()
 {
-    aliases="$(find /sys/devices/ -name modalias -exec cat {} +)"
-    mods=""
-    for a in $aliases; do
-        m="$(modprobe --set-version ${KERNELVERSION} --resolve-alias "$a")"
-        [ -n "$m" ] && mods="$mods $m"
-    done
+    IFS=$'\n' read -rd '' -a mods < \
+        <(find /sys/devices -name modalias -exec sort -zu {} + |
+        xargs -0 modprobe --set-version "$KERNELVERSION" -aR |
+        sort -u)
 
-    echo "${mods}" | tr '-' '_'
-    [ -z "${mods}" ] && return 1
-    return 0
+    printf "%s\n" "${mods[@]//-/_}"
+    (( ${#mods[*]} ))
 }
 
 all_modules ()
-- 
1.7.5.4



More information about the arch-projects mailing list