package/mdnsd/S50mdnsd: rewrite to match current guidelines

With the action function as the last command in the script its return
code automatically becomes that of the script, and without explicit
exit shellcheck does not complain about unused functions.

Also wait for the process to stop in "stop", and simplify restart.

Signed-off-by: Fiona Klute <fiona.klute@gmx.de>
Signed-off-by: Marcus Hoffmann <buildroot@bubu1.eu>
This commit is contained in:
Fiona Klute
2026-06-06 20:20:31 +02:00
committed by Marcus Hoffmann
parent b2d84525f9
commit b4884a2937

View File

@@ -1,5 +1,4 @@
#!/bin/sh
# shellcheck disable=SC2317 # Don't warn about unreachable commands in this file
DAEMON=mdnsd
MDNSD=/usr/sbin/$DAEMON
@@ -12,43 +11,63 @@ MDNSD_ARGS=""
# shellcheck source=/dev/null
[ -r "$CFGFILE" ] && . "$CFGFILE"
# shellcheck disable=SC2086
start() {
[ -n "$1" ] || printf 'Starting %s: ' "$DAEMON"
start-stop-daemon -S -q -p "$PIDFILE" -x "$MDNSD" -- $MDNSD_ARGS
printf 'Starting %s: ' "$DAEMON"
# shellcheck disable=SC2086 # we need word splitting
start-stop-daemon --start --pidfile "$PIDFILE" \
--exec "$MDNSD" -- $MDNSD_ARGS
status=$?
if [ "$status" -eq 0 ]; then
echo "OK"
else
echo "FAIL"
fi
return "$status"
}
stop() {
[ -n "$1" ] || printf 'Stopping %s: ' "$DAEMON"
start-stop-daemon -K -q -p "$PIDFILE" -x "$MDNSD"
printf "Stopping %s: " "$DAEMON"
start-stop-daemon --stop --pidfile "$PIDFILE" \
--exec "$MDNSD"
status=$?
if [ "$status" -eq 0 ]; then
echo "OK"
else
echo "FAIL"
return "$status"
fi
# mdnsd deletes its PID file on exit, wait for it to be gone
while [ -f "$PIDFILE" ]; do
sleep 0.1
done
return "$status"
}
restart() {
printf 'Restarting %s: ' "$DAEMON"
stop silent
start silent
stop
start
}
# SIGHUP reloads /etc/mdns.d/*.service
reload() {
printf 'Reloading %s: ' "$DAEMON"
start-stop-daemon -K -s HUP -q -p "$PIDFILE" -x "$MDNSD"
start-stop-daemon --stop --signal HUP -q --pidfile "$PIDFILE" \
--exec "$MDNSD"
status=$?
if [ "$status" -eq 0 ]; then
echo "OK"
else
echo "FAIL"
fi
return "$status"
}
case "$1" in
start|stop|restart|reload)
"$1"
status=$?
if [ "$status" -eq 0 ]; then
echo "OK"
else
echo "FAIL"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
;;
esac
exit "$status"