#!/bin/bash # Register for with radio-reset-monitor to # get a signal when radio-reset occurs. # Child process exists so the parent # does not need to worry about resets # starting before it can get through # checks, and possibly sleeping forever. # pgrep was needed to kill the sleep. # wait is called to wait for the SIGUSR1 signal. # The child never terminates. # The hope is that the parent will fall into wait # before the child registers for the radio-reset. # checking for do_wait is risky if the kernel ever # changes. The child will exit if the reset is not # in process. # USR1=10 TERM=15 function sleep_reset { # Wait for parent to enter wait. trap "exit 0" $TERM while [[ $(ps -h -o wchan -p $PPID) != do_wait ]] ; do usleep 100 ; done echo Register parent for SIGUSR1 echo "$$" "$USR1" >/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 } date trap ":" $USR1 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 pgrep -P $! | xargs kill fi echo "$$" "0" >/sys/devices/platform/mts-io/radio-reset-monitor echo Radio Reset is done. date sleep 30