[zaptel-commits] tzafrir: trunk r1293 - in /trunk/xpp: card_fxs.c utils/genzaptelconf

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Wed Aug 9 20:56:44 MST 2006


Author: tzafrir
Date: Wed Aug  9 22:56:43 2006
New Revision: 1293

URL: http://svn.digium.com/view/zaptel?rev=1293&view=rev
Log:
* A delay loop waiting for a slow udev to generate /dev/zap/ctl
* Work around stupid call to ztcfg on modprobe (as inserted by zaptel 
  install script)
* -M now edits /etc/sysconfig/zaptel if it find that file and not /etc/modules
* editing of /etc/sysconfig/zaptel: remove all lines that begin with 
  MODULES=, and add MODULES="list of modules" to the end.

Modified:
    trunk/xpp/card_fxs.c
    trunk/xpp/utils/genzaptelconf

Modified: trunk/xpp/card_fxs.c
URL: http://svn.digium.com/view/zaptel/trunk/xpp/card_fxs.c?rev=1293&r1=1292&r2=1293&view=diff
==============================================================================
--- trunk/xpp/card_fxs.c (original)
+++ trunk/xpp/card_fxs.c Wed Aug  9 22:56:43 2006
@@ -846,7 +846,6 @@
 			}
 		}
 	}
-
 out:
 	/* Update /proc info only if reply relate to the last slic read request */
 	if(priv->requested_reply.indirect == info->indirect &&

Modified: trunk/xpp/utils/genzaptelconf
URL: http://svn.digium.com/view/zaptel/trunk/xpp/utils/genzaptelconf?rev=1293&r1=1292&r2=1293&view=diff
==============================================================================
--- trunk/xpp/utils/genzaptelconf (original)
+++ trunk/xpp/utils/genzaptelconf Wed Aug  9 22:56:43 2006
@@ -87,10 +87,12 @@
 set_immediate=yes
 
 ZAPCONF_FILE=/etc/zaptel.conf
+ZAPCONF_FILE_SYSTEM=$ZAPCONF_FILE
 ZAPATA_FILE=/etc/asterisk/zapata-channels.conf
 ZAPTEL_BOOT_DEBIAN=${ZAPTEL_BOOT_DEBIAN:-/etc/default/zaptel}
 ZAPTEL_BOOT_FEDORA=${ZAPTEL_BOOT_FEDORA:-/etc/sysconfig/zaptel}
 MODLIST_FILE=/etc/modules
+MODLIST_FILE_FEDORA=/etc/sysconfig/zaptel
 exten_base_dir=/etc/asterisk/extensions-phones.d
 exten_defs_file=/etc/asterisk/extensions-defs.conf
 ZTCFG=/sbin/ztcfg
@@ -139,6 +141,25 @@
 }
 
 run_ztcfg() {
+  # Wait for udev to generate /dev/zap/ctl, if needed:
+	if [ ! -c /dev/zap/ctl ] && grep -q zaptel /proc/modules ; then
+	  say "Waiting for /dev/zap/ctl to be generated"
+	  devzap_found=0
+		devzap_timeout=5
+	  for i in `seq $devzap_timeout`; do
+			sleep 1
+			if [ -c /dev/zap/ctl ]; then
+			  devzap_found=1
+				break
+			fi
+		done
+		if [ "$devzap_found" != 1 ]; then
+		  say "Still no /dev/zap/ctl after $devzap_timeout seconds."
+		  echo >&2 "No /dev/zap/ctl: cannot run ztcfg. Aborting."
+		fi
+	fi
+	
+	# Run ztcfg itself
 	if [ "$verbose" = no ]; then
 		$ztcfg_cmd "$@"
 	else
@@ -147,7 +168,8 @@
 	fi
 }
 
-update_module_list() {
+update_module_list_debian() {
+	say "Updating Debian modules list $MODLIST_FILE."
 	del_args=`for i in $ALL_MODULES ztdummy
 	do
 		echo "$i" | sed s:.\*:-e\ '/^&/d':
@@ -162,6 +184,22 @@
 	do
 		echo "$i"
 	done >> "$MODLIST_FILE"
+}
+
+update_module_list_fedora() {
+	say "Updating modules list in zaptel init config $MODLIST_FILE_FEDORA."
+	sed -i.bak -e '/^MODULES=/d' "$MODLIST_FILE_FEDORA"
+	echo "MODULES=\"$*\"" >> "$MODLIST_FILE_FEDORA"
+}
+
+update_module_list() {
+  if   [ -f "$MODLIST_FILE" ]; then
+	  update_module_list_debian "$@"
+	elif [ -f "$MODLIST_FILE_FEDORA" ]; then
+	  update_module_list_fedora "$@"
+	else
+	  die "Can't find a modules list to update. Tried: $MODLIST_FILE, $MODLIST_FILE_FEDORA. Aborting"
+	fi
 }
 
 update_extensions_defs() {
@@ -489,21 +527,46 @@
 
 detect() {
 	unload_modules
+	temporary_zapconf save
 	load_modules
+	temporary_zapconf restore
 	modlist="$probed_modules"
-	#for i in $ALL_MODULES
-	#do
-	#	if lsmod | grep "^$i  *" > /dev/null; then
-	#		modlist="$modlist $i"
-	#	fi
-	#done
 	modlist="$(echo $modlist)"		# clean spaces
 	if [ "$do_module_list" = yes ]
 	then
-		say "Updating '${MODLIST_FILE}'"
 		update_module_list "$modlist"
 	fi
 	if echo $modlist | grep -q xpp_usb; then wait_for_xpp; fi
+}
+
+# The module configuration generated by zaptel includes a totally useless 
+# automatic run of ztcfg after modules loading. As a workaround for that, 
+# we provide an empty zaptel.conf temporarily.
+# 
+# At hardware detection time we shouldn't really touch zaptel.conf . So we 
+# must keep a copy of it somewhere.
+#
+# I use ZAPCONF_FILE_SYSTEM rather than ZAPCONF_FILE, as the bogus modprobe 
+# entries will not be initiated by us.
+#
+# ZAPCONF_FILE_TMP is a "global", as it needs to be preserved between the
+# call to 'save' and to 'restore'
+ZAPCONF_FILE_TMP=
+temporary_zapconf() {
+  case "$1" in
+	save)
+	  say "Temporarily moving zaptel.conf aside to work around broken modprobe.conf"
+		ZAPCONF_FILE_TMP=`mktemp -t zaptel.conf-XXXXXX` || die "Error creating temporary zaptel.conf"
+		cp -a $ZAPCONF_FILE_SYSTEM $ZAPCONF_FILE_TMP
+		echo -n >$ZAPCONF_FILE_SYSTEM
+		;;
+	restore)
+		# restore original zaptel.conf:
+		if [ "$ZAPCONF_FILE_TMP" = '' ]; then return; fi
+		mv $ZAPCONF_FILE_TMP $ZAPCONF_FILE_SYSTEM
+		ZAPCONF_FILE_TMP=''
+		;;
+	esac
 }
 
 # TODO: kill this function. It is now unreferenced from anywhere.



More information about the zaptel-commits mailing list