[Pkg-voip-commits] [dahdi-tools] 166/285: new "dahdi_waitfor_span_assignments" tool

tzafrir at debian.org tzafrir at debian.org
Thu Jul 7 19:18:50 UTC 2016


This is an automated email from the git hooks/post-receive script.

tzafrir pushed a commit to branch master
in repository dahdi-tools.

commit c3b020a15567dcf2d0136332f34aa2a444dfc124
Author: Oron Peled <oron.peled at xorcom.com>
Date:   Thu Jan 16 08:03:22 2014 -0500

    new "dahdi_waitfor_span_assignments" tool
    
    * Allows waiting until all spans are "assigned" or "unassigned"
    * Current implementation use a polling loop with sleep
    * Future implementation may block on sysfs attribute
      (like waitfor_xpds is blocking on sysfs Astribanks attribute)
    
    Signed-off-by: Tzafrir Cohen <tzafrir.cohen at xorcom.com>
    Acked-by: Russ Meyerriecks <rmeyerriecks at digium.com>
---
 Makefile                             |  3 +-
 dahdi_waitfor_span_assignments       | 73 ++++++++++++++++++++++++++++++++++++
 doc/dahdi_waitfor_span_assignments.8 | 49 ++++++++++++++++++++++++
 3 files changed, 124 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 45fc7b7..09f42bc 100644
--- a/Makefile
+++ b/Makefile
@@ -112,7 +112,8 @@ ASSIGNED_DATA_SCRIPTS:=\
 	handle_device.d/10-span-types	\
 	handle_device.d/20-span-assignments
 
-ASSIGNED_UTILS:=dahdi_span_assignments dahdi_span_types
+ASSIGNED_UTILS:=dahdi_span_assignments dahdi_span_types \
+	dahdi_waitfor_span_assignments
 ASSIGNED_CONF:=assigned-spans.conf.sample span-types.conf.sample
 
 MAN_PAGES:= \
diff --git a/dahdi_waitfor_span_assignments b/dahdi_waitfor_span_assignments
new file mode 100755
index 0000000..1080d84
--- /dev/null
+++ b/dahdi_waitfor_span_assignments
@@ -0,0 +1,73 @@
+#! /bin/sh
+
+usage() {
+	echo >&2 "Usage: $0 {assigned|unassigned}"
+	echo >&2 "# wait until all spans known are assigned/unassigned"
+	exit 1
+}
+
+TIMEOUT=5	# How much time to wait for spans
+
+if [ "$#" -lt 1 ]; then
+	usage
+fi
+wanted_event="$1"
+shift
+
+case "$wanted_event" in
+assigned)
+	;;
+unassigned)
+	;;
+*)
+	usage
+	;;
+esac
+
+devbase='/sys/bus/dahdi_devices/devices'
+
+spans_of() {
+	dev="$1"
+	wc -l < "$dev/spantype"
+}
+
+assigned_spans_of() {
+	dev="$1"
+	ls -d "$dev/span-"* 2>/dev/null | wc -l
+}
+
+
+waitfor_span_assignments() {
+	wanted_state="$1"
+	device_list=`ls -d "$devbase/"* 2> /dev/null`
+	finished=''
+	count="$TIMEOUT"
+	echo -n "Waiting for spans to become $wanted_state: "
+	while [ "$count" -gt 0 ]; do
+		finished='yes'
+		for dev in $device_list
+		do
+			spans=`spans_of "$dev"`
+			assigned_spans=`assigned_spans_of "$dev"`
+			if [ "$wanted_state" = 'assigned' -a "$assigned_spans" -ne "$spans" ]; then
+				finished='no'
+			elif [ "$wanted_state" = 'unassigned' -a "$assigned_spans" -ne 0 ]; then
+				finished='no'
+			fi
+		done
+		if [ "$finished" = 'yes' ]; then
+			break
+		else
+			sleep 1
+			echo -n "."
+		fi
+		count=`expr "$count" - 1`
+	done
+	if [ "$finished" = 'yes' ]; then
+		echo "done"
+	else
+		echo "timeout"
+	fi
+}
+
+waitfor_span_assignments "$wanted_event"
diff --git a/doc/dahdi_waitfor_span_assignments.8 b/doc/dahdi_waitfor_span_assignments.8
new file mode 100644
index 0000000..6aaa0b9
--- /dev/null
+++ b/doc/dahdi_waitfor_span_assignments.8
@@ -0,0 +1,49 @@
+.TH "DAHDI_WAITFOR_SPAN_ASSIGNMENTS" "8" "22 Jan 2014" "" ""
+
+.SH NAME
+dahdi_waitfor_span_assignments \- wait for DAHDI spans to get (un)assigned
+.SH SYNOPSIS
+
+.B dahdi_span_assignments assigned
+
+.B dahdi_span_assignments unassigned
+
+.SH DESCRIPTION
+DAHDI spans get assigned / unassigned asynchronously.
+
+.B dahdi_span_assignments
+is a helper script that allows running commands after all the spans have
+been assigned or unassigned.
+
+It takes a single command: \fBassigned\fR or \fBunassigned\fR and waits
+(up until a timeout of 5 seconds) for all the DAHDI spans in the system
+to do so.
+
+Note that if the system has a span that will not get assigned
+automatically (e.g.: it's not in assigned\-spans.conf), this program
+does not know and will wait until a timeout.
+
+.SH EXAMPLES
+
+ modprobe wctdm24xxp
+ dahdi_waitfor_span_assignments assigned
+ do_something
+
+ dahdi_span_assignments add
+ dahdi_waitfor_span_assignments assigned
+ do_something_else
+
+ dahdi_span_assignments remove
+ dahdi_span_assignments unassigned
+ do_something_completely_different
+
+.SH SEE ALSO
+dahdi_span_assignments(8)
+
+.SH AUTHOR
+dahdi_waitfor_span_assignments was written by Oron Peled.  This manual
+page was written by Tzafrir Cohen. Permission is granted to copy,
+distribute and/or modify this document under the terms of the GNU
+General Public License, Version 2 any  later version published by the
+Free Software Foundation.
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/dahdi-tools.git



More information about the Pkg-voip-commits mailing list