[dahdi-commits] dahdi/tools.git branch "master" updated.
SVN commits to the DAHDI project
dahdi-commits at lists.digium.com
Thu Jan 23 04:36:09 CST 2014
branch "master" has been updated
via c3b020a15567dcf2d0136332f34aa2a444dfc124 (commit)
via 7f826a7d3540ab99c6440bf094c39cbf26042b87 (commit)
via cdedf024ae0984d4b0dddc76bcdb5e29f21b3040 (commit)
from a6203e151f79e9e8a7e95067dc356996b4c82340 (commit)
Summary of changes:
Makefile | 15 ++-
dahdi_span_config | 113 --------------------
dahdi_waitfor_span_assignments | 73 +++++++++++++
doc/dahdi_waitfor_span_assignments.8 | 49 +++++++++
dahdi_handle_device => hotplug/dahdi_handle_device | 58 +++++-----
hotplug/dahdi_span_config | 83 ++++++++++++++
hotplug/handle_device.d/10-span-types | 5 +
hotplug/handle_device.d/20-span-assignments | 8 ++
hotplug/span_config.d/10-dahdi-cfg | 28 +++++
hotplug/span_config.d/20-fxotune | 12 +++
hotplug/span_config.d/50-asterisk | 9 ++
11 files changed, 309 insertions(+), 144 deletions(-)
delete mode 100755 dahdi_span_config
create mode 100755 dahdi_waitfor_span_assignments
create mode 100644 doc/dahdi_waitfor_span_assignments.8
rename dahdi_handle_device => hotplug/dahdi_handle_device (60%)
create mode 100755 hotplug/dahdi_span_config
create mode 100755 hotplug/handle_device.d/10-span-types
create mode 100755 hotplug/handle_device.d/20-span-assignments
create mode 100755 hotplug/span_config.d/10-dahdi-cfg
create mode 100755 hotplug/span_config.d/20-fxotune
create mode 100755 hotplug/span_config.d/50-asterisk
- Log -----------------------------------------------------------------
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>
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.
+
commit 7f826a7d3540ab99c6440bf094c39cbf26042b87
Author: Oron Peled <oron.peled at xorcom.com>
Date: Thu Jan 16 12:31:17 2014 +0200
hotplug modularization: split logic to scriptlets
* Device related operations are ordered in /usr/share/dahdi/handle_device.d/
* Span related operations are ordered in /usr/share/dahdi/span_config.d/
* In the future, span_config.d/50-asterisk should be moved to Asterisk.
Signed-off-by: Tzafrir Cohen <tzafrir.cohen at xorcom.com>
Acked-by: Russ Meyerriecks <rmeyerriecks at digium.com>
diff --git a/Makefile b/Makefile
index f3ce6df..45fc7b7 100644
--- a/Makefile
+++ b/Makefile
@@ -103,7 +103,15 @@ endif
ifeq (1,$(PBX_HDLC))
BINS += sethdlc
endif
-ASSIGNED_DATA_SCRIPTS:=dahdi_handle_device dahdi_span_config
+ASSIGNED_DATA_SCRIPTS:=\
+ dahdi_handle_device \
+ dahdi_span_config \
+ span_config.d/10-dahdi-cfg \
+ span_config.d/20-fxotune \
+ span_config.d/50-asterisk \
+ handle_device.d/10-span-types \
+ handle_device.d/20-span-assignments
+
ASSIGNED_UTILS:=dahdi_span_assignments dahdi_span_types
ASSIGNED_CONF:=assigned-spans.conf.sample span-types.conf.sample
diff --git a/hotplug/dahdi_handle_device b/hotplug/dahdi_handle_device
index 34af0c3..c67fce9 100755
--- a/hotplug/dahdi_handle_device
+++ b/hotplug/dahdi_handle_device
@@ -20,6 +20,7 @@ exec 2> /dev/null
# Our directory in the beginning, so we can use local lab setup
PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin"
+export PATH
set -e
@@ -35,43 +36,44 @@ if [ "$DAHDI_UDEV_DISABLE_DEVICES" = 'yes' ]; then
exit 0
fi
+# Check if we can safely do our job
+if [ ! -f /sys/module/dahdi/parameters/auto_assign_spans ]; then
+ echo "Old driver (no auto_assign_spans parameter). Skip $DEVPATH" | $LOGGER
+ exit 0
+fi
+if [ `cat /sys/module/dahdi/parameters/auto_assign_spans` -eq 1 ]; then
+ echo "auto_assign_spans=1. Skip $DEVPATH" | $LOGGER
+ exit 0
+fi
+
# Can we pass a different value so we can use
# alternate (testing) configuration?
# Meanwhile, make it hard-coded.
DAHDICONFDIR='/etc/dahdi'
export DAHDICONFDIR
+run_parts() {
+ # Have our internal "run-parts" (adapted from Fedora),
+ # as implementations differ
+ for i in `LC_ALL=C; ls -d $dir/handle_device.d/*[!~,] 2>/dev/null` ; do
+ [ -d "$i" ] && continue
+ [ ! -x "$i" ] && continue
+ # Don't run *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} files
+ case "$i" in
+ *.cfsaved|*.rpmsave|*.rpmorig|*.rpmnew|*.swp|*,v)
+ continue
+ ;;
+ esac
+ echo "D: Running '$i'"
+ "$i"
+ done
+}
+
case "$ACTION" in
add)
echo "$ACTION: $DEVPATH" | $LOGGER
-
- # Check if we can safely do our job
- if [ ! -f /sys/module/dahdi/parameters/auto_assign_spans ]; then
- if [ -f /sys/module/dahdi ]; then
- $LOGGER "Old driver (no auto_assign_spans parameter). Skip $DEVPATH"
- exit 0
- fi
- fi
- if [ `cat /sys/module/dahdi/parameters/auto_assign_spans` -eq 1 ]; then
- echo "auto_assign_spans=1. Skip $DEVPATH" | $LOGGER
- exit 0
- fi
-
- # Can have alternate dahdi configuration directory for debugging
- # export DAHDICONFDIR="/tmp/xortel/dahdi"
-
- # Don't block udev for too long
- (
- if [ -r "$DAHDICONFDIR/span-types.conf" ]; then
- dahdi_span_types set "/sys$DEVPATH"
- fi
- if [ -r "$DAHDICONFDIR/assigned-spans.conf" ]; then
- dahdi_span_assignments add "/sys$DEVPATH"
- else
- # No configuration. No order guaranteed
- dahdi_span_assignments auto "/sys$DEVPATH"
- fi
- ) 2>&1 < /dev/null | $LOGGER &
+ # Background run -- don't block udev
+ run_parts 2>&1 < /dev/null | $LOGGER &
;;
remove)
# Nothing to do yet...
diff --git a/hotplug/dahdi_span_config b/hotplug/dahdi_span_config
index bde20fb..0f610fb 100755
--- a/hotplug/dahdi_span_config
+++ b/hotplug/dahdi_span_config
@@ -20,6 +20,7 @@ exec 2> /dev/null
# Our directory in the beginning, so we can use local lab setup
PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin"
+export PATH
set -e
@@ -41,66 +42,35 @@ fi
DAHDICONFDIR='/etc/dahdi'
export DAHDICONFDIR
-run_dahdi_cfg() {
- echo "dahdi_cfg: span $spanno <$basechan-$endchan> ($DEVPATH)"
- dahdi_cfg -c "$cfg_file" -S "$spanno" -C "$basechan-$endchan"
-}
-
-configure_span() {
- span_devpath="$1"
- # Sanity check
- checkit=`"dahdi_cfg" --help 2>&1 | grep -- '-S' | wc -l`
- if [ "$checkit" != 1 ]; then
- echo "Bad dahdi_cfg (no -S support). Skipping"
- exit 0
- fi
-
- # Set variables
- spanno=`echo "$span_devpath" | sed 's,.*/span-,,'`
- basechan=`cat "$span_devpath/basechan"`
- channels=`cat "$span_devpath/channels"`
- endchan=`expr "$basechan" + "$channels" - 1`
-
- # Configure DAHDI
- cfg_file="$DAHDICONFDIR/system.conf"
- if [ -r "$cfg_file" ]; then
- run_dahdi_cfg
- else
- echo "Using auto-generated config for dahdi_cfg"
- cfg_file='-'
- DAHDI_CONF_FILE="$cfg_file" dahdi_genconf system | run_dahdi_cfg
- fi
- fxotune_cfg='/etc/fxotune.conf'
- if [ -r "$fxotune_cfg" ]; then
- echo "fxotune: span $spanno <$basechan-$endchan> ($DEVPATH)"
- fxotune -s -b "$basechan" -e "$endchan"
- fi
-
- # Add to asterisk
- asterisk -rx "dahdi create channels $basechan $endchan"
+run_parts() {
+ # Have our internal "run-parts" (adapted from Fedora),
+ # as implementations differ
+ for i in `LC_ALL=C; ls -d $dir/span_config.d/*[!~,] 2>/dev/null` ; do
+ [ -d "$i" ] && continue
+ [ ! -x "$i" ] && continue
+ # Don't run *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} files
+ case "$i" in
+ *.cfsaved|*.rpmsave|*.rpmorig|*.rpmnew|*.swp|*,v)
+ continue
+ ;;
+ esac
+ #echo "D: Running '$i'"
+ "$i"
+ done
}
case "$ACTION" in
add)
echo "$ACTION: $DEVPATH" | $LOGGER
-
- # Old driver. These scripts probably won't work anyway.
- if [ ! -f /sys/module/dahdi/parameters/auto_assign_spans ]; then
- if [ -f /sys/module/dahdi ]; then
- $LOGGER "Old driver (no auto_assign_spans parameter). Skip $DEVPATH"
- exit 0
- fi
- fi
-
- if [ $(cat /sys/module/dahdi/parameters/auto_assign_spans) -eq 1 ]; then
- $LOGGER "auto_assign_spans=1. Skip $DEVPATH"
- exit 0
- fi
-
- # Can have alternate dahdi configuration directory for debugging
- # export DAHDICONFDIR="/tmp/xortel/dahdi"
-
- configure_span "/sys$DEVPATH" 2>&1 | $LOGGER
+ # Set variables
+ span_devpath="/sys$DEVPATH"
+ SPANNO=`echo "$span_devpath" | sed 's,.*/span-,,'`
+ BASECHAN=`cat "$span_devpath/basechan"`
+ CHANNELS=`cat "$span_devpath/channels"`
+ ENDCHAN=`expr "$BASECHAN" + "$CHANNELS" - 1`
+ export SPANNO BASECHAN CHANNELS ENDCHAN
+ # Background run -- don't block udev
+ run_parts 2>&1 < /dev/null | $LOGGER &
;;
remove|online|offline)
# Nothing to do yet...
diff --git a/hotplug/handle_device.d/10-span-types b/hotplug/handle_device.d/10-span-types
new file mode 100755
index 0000000..d840c3d
--- /dev/null
+++ b/hotplug/handle_device.d/10-span-types
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+if [ -r "$DAHDICONFDIR/span-types.conf" ]; then
+ dahdi_span_types set "/sys$DEVPATH"
+fi
diff --git a/hotplug/handle_device.d/20-span-assignments b/hotplug/handle_device.d/20-span-assignments
new file mode 100755
index 0000000..f078aca
--- /dev/null
+++ b/hotplug/handle_device.d/20-span-assignments
@@ -0,0 +1,8 @@
+#! /bin/sh
+
+if [ -r "$DAHDICONFDIR/assigned-spans.conf" ]; then
+ dahdi_span_assignments add "/sys$DEVPATH"
+else
+ # No configuration. No order guaranteed
+ dahdi_span_assignments auto "/sys$DEVPATH"
+fi
diff --git a/hotplug/span_config.d/10-dahdi-cfg b/hotplug/span_config.d/10-dahdi-cfg
new file mode 100755
index 0000000..9ca2efe
--- /dev/null
+++ b/hotplug/span_config.d/10-dahdi-cfg
@@ -0,0 +1,28 @@
+#! /bin/sh
+
+if [ "$ACTION" != 'add' ]; then
+ # Nothing to do here
+ exit 0
+fi
+
+# Sanity check
+checkit=`"dahdi_cfg" --help 2>&1 | grep -- '-S' | wc -l`
+if [ "$checkit" != 1 ]; then
+ echo "Bad dahdi_cfg (no -S support). Skipping"
+ exit 0
+fi
+
+run_dahdi_cfg() {
+ echo "dahdi_cfg: span $SPANNO <$BASECHAN-$ENDCHAN> ($DEVPATH)"
+ dahdi_cfg -c "$cfg_file" -S "$SPANNO" -C "$BASECHAN-$ENDCHAN"
+}
+
+# Configure DAHDI
+cfg_file="$DAHDICONFDIR/system.conf"
+if [ -r "$cfg_file" ]; then
+ run_dahdi_cfg
+else
+ echo "Using auto-generated config for dahdi_cfg"
+ cfg_file='-'
+ DAHDI_CONF_FILE="$cfg_file" dahdi_genconf system | run_dahdi_cfg
+fi
diff --git a/hotplug/span_config.d/20-fxotune b/hotplug/span_config.d/20-fxotune
new file mode 100755
index 0000000..199c82c
--- /dev/null
+++ b/hotplug/span_config.d/20-fxotune
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+if [ "$ACTION" != 'add' ]; then
+ # Nothing to do here
+ exit 0
+fi
+
+fxotune_cfg='/etc/fxotune.conf'
+if [ -r "$fxotune_cfg" ]; then
+ echo "fxotune: span $SPANNO <$BASECHAN-$ENDCHAN> ($DEVPATH)"
+ fxotune -s -b "$BASECHAN" -e "$ENDCHAN"
+fi
diff --git a/hotplug/span_config.d/50-asterisk b/hotplug/span_config.d/50-asterisk
new file mode 100755
index 0000000..2e7adbd
--- /dev/null
+++ b/hotplug/span_config.d/50-asterisk
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+if [ "$ACTION" != 'add' ]; then
+ # Nothing to do here
+ exit 0
+fi
+
+# Add to asterisk
+asterisk -rx "dahdi create channels $BASECHAN $ENDCHAN"
commit cdedf024ae0984d4b0dddc76bcdb5e29f21b3040
Author: Oron Peled <oron.peled at xorcom.com>
Date: Thu Jan 16 12:29:04 2014 +0200
hotplug modularization: move sources to a subdir
Signed-off-by: Tzafrir Cohen <tzafrir.cohen at xorcom.com>
Acked-by: Russ Meyerriecks <rmeyerriecks at digium.com>
diff --git a/Makefile b/Makefile
index 144b292..f3ce6df 100644
--- a/Makefile
+++ b/Makefile
@@ -231,7 +231,7 @@ ifeq (,$(wildcard $(DESTDIR)$(CONFIG_FILE)))
$(INSTALL) -m 644 system.conf.sample $(DESTDIR)$(CONFIG_FILE)
endif
install -d $(DESTDIR)$(DATA_DIR)
- install $(ASSIGNED_DATA_SCRIPTS) $(DESTDIR)$(DATA_DIR)/
+ tar cf - -C hotplug $(ASSIGNED_DATA_SCRIPTS) | tar xf - -C $(DESTDIR)$(DATA_DIR)/
install $(ASSIGNED_UTILS) $(DESTDIR)/$(BIN_DIR)/
install -m 644 $(ASSIGNED_CONF) $(DESTDIR)/$(CONFIG_DIR)/
diff --git a/dahdi_handle_device b/hotplug/dahdi_handle_device
similarity index 100%
rename from dahdi_handle_device
rename to hotplug/dahdi_handle_device
diff --git a/dahdi_span_config b/hotplug/dahdi_span_config
similarity index 100%
rename from dahdi_span_config
rename to hotplug/dahdi_span_config
-----------------------------------------------------------------------
--
dahdi/tools.git
More information about the dahdi-commits
mailing list