dahdi-tools/hotplug/dahdi_handle_device
Shaun Ruffell 27d07446ef hotplug: Check for auto_assign_spans only when ACTION is add.
Removes a potentially confusing error message. This is a reapplication of
(4f259cd569 "dahdi_handle_device, dahdi_span_config: Check for
auto_assign_spans only when ACTION is add.") which appears to have been
accidentally removed when moving the hotplug scripts into a subdirectory.

From the original commit:

When dahdi.ko is unloaded, it may be possible for the driver to be removed from
the kernel before the udev scripts are run.  When this happens, you'll see
messages like the following which are not accurate:

    'dahdi_handle_device'[24567]: Old driver (no auto_assign_spans parameter). Skip /devices/pci0000:00/0000:00:1e.0/0000:11:01.0/pci:0000:11:01.0

Now instead you will see:

    'dahdi_handle_device'[28008]: remove: /devices/pci0000:00/0000:00:1e.0/0000:11:01.0/pci:0000:11:01.0

Also, all the udev events will be logged in the system log even when they are
ignored because of legacy auto span assignment. This will help show what is
going on during the transition period to full udev configuration of spans.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
Acked-by: Oron Peled <oron.peled@xorcom.com>
2014-01-31 16:08:21 -06:00

87 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"
export PATH
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
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
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
# Background run -- don't block udev
run_parts 2>&1 < /dev/null | $LOGGER &
;;
remove)
# Nothing to do yet...
echo "$ACTION: $DEVPATH" | $LOGGER
;;
*)
echo "UNHANDLED: $ACTION: $DEVPATH" | $LOGGER
;;
esac