From 42c01012e85646706bf11042cc0952d47d9236d0 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Wed, 31 Oct 2012 21:57:48 -0400 Subject: init: use exponential backoff in poll_device Start at .1 second and double the interval, capping at 1s. Signed-off-by: Dave Reisner --- init_functions | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/init_functions b/init_functions index 3ac0588..2bd07bd 100644 --- a/init_functions +++ b/init_functions @@ -11,14 +11,24 @@ poll_device() { local device=$1 seconds=${2//[!0-9]} [ -z "$seconds" ] && seconds=10 + deciseconds=$(( seconds * 10 )) + + # tenths of a second + sleepinterval=1 [ -b "$device" ] && return 0 if [ "$udevd_running" -eq 1 ]; then msg "Waiting $seconds seconds for device $device ..." >&2 - while [ ! -b "$device" -a "$seconds" -gt 0 ]; do - sleep 1 - seconds=$(( $seconds - 1 )) + while [ ! -b "$device" -a "$deciseconds" -gt 0 ]; do + if [ "$sleepinterval" -ge 10 ]; then + sleep 1 + deciseconds=$(( deciseconds - 10 )) + else + sleep .$sleepinterval + deciseconds=$(( deciseconds - sleepinterval )) + sleepinterval=$(( sleepinterval * 2 )) + fi done fi -- cgit v1.2.3-24-g4f1b