2 # Implement blacklisting for udev-loaded modules
8 # grab modules from rc.conf
9 BLACKLIST
="${MOD_BLACKLIST[@]}"
10 MODPROBE
="/sbin/modprobe"
11 LOGGER
="/usr/bin/logger"
12 RESOLVEALIAS
="/bin/resolve-modalias"
13 USEBLACKLIST
="--use-blacklist"
15 if [ -f /proc
/cmdline
]; then
16 for cmd
in $
(cat /proc
/cmdline
); do
18 disablemodules
=*) eval $cmd ;;
19 load_modules
=off
) exit ;;
22 #parse cmdline entries of the form "disablemodules=x,y,z"
23 if [ -n "$disablemodules" ]; then
24 BLACKLIST
="$BLACKLIST $(echo $disablemodules | sed 's|,| |g')"
28 #MODULES entries in rc.conf that begin with ! are blacklisted
29 for mod
in ${MODULES[@]}; do
30 if [ "${mod}" != "${mod#!}" ]; then
31 BLACKLIST
="$BLACKLIST ${mod#!}"
35 if [ "$MOD_AUTOLOAD" = "yes" -o "$MOD_AUTOLOAD" = "YES" ]; then
36 if [ -n "${BLACKLIST}" ]; then
37 # If an alias name is on the blacklist, load no modules for this device
38 if echo "${BLACKLIST}" |
/bin
/grep -q -e " $1 " -e "^$1 " -e " $1\$"; then
39 $LOGGER -p info
-t "$(basename $0)" "Not loading module alias '$1' because it is blacklisted"
42 #sanitize the blacklist
43 BLACKLIST
="$(echo "$BLACKLIST" | sed -e 's|-|_|g')"
44 # Try to find all modules for the alias
45 mods
=$
($RESOLVEALIAS /lib
/modules
/$
(uname
-r)/modules.
alias $1)
46 # If no modules could be found, try if the alias name is a module name
47 # In that case, omit the --use-blacklist parameter to imitate normal modprobe behaviour
48 [ -z "${mods}" ] && $MODPROBE -qni $1 && mods
="$1" && USEBLACKLIST
=""
49 [ -z "${mods}" ] && $LOGGER -p info
-t "$(basename $0)" "'$1' is not a valid module or alias name"
50 for mod
in ${mods}; do
51 # Find the module and all its dependencies
52 deps
="$($MODPROBE -i --show-depends ${mod})"
53 [ $?
-ne 0 ] && continue
55 #sanitize the module names
56 deps
="$(echo "$deps" | sed \
57 -e "s
#^insmod /lib.*/\(.*\)\.ko.*#\1#g" \
60 # If the module or any of its dependencies is blacklisted, don't load it
62 if echo "${BLACKLIST}" | /bin/grep -q -e " ${dep} " -e "^${dep} " -e " ${dep}\$
"; then
63 if [ "${dep}" = "${mod}" ]; then
64 $LOGGER -p info -t "$
(basename $0)" "Not loading module
'${mod}' for alias '$1' because it is blacklisted
"
66 $LOGGER -p info -t "$
(basename $0)" "Not loading module
'${mod}' for alias '$1' because its dependency
'${dep}' is blacklisted
"
71 # modprobe usually uses the "blacklist
" statements from modprobe.conf only to blacklist all aliases
72 # of a module, but not the module itself. We use --use-blacklist here so that modprobe also blacklists
73 # module names if we resolved alias names manually above
74 $MODPROBE $USEBLACKLIST ${mod}