blob: 9c8762bbbaac71ccf59cb44de85f0ca686dd7890 (
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#!/bin/sh
# $Id: watchdog-restart-20-modules.sh 460 2007-06-02 13:27:00Z zzam $
#
# Reload all loaded dvb modules
#
. /lib/gentoo/functions.sh
: ${DEBUG:=0}
debug_msg() {
[ "${DEBUG}" != "0" ] && einfo "DEBUG: $@"
}
do_unload_mod() {
local mod=${1}
modprobe -r ${mod}
}
rec_unload() {
local mod="${1}"
local mod_deps
local mod_usage
local mod_line
local mod_tried=""
# unload all modules depending on $mod
while true; do
mod_line=$(grep "^${mod} " /proc/modules)
if [ -z "$mod_line" ]; then
# module not loaded
return
fi
mod_deps=$(echo "$mod_line" | awk '{ gsub(","," ",$4); print $4 }')
if [ "${mod_deps}" = "-" ]; then
# no more users
einfo " unloading ${mod}"
if do_unload_mod ${mod}; then
MODULE_LIST="${mod} ${MODULE_LIST}"
else
ewarn "rmmod ${mod} failed"
return
fi
else
# module has more users
debug_msg "${mod} has these users: ${mod_deps}"
local dep
for dep in ${mod_deps}; do
if [ "${mod_tried}" = "${dep}" ]; then
ewarn "break infinite recursion at ${dep}"
return
fi
# try to unload each
rec_unload ${dep}
mod_tried=${dep}
done
fi
done
}
kill_dvb_video_users() {
[ -d /sys ] || return
debug_msg "Killing programms accessing video device of dvb cards"
local dev bname name
for dev in /sys/class/video4linux/video?; do
[ -f "${dev}/name" ] || continue
name=$(cat "${dev}/name")
[ "${name##*av7110}" = "${name}" ] && continue
bname=${dev##*/}
debug_msg " Killing users of device ${bname} (Name: ${name})"
fuser -s -k -TERM /dev/${bname}
done
}
do_unload_all() {
kill_dvb_video_users
einfo "Unloading DVB modules"
MODULE_LIST=""
local mod
local unload_mod_list="dvb_core"
for mod in ${unload_mod_list}; do
rec_unload ${mod}
done
}
do_load_all() {
einfo "Loading DVB modules"
local mod
for mod in ${MODULE_LIST}; do
einfo " Loading ${mod}"
modprobe ${mod}
done
}
show_help() {
echo "Usage:"
echo " $0 unload"
echo " $0 reload"
}
case $1 in
unload)
do_unload_all
;;
reload)
do_unload_all
do_load_all
;;
*)
show_help
exit 1
;;
esac
exit 0
|