summaryrefslogtreecommitdiffstats
path: root/abs/core/udev/load-modules.sh
blob: 861b9422bc07f757e271763930874b93e3345a5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#! /bin/bash
# Implement blacklisting for udev-loaded modules

[ $# -ne 1 ] && exit 1

. /etc/rc.conf

# grab modules from rc.conf
BLACKLIST="${MOD_BLACKLIST[@]}"

if [ -f /proc/cmdline ]; then 
    for cmd in $(cat /proc/cmdline); do
        case $cmd in
            *=*) eval $cmd ;;
        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
for mod in ${MODULES[@]}; do
    if [ "${mod}" != "${mod#!}" ]; then
        BLACKLIST="$BLACKLIST ${mod#!}"
    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
    fi
    /sbin/modprobe $1
else
    #/usr/bin/logger -p info \
    echo \
    "udev load-modules: autoloading is disabled, not loading $1"
fi
# vim: set et ts=4: