summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2007-03-01 08:16:41 +0000
committertzafrir <tzafrir@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2007-03-01 08:16:41 +0000
commit13ac59fc2e0af198f15e5a8291bc3cbc6d22a711 (patch)
tree6beefe246829e3ed51d799ab4a9fb73ff234762a
parente3cb51a11c4af4cb7b2de0af1d8a719a033a7356 (diff)
Fixed module unloading in the zaptel init script.
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@2256 5390a7c7-147a-4af0-8ec9-7488f05a26cb
-rw-r--r--zaptel.init46
1 files changed, 27 insertions, 19 deletions
diff --git a/zaptel.init b/zaptel.init
index 268570e..2951554 100644
--- a/zaptel.init
+++ b/zaptel.init
@@ -37,11 +37,26 @@ if [ -z "${MODULES}" ]; then
MODULES="tor2 wct4xxp wct1xxp wcte11xp wcfxo wctdm wctdm24xxp"
fi
-RMODULES=""
-# Reverse list for un-loading; don't change
-for x in $MODULES; do
- RMODULES="$x $RMODULES"
-done
+# recursively unload a module and its dependencies, if possible.
+# where's modprobe -r when you need it?
+# inputs: module to unload.
+# returns: the result from
+unload_module() {
+ module="$1"
+ line=`lsmod 2>/dev/null | grep "^$1 "`
+ if [ "$line" = '' ]; then return; fi # module was not loaded
+
+ set -- $line
+ # $1: the original module, $2: size, $3: refcount, $4: deps list
+ mods=`echo $4 | tr , ' '`
+ for mod in $mods; do
+ # run in a subshell, so it won't step over our vars:
+ (unload_module $mod)
+ # TODO: the following is probably the error handling we want:
+ # if [ $? != 0 ]; then return 1; fi
+ done
+ rmmod $module
+}
# Check that telephony is up.
[ "${TELEPHONY}" = "yes" ] || exit 0
@@ -107,24 +122,17 @@ case "$1" in
stop)
# Unload drivers
echo -n "Unloading zaptel hardware drivers:"
- for x in $RMODULES; do
- if rmmod ${x} >& /dev/null; then
- echo -n " $x"
- fi
- done
- echo "."
-
- if [ $system = debian ]; then
- echo -n "Removing zaptel module: "
- rmmod zaptel >& /dev/null && echo -n "done"
- echo "."
- elif [ $system = redhat ]; then
- action "Removing zaptel module: " rmmod zaptel
- fi
+ unload_module zaptel
RETVAL=$?
+ echo "."
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
;;
+ unload)
+ # We don't have zaptel helper, so let's not replicate too much code:
+ # allow others to use the unload command.
+ unload zaptel
+ ;;
restart)
$0 stop
$0 start