Commit 5ac724b8 authored by Jouke Witteveen's avatar Jouke Witteveen
Browse files

Introduce polling timeout logic

This should fix FS#30361 along the way.
parent 4e034777
......@@ -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" |
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment