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:
parent
cdedf024ae
commit
7f826a7d35
10
Makefile
10
Makefile
@ -103,7 +103,15 @@ endif
|
|||||||
ifeq (1,$(PBX_HDLC))
|
ifeq (1,$(PBX_HDLC))
|
||||||
BINS += sethdlc
|
BINS += sethdlc
|
||||||
endif
|
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_UTILS:=dahdi_span_assignments dahdi_span_types
|
||||||
ASSIGNED_CONF:=assigned-spans.conf.sample span-types.conf.sample
|
ASSIGNED_CONF:=assigned-spans.conf.sample span-types.conf.sample
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ exec 2> /dev/null
|
|||||||
|
|
||||||
# Our directory in the beginning, so we can use local lab setup
|
# Our directory in the beginning, so we can use local lab setup
|
||||||
PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin"
|
PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin"
|
||||||
|
export PATH
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
@ -35,43 +36,44 @@ if [ "$DAHDI_UDEV_DISABLE_DEVICES" = 'yes' ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
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
|
# Can we pass a different value so we can use
|
||||||
# alternate (testing) configuration?
|
# alternate (testing) configuration?
|
||||||
# Meanwhile, make it hard-coded.
|
# Meanwhile, make it hard-coded.
|
||||||
DAHDICONFDIR='/etc/dahdi'
|
DAHDICONFDIR='/etc/dahdi'
|
||||||
export DAHDICONFDIR
|
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
|
case "$ACTION" in
|
||||||
add)
|
add)
|
||||||
echo "$ACTION: $DEVPATH" | $LOGGER
|
echo "$ACTION: $DEVPATH" | $LOGGER
|
||||||
|
# Background run -- don't block udev
|
||||||
# Check if we can safely do our job
|
run_parts 2>&1 < /dev/null | $LOGGER &
|
||||||
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 &
|
|
||||||
;;
|
;;
|
||||||
remove)
|
remove)
|
||||||
# Nothing to do yet...
|
# Nothing to do yet...
|
||||||
|
@ -20,6 +20,7 @@ exec 2> /dev/null
|
|||||||
|
|
||||||
# Our directory in the beginning, so we can use local lab setup
|
# Our directory in the beginning, so we can use local lab setup
|
||||||
PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin"
|
PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin"
|
||||||
|
export PATH
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
@ -41,66 +42,35 @@ fi
|
|||||||
DAHDICONFDIR='/etc/dahdi'
|
DAHDICONFDIR='/etc/dahdi'
|
||||||
export DAHDICONFDIR
|
export DAHDICONFDIR
|
||||||
|
|
||||||
run_dahdi_cfg() {
|
run_parts() {
|
||||||
echo "dahdi_cfg: span $spanno <$basechan-$endchan> ($DEVPATH)"
|
# Have our internal "run-parts" (adapted from Fedora),
|
||||||
dahdi_cfg -c "$cfg_file" -S "$spanno" -C "$basechan-$endchan"
|
# as implementations differ
|
||||||
}
|
for i in `LC_ALL=C; ls -d $dir/span_config.d/*[!~,] 2>/dev/null` ; do
|
||||||
|
[ -d "$i" ] && continue
|
||||||
configure_span() {
|
[ ! -x "$i" ] && continue
|
||||||
span_devpath="$1"
|
# Don't run *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} files
|
||||||
# Sanity check
|
case "$i" in
|
||||||
checkit=`"dahdi_cfg" --help 2>&1 | grep -- '-S' | wc -l`
|
*.cfsaved|*.rpmsave|*.rpmorig|*.rpmnew|*.swp|*,v)
|
||||||
if [ "$checkit" != 1 ]; then
|
continue
|
||||||
echo "Bad dahdi_cfg (no -S support). Skipping"
|
;;
|
||||||
exit 0
|
esac
|
||||||
fi
|
#echo "D: Running '$i'"
|
||||||
|
"$i"
|
||||||
# Set variables
|
done
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$ACTION" in
|
case "$ACTION" in
|
||||||
add)
|
add)
|
||||||
echo "$ACTION: $DEVPATH" | $LOGGER
|
echo "$ACTION: $DEVPATH" | $LOGGER
|
||||||
|
# Set variables
|
||||||
# Old driver. These scripts probably won't work anyway.
|
span_devpath="/sys$DEVPATH"
|
||||||
if [ ! -f /sys/module/dahdi/parameters/auto_assign_spans ]; then
|
SPANNO=`echo "$span_devpath" | sed 's,.*/span-,,'`
|
||||||
if [ -f /sys/module/dahdi ]; then
|
BASECHAN=`cat "$span_devpath/basechan"`
|
||||||
$LOGGER "Old driver (no auto_assign_spans parameter). Skip $DEVPATH"
|
CHANNELS=`cat "$span_devpath/channels"`
|
||||||
exit 0
|
ENDCHAN=`expr "$BASECHAN" + "$CHANNELS" - 1`
|
||||||
fi
|
export SPANNO BASECHAN CHANNELS ENDCHAN
|
||||||
fi
|
# Background run -- don't block udev
|
||||||
|
run_parts 2>&1 < /dev/null | $LOGGER &
|
||||||
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
|
|
||||||
;;
|
;;
|
||||||
remove|online|offline)
|
remove|online|offline)
|
||||||
# Nothing to do yet...
|
# Nothing to do yet...
|
||||||
|
5
hotplug/handle_device.d/10-span-types
Executable file
5
hotplug/handle_device.d/10-span-types
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
if [ -r "$DAHDICONFDIR/span-types.conf" ]; then
|
||||||
|
dahdi_span_types set "/sys$DEVPATH"
|
||||||
|
fi
|
8
hotplug/handle_device.d/20-span-assignments
Executable file
8
hotplug/handle_device.d/20-span-assignments
Executable 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
|
28
hotplug/span_config.d/10-dahdi-cfg
Executable file
28
hotplug/span_config.d/10-dahdi-cfg
Executable 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
|
12
hotplug/span_config.d/20-fxotune
Executable file
12
hotplug/span_config.d/20-fxotune
Executable 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
|
9
hotplug/span_config.d/50-asterisk
Executable file
9
hotplug/span_config.d/50-asterisk
Executable 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"
|
Loading…
Reference in New Issue
Block a user