From 5ac724b8d139b7e38c3a16c8752bad55076ea670 Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Thu, 21 Jun 2012 12:19:53 +0200 Subject: Introduce polling timeout logic This should fix FS#30361 along the way. --- src/8021x | 7 ++----- src/connections/ethernet | 16 +++++----------- src/globals | 14 ++++++++++++++ src/network | 7 ++----- 4 files changed, 23 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/8021x b/src/8021x index d92ccbe..d143b30 100644 --- a/src/8021x +++ b/src/8021x @@ -130,7 +130,7 @@ list_networks() { } wpa_supplicant_scan_info() { - local INTERFACE="$1" fields="$2" spawned_wpa=0 essids scan_wait + local INTERFACE="$1" fields="$2" spawned_wpa=0 essids # temp file used, as keeping ESSID's with spaces in their name in arrays # is hard, obscure and kinda nasty. This is simpler and clearer. @@ -146,10 +146,7 @@ wpa_supplicant_scan_info() { # Wait at least 3 seconds for scan results sleep 3 # Sometimes, that is not enough (FS#29946) - for (( scan_wait = 3; scan_wait < 10; scan_wait++ )); do - wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status | grep -q "wpa_state=SCANNING" || break - sleep 1 - done + timeout_wait 7 '! wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status | grep -q "wpa_state=SCANNING"' wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" scan_results | grep -v "^Selected" | grep -v "^bssid" | diff --git a/src/connections/ethernet b/src/connections/ethernet index e51f68d..24e92d5 100644 --- a/src/connections/ethernet +++ b/src/connections/ethernet @@ -14,8 +14,6 @@ report_iproute() } ethernet_up() { - local dad_timeout="${DAD_TIMEOUT:-3}" - load_profile "$1" SYSCTL_INTERFACE="${INTERFACE/.//}" @@ -34,10 +32,9 @@ ethernet_up() { bring_interface up "$INTERFACE" - if ! checkyesno "${SKIPNOCARRIER:-no}" && ip link show dev "$INTERFACE" | fgrep -q "NO-CARRIER"; then + if ! checkyesno "${SKIPNOCARRIER:-no}"; then # Some cards are plain slow to come up. Don't fail immediately. - sleep ${CARRIER_TIMEOUT:-2} - if ip link show dev "$INTERFACE" | fgrep -q "NO-CARRIER"; then + if ! timeout_wait "${CARRIER_TIMEOUT:-5}" '! ip link show dev "$INTERFACE" | fgrep -q "NO-CARRIER"'; then report_iproute "No connection" fi fi @@ -186,12 +183,9 @@ ethernet_up() { if [[ -n "$IP6" ]]; then # Wait for DAD to finish (FS#28887) report_debug ethernet_up ip -6 addr show dev "$INTERFACE" tentative - while [[ -n "$(ip -6 addr show dev "$INTERFACE" tentative)" ]]; do - if (( dad_timeout-- <= 0 )); then - report_iproute "Duplicate Address Detection is taking too long" - fi - sleep 1 - done + if ! timeout_wait "${DAD_TIMEOUT:-3}" '[[ -z "$(ip -6 addr show dev "$INTERFACE" tentative)" ]]'; then + report_iproute "Duplicate Address Detection is taking too long" + fi # Add static IPv6 routes if [[ -n "$ROUTES6" ]]; then diff --git a/src/globals b/src/globals index 0d573e2..af411fe 100644 --- a/src/globals +++ b/src/globals @@ -95,6 +95,20 @@ function checkyesno() { } +## Waits until a statement succeeds or a timeout occurs +# $1: timeout in seconds +# $2...: condition command +function timeout_wait() { + local timeout="$1" + shift + while ! eval "$*"; do + (( timeout-- > 0 )) || return 1 + sleep 1 + done + return 0 +} + + ### Load all +x files in $HOOKS_DIR function load_hooks() { local hook diff --git a/src/network b/src/network index 1c466c7..02d74d7 100644 --- a/src/network +++ b/src/network @@ -372,17 +372,14 @@ interface_is_up() { # $2: the interface name bring_interface() { - local INTERFACE="$2" timeout="${UP_TIMEOUT:-5}" + local INTERFACE="$2" case "$1" in up) if ! ( eval $IFACE_UP ); then return 1 fi ip link set dev "$INTERFACE" up &>/dev/null - while ! interface_is_up "$INTERFACE"; do - (( timeout-- > 0 )) || return 1 - sleep 1 - done + timeout_wait "${UP_TIMEOUT:-5}" 'interface_is_up "$INTERFACE"' || return 1 ;; flush|down) if ! ( eval $IFACE_DOWN ); then -- cgit v1.2.3-24-g4f1b