-
Notifications
You must be signed in to change notification settings - Fork 37
WiFi_OnOff: improve wait handling for delayed interface creation #482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,39 +19,68 @@ wait_for_wifi_interface() { | |
| sleep_step="${2:-2}" | ||
| waited=0 | ||
| iface="" | ||
|
|
||
| settle_done=0 | ||
|
|
||
| case "$max_wait" in | ||
| ''|*[!0-9]*) | ||
| max_wait=30 | ||
| ;; | ||
| esac | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra white-space |
||
| case "$sleep_step" in | ||
| ''|*[!0-9]*) | ||
| sleep_step=2 | ||
| ;; | ||
| esac | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra white-space |
||
| if [ "$max_wait" -le 0 ] 2>/dev/null; then | ||
| max_wait=30 | ||
| fi | ||
| if [ "$sleep_step" -le 0 ] 2>/dev/null; then | ||
| sleep_step=2 | ||
| fi | ||
|
|
||
| while [ "$waited" -lt "$max_wait" ]; do | ||
| wifi_unblock_rfkill | ||
|
|
||
| iface="$(get_wifi_interface 2>/dev/null || true)" | ||
| if [ -n "$iface" ]; then | ||
| printf '%s\n' "$iface" | ||
| return 0 | ||
| fi | ||
|
|
||
| sleep "$sleep_step" | ||
| waited=$((waited + sleep_step)) | ||
| done | ||
|
|
||
|
|
||
| # Keep stdout reserved for the detected interface name. This helper is | ||
| # commonly used through command substitution, so all diagnostics from the | ||
| # wait loop must go to stderr. The final interface is printed through fd 3, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the README be also updated to let the user know that fd 3 is in use and they cannot use it. |
||
| # which preserves the caller's original stdout. | ||
| { | ||
| log_info "Waiting up to ${max_wait}s for WiFi interface creation" | ||
|
|
||
| while [ "$waited" -lt "$max_wait" ]; do | ||
| wifi_unblock_rfkill | ||
|
|
||
| iface="$(get_wifi_interface 2>/dev/null || true)" | ||
| if [ -n "$iface" ]; then | ||
| printf '%s\n' "$iface" >&3 | ||
| return 0 | ||
| fi | ||
|
|
||
| if [ "$settle_done" -eq 0 ]; then | ||
| settle_done=1 | ||
|
|
||
| if command -v udevadm >/dev/null 2>&1; then | ||
| log_info "No WiFi interface yet; triggering net uevents and waiting for udev settle" | ||
| udevadm trigger --subsystem-match=net >/dev/null 2>&1 || true | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will re-trigger on all network interfaces, which are already settled.
|
||
| udevadm settle --timeout=5 >/dev/null 2>&1 || true | ||
|
|
||
| iface="$(get_wifi_interface 2>/dev/null || true)" | ||
| if [ -n "$iface" ]; then | ||
| printf '%s\n' "$iface" >&3 | ||
| return 0 | ||
| fi | ||
| fi | ||
| fi | ||
|
|
||
| sleep "$sleep_step" | ||
| waited=$((waited + sleep_step)) | ||
|
|
||
| if [ "$waited" -gt 0 ] && [ $((waited % 10)) -eq 0 ]; then | ||
| log_info "Still waiting for WiFi interface... waited=${waited}s/${max_wait}s" | ||
| fi | ||
| done | ||
| } 3>&1 1>&2 | ||
|
|
||
| return 1 | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be updated to 60 too?