summaryrefslogtreecommitdiff
blob: 7516096e8457b280e7ece724608470a75941681a (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
61
62
63
64
65
66
67
68
#!/bin/sh

# Do not continue for non-modular kernel - Bug #168322
[ ! -f /proc/modules ] && exit 0

if [ -e /dev/.udev_populate ]; then
	# Enable verbose while called from udev-addon-start
	. /dev/.udev_populate

	if [ -c "${CONSOLE}" ]; then
		# redirect stdin/out/err
		exec <${CONSOLE} >${CONSOLE} 2>/${CONSOLE}
	fi
fi

. /etc/init.d/functions.sh

MODPROBE=/sbin/modprobe

# Create a lock file for the current module.
lock_modprobe() {
	[ -e /dev/.udev/ ] || return 0

	MODPROBE_LOCK="/dev/.udev/.lock-modprobe-${MODNAME}"

	retry=20
	while ! mkdir "$MODPROBE_LOCK" 2> /dev/null; do
		if [ $retry -eq 0 ]; then
			 ewarn "Could lock modprobe ${MODNAME}!"
			 return 1
		fi
		sleep 1
		retry=$(($retry - 1))
	done
	return 0
}

unlock_modprobe() {
	[ "$MODPROBE_LOCK" ] || return 0
	rmdir "$MODPROBE_LOCK" || true
}

MODLIST=$("${MODPROBE}" -q -i --show-depends "${@}" 2>/dev/null \
	| sed -e "s#^insmod /lib.*/\(.*\)\.ko.*#\1#g" -e 's|-|_|g')

# exit if you have no modules to load
[ -z "${MODLIST}" ] && exit 0
for m in ${MODLIST}; do
	MODNAME=$m
done

# check for blacklisting
if [ -f /etc/modprobe.conf ]; then
	if grep -q '^blacklist.*[[:space:]]'"${MODNAME}"'\([[:space:]]\|$\)' /etc/modprobe.conf; then
		# module blacklisted
		exit 0
	fi
fi

lock_modprobe
# check if loaded
if ! grep -q "^${MODNAME}[[:space:]]" /proc/modules; then
	# now do real loading
	einfo "  udev loading module ${MODNAME}"
	"${MODPROBE}" -q "${@}" >/dev/null 2>/dev/null
fi
unlock_modprobe