mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
wifidmd: add timing-based wait logic to detect completion of wifi reload
This commit is contained in:
parent
f9ad16934c
commit
0718730d6b
1 changed files with 74 additions and 2 deletions
|
|
@ -42,23 +42,95 @@ for arg in ${input}; do
|
|||
fi
|
||||
done
|
||||
|
||||
|
||||
################################################################################
|
||||
# wait_for_wifi_reload
|
||||
#
|
||||
# Description:
|
||||
# Currently, there is no direct way to determine when WiFi reload
|
||||
# operations have fully completed. The ubus API does not provide any
|
||||
# event or flag indicating that WiFi services have finished reloading.
|
||||
#
|
||||
# To work around this, we use a timing-based heuristic:
|
||||
# - We repeatedly run `ubus call wifi status` every 1 second.
|
||||
# - Each call is timed (using `date +%s` before and after).
|
||||
# - Normally, this command returns almost instantly (<1s).
|
||||
# - However, during a WiFi reload, the call may take longer
|
||||
# (several seconds) while the subsystem is busy.
|
||||
# - Once we detect that `ubus call wifi status` takes longer than
|
||||
# 2 seconds to return, we assume the reload has been applied
|
||||
# and completed successfully.
|
||||
#
|
||||
# Additional wait constraints:
|
||||
# - Minimum wait: 5 seconds (to ensure reload started).
|
||||
# - Maximum wait: 15 seconds (to prevent indefinite blocking).
|
||||
# - If the threshold is not met within 15s, we log a timeout warning.
|
||||
################################################################################
|
||||
wait_for_wifi_reload() {
|
||||
MAX_ITER=15
|
||||
MIN_ITER=5
|
||||
THRESH=2 # seconds
|
||||
|
||||
# Check if wifi ubus object exists
|
||||
ubus -t 2 wait_for wifi >/dev/null 2>&1
|
||||
if [ "$?" -ne 0 ]; then
|
||||
log "wifi ubus object not available, skipping wait logic"
|
||||
return 0
|
||||
fi
|
||||
|
||||
#log "Waiting for WiFi reload (min ${MIN_ITER}s, max ${MAX_ITER}s)..."
|
||||
|
||||
iter=0
|
||||
while [ "${iter}" -lt "${MAX_ITER}" ]; do
|
||||
iter=$((iter + 1))
|
||||
start=$(date +%s)
|
||||
ubus call wifi status >/dev/null 2>&1
|
||||
#rc=$?
|
||||
end=$(date +%s)
|
||||
elapsed=$((end - start))
|
||||
|
||||
#log "wait_for_wifi_reload: iter=${iter}, rc=${rc}, elapsed=${elapsed}s"
|
||||
|
||||
# If ubus took >2s and we've waited at least MIN_ITER → assume reload done
|
||||
if [ "${elapsed}" -gt "${THRESH}" ] && [ "${iter}" -ge "${MIN_ITER}" ]; then
|
||||
log "Detected long ubus response (${elapsed}s) after ${iter}s → assuming WiFi reload complete"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Sleep 1s between checks
|
||||
if [ "${iter}" -lt "${MAX_ITER}" ]; then
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
|
||||
log "Timeout after ${MAX_ITER}s — WiFi reload not confirmed"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Define function to reload mapcontroller
|
||||
reload_mapcontroller() {
|
||||
pid=$(pidof mapcontroller)
|
||||
if [ -n "$pid" ]; then
|
||||
log "Reloading mapcontroller (PID: $pid)..."
|
||||
kill -SIGHUP "$pid"
|
||||
wait_for_wifi_reload
|
||||
else
|
||||
log "Warning: mapcontroller process not found"
|
||||
fi
|
||||
}
|
||||
|
||||
# Define function to commit wireless config
|
||||
commit_wireless_config() {
|
||||
log "Committing wireless config..."
|
||||
ubus call uci commit '{"config":"wireless"}'
|
||||
wait_for_wifi_reload
|
||||
}
|
||||
|
||||
# Apply logic based on flags
|
||||
if [ "$mapcontroller" -eq 1 ]; then
|
||||
reload_mapcontroller
|
||||
elif [ "$wireless" -eq 1 ]; then
|
||||
log "Committing wireless config..."
|
||||
ubus call uci commit '{"config":"wireless"}'
|
||||
commit_wireless_config
|
||||
else
|
||||
log "No action needed."
|
||||
exit 1
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue