dahdi-tools/dahdi_handle_device
Shaun Ruffell a4f79134c9 dahdi_handle_device: Auto assign only the device being added.
Eliminates trying to add spans multiple times as seen below:

    'dahdi_handle_device'[21993]: add: /devices/dynamic:loc:1
    'dahdi_handle_device'[21991]: add: /devices/dynamic:loc:0
    'dahdi_handle_device'[22001]: auto-assign /sys/bus/dahdi_devices/devices/dynamic:loc:0
    'dahdi_handle_device'[22001]: auto-assign /sys/bus/dahdi_devices/devices/dynamic:loc:1
    'dahdi_handle_device'[21999]: auto-assign /sys/bus/dahdi_devices/devices/dynamic:loc:0
    'dahdi_handle_device'[21999]: auto-assign /sys/bus/dahdi_devices/devices/dynamic:loc:1
    kernel: [ 3348.312534] dahdi_devices dynamic:loc:0: local span 1 is already assigned span 1
    kernel: [ 3348.312552] dahdi_devices dynamic:loc:1: local span 1 is already assigned span 2

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
Acked-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
2014-01-20 19:22:57 +02:00

84 lines
2.1 KiB
Bash
Executable File

#! /bin/sh
#
# /usr/share/dahdi/dahdi_handle_device
#
# Called by UDEV when a dahdi device is added/removed
#
me=`basename $0`
dir=`dirname $0`
LOGGER="logger -i -t '$me'"
NAME=`basename "$DEVPATH" | tr -c 'A-Za-z0-9-' '_'`
# Always redirect stderr somewhere, otherwise the shell script will die
# when it tries to do I/O related stuff on closed file descriptor.
# Our default is to throw it down the bit-bucket.
exec 2> /dev/null
# If you wish to trace this script:
#exec 2> "/tmp/${me}.$NAME" 1>&2
#exec 2> /dev/console
# Our directory in the beginning, so we can use local lab setup
PATH="$dir:/usr/sbin:/sbin:/usr/bin:/bin"
set -e
#echo >&2 "$0($ACTION): DEBUG($# args): '$*'"
# Do we have a configuration?
if [ -f /etc/dahdi/init.conf ]; then
. /etc/dahdi/init.conf
fi
if [ "$DAHDI_UDEV_DISABLE_DEVICES" = 'yes' ]; then
echo "DAHDI_UDEV_DISABLE_DEVICES=yes. 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
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 &
;;
remove)
# Nothing to do yet...
echo "$ACTION: $DEVPATH" | $LOGGER
;;
*)
echo "UNHANDLED: $ACTION: $DEVPATH" | $LOGGER
;;
esac