diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index d9d8acfd25..2e8b3e5580 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -1428,6 +1428,14 @@ int dns_scope_announce(DnsScope *scope, bool goodbye) { if (scope->protocol != DNS_PROTOCOL_MDNS) return 0; + r = sd_event_get_state(scope->manager->event); + if (r < 0) + return log_debug_errno(r, "Failed to get event loop state: %m"); + + /* If this is called on exit, through manager_free() -> link_free(), then we cannot announce. */ + if (r == SD_EVENT_FINISHED) + return 0; + /* Check if we're done with probing. */ LIST_FOREACH(transactions_by_scope, t, scope->transactions) if (t->probing && DNS_TRANSACTION_IS_LIVE(t->state)) diff --git a/test/units/testsuite-75.sh b/test/units/testsuite-75.sh index 064dd3807a..5dc31f8baa 100755 --- a/test/units/testsuite-75.sh +++ b/test/units/testsuite-75.sh @@ -43,6 +43,13 @@ monitor_check_rr() ( timeout -v 30s journalctl -u resolvectl-monitor.service --since "$since" -f --full | grep -m1 "$match" ) +restart_resolved() { + systemctl stop systemd-resolved.service + (! systemctl is-failed systemd-resolved.service) + systemctl start systemd-resolved.service + systemctl service-log-level systemd-resolved.service debug +} + # Test for resolvectl, resolvconf systemctl unmask systemd-resolved.service systemctl enable --now systemd-resolved.service @@ -89,8 +96,7 @@ mkdir -p /run/systemd/resolved.conf.d echo "MulticastDNS=yes" echo "LLMNR=yes" } >/run/systemd/resolved.conf.d/mdns-llmnr.conf -systemctl restart systemd-resolved.service -systemctl service-log-level systemd-resolved.service debug +restart_resolved # make sure networkd is not running. systemctl stop systemd-networkd.service # defaults to yes (both the global and per-link settings are yes) @@ -115,8 +121,7 @@ assert_in 'no' "$(resolvectl llmnr hoge)" echo "MulticastDNS=resolve" echo "LLMNR=resolve" } >/run/systemd/resolved.conf.d/mdns-llmnr.conf -systemctl restart systemd-resolved.service -systemctl service-log-level systemd-resolved.service debug +restart_resolved # set per-link setting resolvectl mdns hoge yes resolvectl llmnr hoge yes @@ -136,8 +141,7 @@ assert_in 'no' "$(resolvectl llmnr hoge)" echo "MulticastDNS=no" echo "LLMNR=no" } >/run/systemd/resolved.conf.d/mdns-llmnr.conf -systemctl restart systemd-resolved.service -systemctl service-log-level systemd-resolved.service debug +restart_resolved # set per-link setting resolvectl mdns hoge yes resolvectl llmnr hoge yes @@ -222,7 +226,7 @@ ln -svf /etc/bind.keys /etc/bind/bind.keys # Start the services systemctl unmask systemd-networkd systemctl start systemd-networkd -systemctl restart systemd-resolved +restart_resolved # Create knot's runtime dir, since from certain version it's provided only by # the package and not created by tmpfiles/systemd if [[ ! -d /run/knot ]]; then @@ -587,8 +591,7 @@ if command -v nft >/dev/null; then echo "StaleRetentionSec=1d" } >/run/systemd/resolved.conf.d/test.conf ln -svf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf - systemctl restart systemd-resolved.service - systemctl service-log-level systemd-resolved.service debug + restart_resolved run dig stale1.unsigned.test -t A grep -qE "NOERROR" "$RUN_OUT" @@ -711,4 +714,7 @@ run resolvectl reset-statistics --json=pretty run resolvectl reset-statistics --json=short +# Check if resolved exits cleanly. +restart_resolved + touch /testok