All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v2 1/1] package/dnsmasq: Fix init script restart command
@ 2024-05-31 18:53 Fiona Klute via buildroot
  2024-06-01 20:19 ` Yann E. MORIN
  2024-06-08 16:59 ` Peter Korsgaard
  0 siblings, 2 replies; 3+ messages in thread
From: Fiona Klute via buildroot @ 2024-05-31 18:53 UTC (permalink / raw)
  To: buildroot; +Cc: Bernd Kuhls, Yann E . MORIN, Fiona Klute

I have had constant issues restarting dnsmasq. Stop works, start fails
because the new instance can't bind the socket. Another restart
immediately after works just fine:

# /etc/init.d/S80dnsmasq restart
Stopping dnsmasq: OK
Starting dnsmasq:
dnsmasq: failed to create listening socket for 192.168.128.1: Address in use
FAIL
# /etc/init.d/S80dnsmasq restart
Stopping dnsmasq: FAIL
Starting dnsmasq: OK

Solve this by waiting for process to actually stop before returning
from the stop command. Clean up the PID file after to avoid potential
issues with the PID being reused after stop. The wait could also be
placed inside the restart block, but putting it into the stop block
has the advantage that it also avoids similar issues for any other
callers.

Signed-off-by: Fiona Klute <fiona.klute+wiwa@gmx.de>
---
Changes v1 -> v2:
Read $PIDFILE only once per iteration, to avoid errors if it
disappears between checks. Suggested by Yann E. MORIN.

 package/dnsmasq/S80dnsmasq | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/package/dnsmasq/S80dnsmasq b/package/dnsmasq/S80dnsmasq
index 175daf9d26..27163f5205 100644
--- a/package/dnsmasq/S80dnsmasq
+++ b/package/dnsmasq/S80dnsmasq
@@ -16,6 +16,13 @@ case "$1" in
 		printf "Stopping dnsmasq: "
 		start-stop-daemon -K -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON"
 		[ $? = 0 ] && echo "OK" || echo "FAIL"
+		# wait for dnsmasq process to be gone
+		while true; do
+			pid="$( cat "${PIDFILE}" 2>/dev/null || true )"
+			( [ -n "${pid}" ] && [ -d "/proc/${pid}" ] ) || break
+			sleep 0.1
+		done
+		rm -f "$PIDFILE"
 		;;
 	restart|reload)
 		$0 stop
--
2.45.1
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-08 16:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-31 18:53 [Buildroot] [PATCH v2 1/1] package/dnsmasq: Fix init script restart command Fiona Klute via buildroot
2024-06-01 20:19 ` Yann E. MORIN
2024-06-08 16:59 ` Peter Korsgaard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.