summaryrefslogtreecommitdiffstats
path: root/abs/core/udev/load-modules.sh
diff options
context:
space:
mode:
authorCecil Hugh Watson <knoppmyth@gmail.com>2009-09-26 01:57:08 (GMT)
committerCecil Hugh Watson <knoppmyth@gmail.com>2009-09-26 01:57:08 (GMT)
commit7b29169fff9e7c624890c5edffe85def8a293136 (patch)
tree47753889faa3a2063b66d1c7e7681e703eb1b39a /abs/core/udev/load-modules.sh
parentc491dea779dac29afff3578bf8245943817c2339 (diff)
downloadlinhes_pkgbuild-7b29169fff9e7c624890c5edffe85def8a293136.zip
linhes_pkgbuild-7b29169fff9e7c624890c5edffe85def8a293136.tar.gz
linhes_pkgbuild-7b29169fff9e7c624890c5edffe85def8a293136.tar.bz2
LinHES 6.01.00
Diffstat (limited to 'abs/core/udev/load-modules.sh')
-rwxr-xr-xabs/core/udev/load-modules.sh78
1 files changed, 49 insertions, 29 deletions
diff --git a/abs/core/udev/load-modules.sh b/abs/core/udev/load-modules.sh
index 861b942..a42d376 100755
--- a/abs/core/udev/load-modules.sh
+++ b/abs/core/udev/load-modules.sh
@@ -1,4 +1,4 @@
-#! /bin/bash
+#!/bin/bash
# Implement blacklisting for udev-loaded modules
[ $# -ne 1 ] && exit 1
@@ -7,20 +7,22 @@
# grab modules from rc.conf
BLACKLIST="${MOD_BLACKLIST[@]}"
+MODPROBE="/sbin/modprobe"
+LOGGER="/usr/bin/logger"
+RESOLVEALIAS="/bin/resolve-modalias"
+USEBLACKLIST="--use-blacklist"
if [ -f /proc/cmdline ]; then
for cmd in $(cat /proc/cmdline); do
case $cmd in
- *=*) eval $cmd ;;
+ disablemodules=*) eval $cmd ;;
+ load_modules=off) exit ;;
esac
done
#parse cmdline entries of the form "disablemodules=x,y,z"
if [ -n "$disablemodules" ]; then
BLACKLIST="$BLACKLIST $(echo $disablemodules | sed 's|,| |g')"
fi
- if [ "$load_modules" == "off" ]; then
- MOD_AUTOLOAD="no"
- fi
fi
#MODULES entries in rc.conf that begin with ! are blacklisted
@@ -30,31 +32,49 @@ for mod in ${MODULES[@]}; do
fi
done
-
if [ "$MOD_AUTOLOAD" = "yes" -o "$MOD_AUTOLOAD" = "YES" ]; then
- if [ -n "$BLACKLIST" ]; then
- depmods="$(/sbin/modprobe -i --show-depends $1)"
- if [ $? -ne 0 ]; then
- /usr/bin/logger -p info "cannot find module $1"
- exit 1
- fi
-
- #sanitize our module names
- depmods="$(echo "$depmods" | sed \
- -e "s#^insmod /lib.*/\(.*\)\.ko.*#\1#g" \
- -e 's|-|_|g')"
-
- for mod in $depmods; do
- if echo $BLACKLIST | /bin/grep "\<$mod\>" 2>&1 >/dev/null; then
- /usr/bin/logger -p info "udev load-modules: $1 is blacklisted"
- exit 1
- fi
- done
+ if [ -n "${BLACKLIST}" ]; then
+ # If an alias name is on the blacklist, load no modules for this device
+ if echo "${BLACKLIST}" | /bin/grep -q -e " $1 " -e "^$1 " -e " $1\$"; then
+ $LOGGER -p info -t "$(basename $0)" "Not loading module alias '$1' because it is blacklisted"
+ exit
fi
- /sbin/modprobe $1
-else
- #/usr/bin/logger -p info \
- echo \
- "udev load-modules: autoloading is disabled, not loading $1"
+ #sanitize the blacklist
+ BLACKLIST="$(echo "$BLACKLIST" | sed -e 's|-|_|g')"
+ # Try to find all modules for the alias
+ mods=$($RESOLVEALIAS /lib/modules/$(uname -r)/modules.alias $1)
+ # If no modules could be found, try if the alias name is a module name
+ # In that case, omit the --use-blacklist parameter to imitate normal modprobe behaviour
+ [ -z "${mods}" ] && $MODPROBE -qni $1 && mods="$1" && USEBLACKLIST=""
+ [ -z "${mods}" ] && $LOGGER -p info -t "$(basename $0)" "'$1' is not a valid module or alias name"
+ for mod in ${mods}; do
+ # Find the module and all its dependencies
+ deps="$($MODPROBE -i --show-depends ${mod})"
+ [ $? -ne 0 ] && continue
+
+ #sanitize the module names
+ deps="$(echo "$deps" | sed \
+ -e "s#^insmod /lib.*/\(.*\)\.ko.*#\1#g" \
+ -e 's|-|_|g')"
+
+ # If the module or any of its dependencies is blacklisted, don't load it
+ for dep in $deps; do
+ if echo "${BLACKLIST}" | /bin/grep -q -e " ${dep} " -e "^${dep} " -e " ${dep}\$"; then
+ if [ "${dep}" = "${mod}" ]; then
+ $LOGGER -p info -t "$(basename $0)" "Not loading module '${mod}' for alias '$1' because it is blacklisted"
+ else
+ $LOGGER -p info -t "$(basename $0)" "Not loading module '${mod}' for alias '$1' because its dependency '${dep}' is blacklisted"
+ fi
+ continue 2
+ fi
+ done
+ # modprobe usually uses the "blacklist" statements from modprobe.conf only to blacklist all aliases
+ # of a module, but not the module itself. We use --use-blacklist here so that modprobe also blacklists
+ # module names if we resolved alias names manually above
+ $MODPROBE $USEBLACKLIST ${mod}
+ done
+ else
+ $MODPROBE $1
+ fi
fi
# vim: set et ts=4: