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@xorcom.com>
Acked-by: Russ Meyerriecks <rmeyerriecks@digium.com>
This commit is contained in:
Oron Peled 2014-01-16 12:31:17 +02:00 committed by Tzafrir Cohen
parent cdedf024ae
commit 7f826a7d35
8 changed files with 126 additions and 84 deletions

View File

@ -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

View File

@ -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...

View File

@ -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...

View File

@ -0,0 +1,5 @@
#! /bin/sh
if [ -r "$DAHDICONFDIR/span-types.conf" ]; then
dahdi_span_types set "/sys$DEVPATH"
fi

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"