From 09bbcaf175be235874cceee0f0e75781ed100d02 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 5 Nov 2011 21:26:53 -0400 Subject: init_functions: refactor poll_device 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 --- init_functions | 23 ++++++++++++----------- 1 file 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() { -- cgit v1.2.3-24-g4f1b