[svn-commits] tzafrir: branch 1.4 r2495 - /branches/1.4/zaptel.init

svn-commits at lists.digium.com svn-commits at lists.digium.com
Fri May 4 15:37:10 MST 2007


Author: tzafrir
Date: Fri May  4 17:37:10 2007
New Revision: 2495

URL: http://svn.digium.com/view/zaptel?view=rev&rev=2495
Log:
zaptel.init: use automative modules unloading (as in trunk and 1.2).

Modified:
    branches/1.4/zaptel.init

Modified: branches/1.4/zaptel.init
URL: http://svn.digium.com/view/zaptel/branches/1.4/zaptel.init?view=diff&rev=2495&r1=2494&r2=2495
==============================================================================
--- branches/1.4/zaptel.init (original)
+++ branches/1.4/zaptel.init Fri May  4 17:37:10 2007
@@ -39,11 +39,26 @@
 	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
+}
 
 # Wait for Astribank to initialize registers:
 wait_for_xpp() {
@@ -222,23 +237,16 @@
 	# Unload drivers
 	$ZTCFG -s
 	echo -n "Unloading zaptel hardware drivers:"
-	for x in $RMODULES; do 
-		if rmmod ${x} >& /dev/null; then
-			echo -n " $x"
-		fi
-	done
+  	unload_module zaptel
+	RETVAL=$?
 	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
-	RETVAL=$?
-
 	[ $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_module zaptel
 	;;
   restart)
 	$0 stop



More information about the svn-commits mailing list