]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
Support old version of module-init-tools
authorAmadeusz Żołnowski <aidecoe@aidecoe.name>
Wed, 9 Jun 2010 08:36:05 +0000 (10:36 +0200)
committerHarald Hoyer <harald@redhat.com>
Wed, 9 Jun 2010 08:46:38 +0000 (10:46 +0200)
modprobe included in version prior to 3.7 of module-init-tools doesn't
have -d | --dirname option which allows to give a prefix other than
'/' for kernel modules path. Dracut assumes existence of that
option and uses it even with default '/'. The patch passes -d option
only if it's different from default and also checks module-init-tools
version if user changes the prefix by --kmoddir Dracut option.

dracut
dracut-functions

diff --git a/dracut b/dracut
index 35be7eb259381bf6a9f8e27278e5029b03541c15..139d0e049b9d7c692bea79257aa67f7f337d04b5 100755 (executable)
--- a/dracut
+++ b/dracut
@@ -183,7 +183,13 @@ esac
 abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
 
 srcmods="/lib/modules/$kernel/"
-[[ $drivers_dir ]] && srcmods="$drivers_dir"
+[[ $drivers_dir ]] && {
+    if verlt $(modprobe --version | cut -d' ' -f3) 3.7; then
+        derror 'To use --kmoddir option module-init-tools >= 3.7 is required.'
+        exit 1
+    fi
+    srcmods="$drivers_dir"
+}
 export srcmods
 
 if [[ -f $outfile && ! $force ]]; then
index a76cc22953a2053d5fe94a12781463400c7365ec..fbac28298039742f0ce7607155ebc0eab42f4c3f 100755 (executable)
@@ -24,6 +24,39 @@ IF_dynamic=""
 # Generic substring function.  If $2 is in $1, return 0.
 strstr() { [[ $1 =~ $2 ]]; }
 
+# Version comparision function.  Returns result similar to C strcmp,
+# but instead of -1 is 2.  Function assumes version scheme like does
+# Linux kernel.
+vercmp() {
+    local n1 n2 i=1
+
+    while true
+    do
+        n1=$(echo $1 | cut -d'.' -f$i)
+        n2=$(echo $2 | cut -d'.' -f$i)
+
+        [[ ! $n1 && ! $n2 ]] && return 0
+        [[ $n1 -lt $n2 ]] && return 2
+        [[ $n1 -gt $n2 ]] && return 1
+
+        ((i++))
+    done
+}
+
+# Variation of version comparision function.  If $1 >= $2, return 0.
+verge() {
+    vercmp $1 $2
+
+    [[ $? = 0 || $? = 1 ]]
+}
+
+# Variation of version comparision function.  If $1 < $2, return 0.
+verlt() {
+    vercmp $1 $2
+
+    [[ $? = 2 ]]
+}
+
 # Log initrd creation.
 if ! [[ $dracutlogfile ]]; then
     [[ $dracutbasedir = /usr/share/dracut ]] && \
@@ -487,7 +520,7 @@ filter_kernel_modules () (
 # install kernel modules along with all their dependencies.
 instmods() {
     [[ $no_kernel = yes ]] && return
-    local mod mpargs modpath modname cmd
+    local mod mpargs modpath modname cmd moddirname
     while (($# > 0)); do
        mod=${1%.ko*}
        case $mod in
@@ -519,10 +552,17 @@ instmods() {
                ! echo $add_drivers | grep -qe "\<${mod}\>" &&  {
                    shift; continue; 
                }
+
+               # We use '-d' option in modprobe only if modules prefix path
+               # differs from default '/'.  This allows us to use Dracut with
+               # old version of modprobe which doesn't have '-d' option.
+               moddirname=${srcmods%%/lib/modules/*}
+               [[ -n ${moddirname} ]] && moddirname="-d ${moddirname}/"
+
                # ok, load the module, all its dependencies, and any firmware
                # it may require
                for_each_kmod_dep install_kmod_with_fw $mod \
-                   --set-version $kernel -d ${srcmods%%/lib/modules/*}/
+                   --set-version $kernel ${moddirname}
                ;;
        esac      
        shift