summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2012-06-21 12:19:53 +0200
committerJouke Witteveen <j.witteveen@gmail.com>2012-06-21 12:19:53 +0200
commit5ac724b8d139b7e38c3a16c8752bad55076ea670 (patch)
treeb7d5cdb68c5e050829aa6de401224284c0b482c0 /src
parent4e034777fa0bfffa11d87b602e6b2b941edd3262 (diff)
downloadnetctl-5ac724b8d139b7e38c3a16c8752bad55076ea670.tar.gz
netctl-5ac724b8d139b7e38c3a16c8752bad55076ea670.tar.xz
Introduce polling timeout logic
This should fix FS#30361 along the way.
Diffstat (limited to 'src')
-rw-r--r--src/8021x7
-rw-r--r--src/connections/ethernet16
-rw-r--r--src/globals14
-rw-r--r--src/network7
4 files changed, 23 insertions, 21 deletions
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