[arch-projects] [mkinitcpio][PATCH 05/11] init_functions: refactor poll_device

Dave Reisner d at falconindy.com
Fri Nov 11 21:55:15 EST 2011


Beyond stylistic cleanup, add a conditional to ensure that we don't
show the 'waiting for device' message if it already exists.

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
 init_functions |   23 ++++++++++++-----------
 1 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/init_functions b/init_functions
index e026929..7dd0968 100644
--- a/init_functions
+++ b/init_functions
@@ -8,20 +8,21 @@ err () {
 }
 
 poll_device() {
-    device="$1"
-    if [ "$2" -ge 0 ]; then
-        seconds="$2"
-    else
-        seconds=5
-    fi
-    if [ "${udevd_running}" -eq 1 ]; then
-        msg "Waiting ${seconds} seconds for device ${device} ..."
-        while [ ! -b "${device}" -a ${seconds} -gt 0 ]; do
+    local device=$1 seconds=${2//[!0-9]}
+
+    [ -z "$seconds" ] && seconds=5
+
+    [ -b "$device" ] && return 0
+
+    if [ "$udevd_running" -eq 1 ]; then
+        msg "Waiting $seconds seconds for device $device ..."
+        while [ ! -b "$device" -a "$seconds" -gt 0 ]; do
             sleep 1
-            seconds=$((${seconds}-1))
+            seconds=$(( $seconds - 1 ))
         done
     fi
-    [ -b "${device}" ]
+
+    [ -b "$device" ]
 }
 
 launch_interactive_shell() {
-- 
1.7.7.3



More information about the arch-projects mailing list