summaryrefslogtreecommitdiff
path: root/recipes-connectivity/ppp/files/wait_for_reset
blob: 7e9da9554cb6e71d6fd5b4c290af1bd5d701bffa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash

# For ppp to work, stty must work on file descriptor 0.
# If stty fails, so will ppp.

NAME=wait_for_reset

: ${LOG:="/usr/bin/logger -t ${NAME} -p daemon.notice"}

USR2=12
TERM=15
# Child used to set our PID in the radio-reset-monitor
function sleep_reset
{
    # Wait for parent to enter wait.
    trap "kill $!;kill $BASHPID" $TERM
    while [[ $(ps -h -o wchan -p $PPID) != do_wait ]] ; do usleep 100 ; done
    ${LOG} Register for SIGUSR2 when radio-reset complete
    echo "$$" "$USR2" >/sys/devices/platform/mts-io/radio-reset-monitor
    discovered=$(cat /sys/devices/platform/mts-io/radio-udev-discovery)
    if ((discovered == 1)) ; then
       # reset is not in progress.
       exit 0
    fi
    sleep 4294967295  # Hopefully forever
    exit 0
}

# Wait for radio-reset to complete
function wait_for_reset
{
	# Wait for radio reset/modem discovery
	trap ":" $USR2
	in_reset=$(cat /sys/devices/platform/mts-io/radio-udev-discovery)
	if ((in_reset == 0)) ; then
		sleep_reset &
		wait $!
		# pgrep is needed to find the sleep process
                echo "pgrep -P: $(pgrep -P $!)"
		pgrep -P $! | xargs kill
                ${LOG} "radio-reset is complete"
                
	fi
	trap "" $USR2
}