Author: glen
Date: Tue Mar  3 11:34:15 2009
New Revision: 10169

Modified:
   geninitrd/trunk/geninitrd
Log:
- fix die() stderr redirection
- simplify find_depmod by using only modprobe
- skip errors logic moved to find_depmod from findmodule
- rename findmodule -> find_module for consistency

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd   (original)
+++ geninitrd/trunk/geninitrd   Tue Mar  3 11:34:15 2009
@@ -106,7 +106,7 @@
 # aborts program abnormally
 die() {
        local rc=${2:-1}
-       msg "ERROR: $1" 2>&2
+       msg "ERROR: $1" >&2
        exit $rc
 }
 
@@ -259,38 +259,44 @@
 # Finds module dependencies
 #
 # @param       $module
-# @param       $mode   [silent]
 #
-# Outputs each dependant module full path.
+# Outputs full path to module and it's dependencies
 find_depmod() {
        local module="$1"
-       local mode="$2"
+       local skiperrors=0
 
-       # backwards compatible, process $mode, parse aliases
-       local modfile=$(NEW_MODINFO=1 modinfo -k $kernel -n $module 2>/dev/null)
-       if [ ! -f "$modfile" ]; then
-               # module not found. try aliases!
-               local alias aliases=$(modprobe_conf | awk -vm="$module" '$1 == 
"alias" && $2 == m { print $3 }')
-               if [ "$aliases" ]; then
-                       for alias in $aliases; do
-                               debug "Try $alias alias for $module"
-                               find_depmod "$alias"
-                       done
+       # if module is prefixed with dash, we should ignore errors if the module
+       # can't be found.
+       if [ ${module#-} != $module ]; then
+               skiperrors=1
+               module=${module#-}
+       fi
+
+       # XXX: what's this?
+       if [ "$module" = "pluto" ] || [ "$module" = "fcal" ]; then
+               find_depmod fc4
+               find_depmod soc
+       fi
+
+       # This works when user has module-init-tools installed even on 2.4 
kernels
+       local modprobe
+       modprobe=$(modprobe --set-version $kernel --show-depends $module 
--ignore-install 2>&1)
+
+       if [ $? != 0 ]; then
+               if [ $skiperrors = 1 ]; then
                        return
                fi
+               echo >&2 "$modprobe"
 
-               if [ "$mode" != "silent" ]; then
-                       warn "$module: module not found for $kernel kernel"
-               fi
                if ! is_no "$EXIT_IF_MISSING"; then
-                       exit 1
-               else
-                       warn "If $module isn't compiled in kernel then this 
initrd may not start your system."
+                       die "$module: module not found for $kernel kernel"
                fi
+
+               warn "$module: module not found for $kernel kernel"
+               warn "If $module isn't compiled in kernel then this initrd may 
not start your system."
        fi
 
-       # This works when user has module-init-tools installed even on 2.4 
kernels
-       modprobe --set-version $kernel --show-depends $module --ignore-install 
| \
+       echo "$modprobe" | \
        while read insmod modpath options; do
                [ "$insmod" = "insmod" ] && echo $modpath
        done
@@ -306,35 +312,11 @@
        echo -n $(NEW_MODINFO=1 modinfo -k $kernel -F firmware $module 
2>/dev/null | xargs)
 }
 
-findmodule() {
-       local skiperrors=""
-       local modName=$1
-
-       if [ ${modName#-} != $modName ]; then
-               skiperrors=1
-               modName=${modName#-}
-       fi
-
-       # what's that?
-       if [ "$modName" = "pluto" ]; then
-               findmodule fc4
-               findmodule soc
-       fi
-       if [ "$modName" = "fcal" ]; then
-               findmodule fc4
-               findmodule socal
-       fi
-
-       local mod depmod
-       if [ "$skiperrors" = 1 ]; then
-               depmod=$(find_depmod $modName silent)
-       else
-               depmod=$(find_depmod $modName)
-               if [ $? != 0 ]; then
-                       exit 1
-               fi
-       fi
+# @param       $module
+find_module() {
+       local mod depmod module=$1
 
+       depmod=$(find_depmod $module) || exit 1
        for mod in $depmod; do
                mod=${mod#/lib/modules/$kernel/}
 
@@ -347,7 +329,7 @@
                        MODULES="$MODULES $mod"
 
                        # if we are adding uvesafb, we need v86d as well
-                       if [ "$modName" = "uvesafb" ]; then
+                       if [ "$module" = "uvesafb" ]; then
                                need_v86d=yes
                        fi                              
                fi
@@ -496,14 +478,14 @@
        if is_yes "$have_md"; then
                case "$raidlevel" in
                [01]|10)
-                       findmodule "raid$raidlevel"
+                       find_module "raid$raidlevel"
                        ;;
                [456])
-                       findmodule "-raid$raidlevel"
-                       findmodule "-raid456"
+                       find_module "-raid$raidlevel"
+                       find_module "-raid456"
                        ;;
                linear)
-                       findmodule "linear"
+                       find_module "linear"
                        ;;
                *)
                        warn "raid level $number (in mdadm config) not 
recognized"
@@ -531,13 +513,13 @@
                        for mod in $scsimodules; do
                                # for now allow scsi modules to come from 
anywhere. There are some
                                # RAID controllers with drivers in block
-                               findmodule "$mod"
+                               find_module "$mod"
                        done
                else
-                       findmodule "$n"
+                       find_module "$n"
                fi
        done
-       findmodule "-scsi_wait_scan"
+       find_module "-scsi_wait_scan"
 }
 
 # find modules for $devpath
@@ -577,11 +559,11 @@
                        [ -z "$NFS_ETH_MODULES" ] && 
NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
                        warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES 
is for this machine"
                        for m in $NFS_ETH_MODULES; do
-                               findmodule "$m"
+                               find_module "$m"
                        done
                fi
-               findmodule "-ipv4"
-               findmodule "nfs"
+               find_module "-ipv4"
+               find_module "nfs"
                have_nfs=yes
                warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when 
starting kernel"
                warn "or you will have problems like init(xx) being child 
process of swapper(1)."
@@ -618,33 +600,33 @@
        fi
 
        if [[ "$devpath" == /dev/rd/* ]]; then
-               findmodule "DAC960"
+               find_module "DAC960"
                rootdev_add=/dev/rd/
                return
        fi
 
        if [[ "$devpath" == /dev/ida/* ]]; then
-               findmodule "cpqarray"
+               find_module "cpqarray"
                rootdev_add=/dev/ida/
                return
        fi
 
        if [[ "$devpath" == /dev/cciss/* ]]; then
-               findmodule "cciss"
+               find_module "cciss"
                rootdev_add=/dev/cciss/
                return
        fi
 
        if [[ "$devpath" == /dev/ataraid/* ]]; then
                find_modules_ide
-               findmodule "ataraid"
+               find_module "ataraid"
                ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && 
! /^[\t ]*#/ { print $3; }')
                if [ -n "$ataraidmodules" ]; then
                        # FIXME: think about modules compiled in kernel
                        die "ataraid_hostadapter alias not defined in 
modprobe.conf! Please set it and run $PROGRAM again."
                fi
                for n in $ataraidmodules; do
-                       findmodule "$n"
+                       find_module "$n"
                done
                rootdev_add=/dev/ataraid/
                return
@@ -668,7 +650,7 @@
                loopFile="$(echo $line | awk '{print $5}')"
 
                BASICMODULES="$BASICMODULES -loop"
-               findmodule "-$loopFs"
+               find_module "-$loopFs"
                BASICMODULES="$BASICMODULES -${loopFs}"
                return
        fi
@@ -1531,11 +1513,11 @@
 cache_modprobe_conf
 
 for n in $PREMODS; do
-       findmodule "$n"
+       find_module "$n"
 done
 
 if [ "$FBMODULE" ]; then
-       findmodule "$FBMODULE"
+       find_module "$FBMODULE"
 fi
 
 # allow forcing loading SCSI and/or IDE modules
@@ -1556,18 +1538,18 @@
 
 find_modules_for_devpath "$rootdev"
 
-findmodule "-$rootFs"
+find_module "-$rootFs"
 
 for n in $BASICMODULES; do
-       findmodule "$n"
+       find_module "$n"
 done
 
 if is_yes "$USE_TUXONICE"; then
-       findmodule "-lzf"
+       find_module "-lzf"
 fi
 
 if is_yes "$FB_SPLASH"; then
-       findmodule "-evdev"
+       find_module "-evdev"
 fi
 
 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to