[dahdi-commits] dahdi/linux.git branch "master" updated.

SVN commits to the DAHDI project dahdi-commits at lists.digium.com
Thu Nov 5 02:11:27 CST 2015


branch "master" has been updated
       via  8d1f17fc44e7191b58c20024b33f9e18e0aee83a (commit)
      from  404a67d089736c8cf13f9446f74d6fc67b7725c9 (commit)

Summary of changes:
 dahdi-modules |   72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100755 dahdi-modules


- Log -----------------------------------------------------------------
commit 8d1f17fc44e7191b58c20024b33f9e18e0aee83a
Author: Tzafrir Cohen <tzafrir.cohen at xorcom.com>
Date:   Mon Nov 2 18:11:09 2015 +0200

    dahdi-modules: load and unloads the modules
    
    A script that performs the module loading / unloading instead of the
    init script.
    
    Other functionality of the init script is performed by udev hooks. But
    manual initiation of modules loading or unloading is still needed on
    several occasions.
    
    This script should help enable the removal of the init script from the
    DAHDI package.
    
    Signed-off-by: Tzafrir Cohen <tzafrir.cohen at xorcom.com>

diff --git a/dahdi-modules b/dahdi-modules
new file mode 100755
index 0000000..230cd50
--- /dev/null
+++ b/dahdi-modules
@@ -0,0 +1,72 @@
+#!/bin/sh
+
+MODULES="dahdi"
+DAHDI_MODULES_FILE="/etc/dahdi/modules"
+
+usage() {
+	cat <<EOF
+$0: loads / unloads DAHDI kernel modules
+
+Usage: $0 <load|unload>
+
+* load: Loads all modules listed in /etc/dahdi/modules (one per line)
+* unload: Unloads the DAHDI modules (all the modules that are dependencies
+  of $MODULES).
+EOF
+}
+
+# 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 , ' '`
+	ec_modules=""
+	# xpp_usb keeps the xpds below busy if an xpp hardware is
+	# connected. Hence must be removed before them:
+	case "$module" in xpd_*) mods="xpp_usb $mods";; esac
+
+	for mod in $mods; do
+		case "$mod" in
+		dahdi_echocan_*)
+			ec_modules="$mod $ec_modules"
+			;;
+		*)
+			# run in a subshell, so it won't step over our vars:
+			(unload_module $mod)
+			;;
+		esac
+	done
+	# Now that all the other dependencies are unloaded, we can unload the
+	# dahdi_echocan modules.  The drivers that register spans may keep
+	# references on the echocan modules before they are unloaded.
+	for mod in $ec_modules; do
+		(unload_module $mod)
+	done
+	rmmod $module
+}
+
+unload_modules() {
+	for module in "$@"; do
+		unload_module $module
+	done
+}
+
+load_modules() {
+	modules=`sed -e 's/#.*$//' $DAHDI_MODULES_FILE 2>/dev/null`
+	for line in $modules; do
+		modprobe $line
+	done
+}
+
+case "$1" in
+	load) load_modules "$@";;
+	unload) unload_modules $MODULES;;
+	*) usage;;
+esac

-----------------------------------------------------------------------


-- 
dahdi/linux.git



More information about the dahdi-commits mailing list