dahdi-tools/hotplug/dahdi_auto_assign_compat
Oron Peled 754d981621 Avoid a race between /etc/init.d/dahdi and hotplug scripts:
* On some systems/configurations, dahdi init script may kick in
  during the time that hotplug scripts are configuring spans.

* It may lead to a race since the init script runs "dahdi_auto_assign_compat"
  which calls "dahdi_registration" and that tries to run
  "dahdi_span_assignments auto ..."

* Use the newly-added "dahdi_span_assignments" "unmatched" operation.

* Now the "dahdi_auto_assign_compat" script only runs "dahdi_registration"
  if there are no "unmatched" Astribanks.

* This prevents the race in fully configured systems.
  The race may still exist on partially-configured systems.
2017-08-31 19:00:02 +03:00

31 lines
723 B
Bash
Executable File

#! /bin/sh
devdir='/sys/bus/dahdi_devices/devices'
# DAHDI is loaded?
if [ ! -d "$devdir" ]; then
exit 0
fi
devices_by_registration_time() {
grep -H '' $devdir/*/registration_time 2>/dev/null | \
sed 's,/registration_time:,\t,' | \
sort -k 2,2
}
# First assign non-Astribank devices
devices_by_registration_time | \
grep -v '/astribanks:' | \
while read devpath time; do
echo >&2 "D: auto '$devpath'"
dahdi_span_assignments auto "$devpath"
done
# Now handle Astribanks
unmatched="`dahdi_span_assignments unmatched`"
if [ -n "$unmatched" ]; then
# Only if astribanks are not matched in span-assignments.conf
# TODO: have dahdi_registration run only on "$unmatched"
LC_ALL=C dahdi_registration -Rv on
fi