Debian Codegraph @

dahdi_waitfor_span_assignments

raw symbols SCIP
1 #! /bin/shscip-shell filesystem . . `/bin/sh`.
2
3 usagescip-shell shell dahdi-tools 1:3.4.0-1 usage().() {
4 echoscip-shell system . . echo. >&2 "Usage: $0 {assigned|unassigned}"
5 echoscip-shell system . . echo. >&2 "# wait until all spans known are assigned/unassigned"
6 exit 1
7 }
8
9 TIMEOUT=5 # How much time to wait for spans
10
11 if [scip-shell system . . `[`. "$#" -lt 1 ]; then
12 usagescip-shell shell dahdi-tools 1:3.4.0-1 usage().
13 fi
14 wanted_event="$1"
15 shift
16
17 case "$wanted_event" in
18 assigned)
19 ;;
20 unassigned)
21 ;;
22 *)
23 usagescip-shell shell dahdi-tools 1:3.4.0-1 usage().
24 ;;
25 esac
26
27 devbase='/sys/bus/dahdi_devices/devicesscip-shell filesystem . . `/sys/bus/dahdi_devices/devices`.'
28
29 spans_ofscip-shell shell dahdi-tools 1:3.4.0-1 spans_of().() {
30 dev="$1"
31 wcscip-shell system . . wc. -l < "$dev/spantype"
32 }
33
34 assigned_spans_ofscip-shell shell dahdi-tools 1:3.4.0-1 assigned_spans_of().() {
35 dev="$1"
36 lsscip-shell system . . ls. -d "$dev/span-"* 2>/dev/nullscip-shell filesystem . . `/dev/null`. | wcscip-shell system . . wc. -l
37 }
38
39
40 waitfor_span_assignmentsscip-shell shell dahdi-tools 1:3.4.0-1 waitfor_span_assignments().() {
41 wanted_state="$1"
42 device_list=`lsscip-shell system . . ls. -d "$devbase/"* 2> /dev/nullscip-shell filesystem . . `/dev/null`.`
43 finished=''
44 count="$TIMEOUT"
45 echoscip-shell system . . echo. -n "Waiting for spans to become $wanted_state: "
46 while [scip-shell system . . `[`. "$count" -gt 0 ]; do
47 finished='yes'
48 for dev in $device_list
49 do
50 spans=`spans_ofscip-shell shell dahdi-tools 1:3.4.0-1 spans_of(). "$dev"`
51 assigned_spans=`assigned_spans_ofscip-shell shell dahdi-tools 1:3.4.0-1 assigned_spans_of(). "$dev"`
52 if [scip-shell system . . `[`. "$wanted_state" = 'assigned' -a "$assigned_spans" -ne "$spans" ]; then
53 finished='no'
54 elif [scip-shell system . . `[`. "$wanted_state" = 'unassigned' -a "$assigned_spans" -ne 0 ]; then
55 finished='no'
56 fi
57 done
58 if [scip-shell system . . `[`. "$finished" = 'yes' ]; then
59 break
60 else
61 sleepscip-shell system . . sleep. 1
62 echoscip-shell system . . echo. -n "."
63 fi
64 count=`exprscip-shell system . . expr. "$count" - 1`
65 done
66 if [scip-shell system . . `[`. "$finished" = 'yes' ]; then
67 echoscip-shell system . . echo. "done"
68 else
69 echoscip-shell system . . echo. "timeout"
70 fi
71 }
72
73 waitfor_span_assignmentsscip-shell shell dahdi-tools 1:3.4.0-1 waitfor_span_assignments(). "$wanted_event"