awilliams / wifi-presence

Presence detection on OpenWrt routers using connect/disconnect events of WiFi clients. Events are published to MQTT with Home Assistant integration.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OpenWrt Boot racecondition

jmccrohan opened this issue · comments

Hi Adam,

I've noticed that wifi-presence does not start cleanly on boot for me. I suspect the issue is that hostapd hasn't started yet, and there are no control sockets found by wifi-presence when it starts.

root@ap-office:~# logread | grep wifi-presence
Fri Apr 22 17:08:51 2022 daemon.err wifi-presence[2366]: Error: hostapd.socks cannot be blank

Restarting the process manually after boot is fine, so I'm not sure what the best way of resolving this is, whether it be through procd, or through wifi-presence itself.

Cheers,
Jon

Thanks for the report. I've noticed that too, where wifi-presence fails to start likely because of what you described. In my case though, procd restarts it and eventually it works.

We could consider something like the following in the start_service function.

for i in 1 2 3 4 5 6 7 8 9 10; do
	if [ -d "${hostapdSockDir}" ] && find "${hostapdSockDir}" -type s | grep . >/dev/null; then
		# hostapd socket(s) found
		break
	fi
	# No hostapd socket found, retrying in 1s
	sleep 1
done

The START=95 setting should mean that wifi-presence is started after hostapd (START=19).

Thanks. Yes, this approach makes sense to me. Do you want to roll the fix for this and #3 into a single PR?