[arch-projects] [mkinitcpio] [PATCH 06/18] init: use exponential backoff in poll_device

Dave Reisner dreisner at archlinux.org
Fri Nov 23 18:48:51 EST 2012


Start at .1 second and double the interval, capping at 1s.

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
 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
 
-- 
1.8.0



More information about the arch-projects mailing list