[Pkg-utopia-maintainers] Bug#876342: avahi-daemon: PID file not removed when avahi-daemon is stopped (due to chroot helper issue), causing a failure when the old PID is reused
Vincent Lefevre
vincent at vinc17.net
Sun Nov 22 01:57:04 GMT 2026
Control: reopen -1
Control: found -1 0.8-18
Control: retitle -1 avahi-daemon: PID file not removed when avahi-daemon is stopped (due to chroot helper issue), causing a failure when the old PID is reused
Reopening since the issue of the stale PID file after avahi-daemon
stops still occurs *every time* avahi-daemon is restarted on both of
my machines (including a recent one) that have avahi-daemon installed
(and an explanation is given by AI -- see at the end), e.g. with
apt install --reinstall avahi-daemon
Here's an example of the logs:
Nov 22 01:48:16 qaa avahi-daemon[1312]: Files changed, reloading.
Nov 22 01:48:16 qaa avahi-daemon[1312]: No service file found in /etc/avahi/services.
Nov 22 01:48:16 qaa avahi-daemon[1312]: Files changed, reloading.
Nov 22 01:48:16 qaa avahi-daemon[1312]: No service file found in /etc/avahi/services.
Nov 22 01:48:16 qaa dbus-daemon[1319]: [system] Reloaded configuration
Nov 22 01:48:16 qaa cups-browsed[87261]: WARNING: Unhandled message: interface=org.freedesktop.DBus, path=/org/freedesktop/DBus, member=ActivatableServicesChanged
Nov 22 01:48:16 qaa dbus-daemon[1319]: [system] Reloaded configuration
Nov 22 01:48:16 qaa cups-browsed[87261]: WARNING: Unhandled message: interface=org.freedesktop.DBus, path=/org/freedesktop/DBus, member=ActivatableServicesChanged
Nov 22 01:48:16 qaa avahi-daemon[1312]: Files changed, reloading.
Nov 22 01:48:16 qaa avahi-daemon[1312]: No service file found in /etc/avahi/services.
Nov 22 01:48:16 qaa dbus-daemon[1319]: [system] Reloaded configuration
Nov 22 01:48:16 qaa cups-browsed[87261]: WARNING: Unhandled message: interface=org.freedesktop.DBus, path=/org/freedesktop/DBus, member=ActivatableServicesChanged
Nov 22 01:48:16 qaa dbus-daemon[1319]: [system] Reloaded configuration
Nov 22 01:48:16 qaa cups-browsed[87261]: WARNING: Unhandled message: interface=org.freedesktop.DBus, path=/org/freedesktop/DBus, member=ActivatableServicesChanged
Nov 22 01:48:16 qaa dbus-daemon[1319]: [system] Reloaded configuration
Nov 22 01:48:16 qaa cups-browsed[87261]: WARNING: Unhandled message: interface=org.freedesktop.DBus, path=/org/freedesktop/DBus, member=ActivatableServicesChanged
Nov 22 01:48:16 qaa dbus-daemon[1319]: [system] Reloaded configuration
Nov 22 01:48:16 qaa cups-browsed[87261]: WARNING: Unhandled message: interface=org.freedesktop.DBus, path=/org/freedesktop/DBus, member=ActivatableServicesChanged
Nov 22 01:48:16 qaa avahi-daemon[1312]: Files changed, reloading.
Nov 22 01:48:16 qaa avahi-daemon[1312]: No service file found in /etc/avahi/services.
Nov 22 01:48:16 qaa avahi-daemon[1312]: Files changed, reloading.
Nov 22 01:48:16 qaa avahi-daemon[1312]: No service file found in /etc/avahi/services.
Nov 22 01:48:16 qaa systemd[1]: Reloading dbus.service - D-Bus System Message Bus...
Nov 22 01:48:16 qaa dbus-daemon[1319]: [system] Reloaded configuration
Nov 22 01:48:16 qaa cups-browsed[87261]: WARNING: Unhandled message: interface=org.freedesktop.DBus, path=/org/freedesktop/DBus, member=ActivatableServicesChanged
Nov 22 01:48:16 qaa dbus-send[96615]: method return time=1795308496.712487 sender=org.freedesktop.DBus -> destination=:1.103 serial=3 reply_serial=2
Nov 22 01:48:16 qaa systemd[1]: Reloaded dbus.service - D-Bus System Message Bus.
Nov 22 01:48:16 qaa systemd[1]: Reload requested from client PID 96636 ('systemctl') (unit session-2.scope)...
Nov 22 01:48:16 qaa systemd[1]: Reloading...
Nov 22 01:48:16 qaa systemd[1]: Reloading finished in 123 ms.
Nov 22 01:48:17 qaa systemd[1]: Stopping avahi-daemon.service - Avahi mDNS/DNS-SD Stack...
Nov 22 01:48:17 qaa avahi-daemon[1312]: Got SIGTERM, quitting.
Nov 22 01:48:17 qaa avahi-daemon[1312]: Leaving mDNS multicast group on interface wlp0s20f3.IPv6 with address 2a02:8424:9d96:6301:3205:5ff:fecb:b7d6.
Nov 22 01:48:17 qaa avahi-daemon[1312]: Leaving mDNS multicast group on interface wlp0s20f3.IPv4 with address 192.168.1.14.
Nov 22 01:48:17 qaa avahi-daemon[1312]: Leaving mDNS multicast group on interface eth0.IPv6 with address 2a02:8424:9d96:6301:26d0:c32:b954:99b1.
Nov 22 01:48:17 qaa avahi-daemon[1312]: Leaving mDNS multicast group on interface eth0.IPv4 with address 192.168.1.13.
Nov 22 01:48:17 qaa avahi-daemon[1312]: Leaving mDNS multicast group on interface lo.IPv6 with address ::1.
Nov 22 01:48:17 qaa avahi-daemon[1312]: Leaving mDNS multicast group on interface lo.IPv4 with address 127.0.0.1.
Nov 22 01:48:17 qaa dbus-daemon[1319]: [system] Activating via systemd: service name='org.freedesktop.Avahi' unit='dbus-org.freedesktop.Avahi.service' requested by ':1.104' (uid=33 pid=87196 comm="/usr/sbin/apache2 -k start -DFOREGROUND")
Nov 22 01:48:17 qaa avahi-daemon[1312]: avahi-daemon 0.8 exiting.
Nov 22 01:48:17 qaa systemd[1]: avahi-daemon.service: Deactivated successfully.
Nov 22 01:48:17 qaa systemd[1]: Stopped avahi-daemon.service - Avahi mDNS/DNS-SD Stack.
Nov 22 01:48:17 qaa systemd[1]: avahi-daemon.socket: Deactivated successfully.
Nov 22 01:48:17 qaa systemd[1]: Closed avahi-daemon.socket - Avahi mDNS/DNS-SD Stack Activation Socket.
Nov 22 01:48:17 qaa systemd[1]: Stopping avahi-daemon.socket - Avahi mDNS/DNS-SD Stack Activation Socket...
Nov 22 01:48:17 qaa systemd[1]: Listening on avahi-daemon.socket - Avahi mDNS/DNS-SD Stack Activation Socket.
Nov 22 01:48:17 qaa systemd[1]: Starting avahi-daemon.service - Avahi mDNS/DNS-SD Stack...
Nov 22 01:48:17 qaa avahi-daemon[96710]: Process 1312 died: No such process; trying to remove PID file. (/run/avahi-daemon//pid)
Nov 22 01:48:17 qaa avahi-daemon[96710]: Found user 'avahi' (UID 106) and group 'avahi' (GID 113).
Nov 22 01:48:17 qaa avahi-daemon[96710]: Successfully dropped root privileges.
Nov 22 01:48:17 qaa avahi-daemon[96710]: avahi-daemon 0.8 starting up.
Nov 22 01:48:17 qaa dbus-daemon[1319]: [system] Successfully activated service 'org.freedesktop.Avahi'
Nov 22 01:48:17 qaa systemd[1]: Started avahi-daemon.service - Avahi mDNS/DNS-SD Stack.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Successfully called chroot().
Nov 22 01:48:17 qaa avahi-daemon[96710]: Successfully dropped remaining capabilities.
Nov 22 01:48:17 qaa avahi-daemon[96710]: No service file found in /etc/avahi/services.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Joining mDNS multicast group on interface wlp0s20f3.IPv6 with address 2a02:8424:9d96:6301:3205:5ff:fecb:b7d6.
Nov 22 01:48:17 qaa avahi-daemon[96710]: New relevant interface wlp0s20f3.IPv6 for mDNS.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Joining mDNS multicast group on interface wlp0s20f3.IPv4 with address 192.168.1.14.
Nov 22 01:48:17 qaa avahi-daemon[96710]: New relevant interface wlp0s20f3.IPv4 for mDNS.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Joining mDNS multicast group on interface eth0.IPv6 with address 2a02:8424:9d96:6301:26d0:c32:b954:99b1.
Nov 22 01:48:17 qaa avahi-daemon[96710]: New relevant interface eth0.IPv6 for mDNS.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Joining mDNS multicast group on interface eth0.IPv4 with address 192.168.1.13.
Nov 22 01:48:17 qaa avahi-daemon[96710]: New relevant interface eth0.IPv4 for mDNS.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Joining mDNS multicast group on interface lo.IPv6 with address ::1.
Nov 22 01:48:17 qaa avahi-daemon[96710]: New relevant interface lo.IPv6 for mDNS.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Joining mDNS multicast group on interface lo.IPv4 with address 127.0.0.1.
Nov 22 01:48:17 qaa avahi-daemon[96710]: New relevant interface lo.IPv4 for mDNS.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Network interface enumeration completed.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Registering new address record for 2a02:8424:9d96:6301:3205:5ff:fecb:b7d6 on wlp0s20f3.*.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Registering new address record for 192.168.1.14 on wlp0s20f3.IPv4.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Registering new address record for 2a02:8424:9d96:6301:26d0:c32:b954:99b1 on eth0.*.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Registering new address record for 192.168.1.13 on eth0.IPv4.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Registering new address record for ::1 on lo.*.
Nov 22 01:48:17 qaa avahi-daemon[96710]: Registering new address record for 127.0.0.1 on lo.IPv4.
Nov 22 01:48:17 qaa dbus-daemon[1319]: [system] Reloaded configuration
Nov 22 01:48:17 qaa cups-browsed[87261]: WARNING: Unhandled message: interface=org.freedesktop.DBus, path=/org/freedesktop/DBus, member=ActivatableServicesChanged
Nov 22 01:48:18 qaa avahi-daemon[96710]: Server startup complete. Host name is qaa.local. Local service cookie is 3599230062.
Nov 22 01:48:18 qaa dbus-daemon[1319]: [system] Activating via systemd: service name='org.freedesktop.PackageKit' unit='packagekit.service' requested by ':1.108' (uid=0 pid=96759 comm="/usr/bin/gdbus call --system --dest org.freedeskto")
Nov 22 01:48:18 qaa systemd[1]: Starting packagekit.service - PackageKit Daemon...
Nov 22 01:48:18 qaa PackageKit[96763]: daemon start
Nov 22 01:48:18 qaa dbus-daemon[1319]: [system] Successfully activated service 'org.freedesktop.PackageKit'
Nov 22 01:48:18 qaa systemd[1]: Started packagekit.service - PackageKit Daemon.
You can see the "avahi-daemon[96710]: Process 1312 died: No such
process; trying to remove PID file. (/run/avahi-daemon//pid)" message.
This issue has been confirmed by other users, and a Google search
on "No such process; trying to remove PID file" (which is the usual
consequence when avahi-daemon restarts) gives 1010 results.
I've looked at the avahi-daemon source. avahi-daemon/main.c has
if ((pid = daemon_pid_file_is_running()) >= 0) {
avahi_log_error("Daemon already running on PID %u", pid);
goto finish;
}
which is the cause of the failure when this old PID corresponds to
a running process (which is quite rare in the case of a restart).
Moreover, according to
https://codesearch.debian.net/search?q=trying+to+remove+PID+file&literal=1
the "trying to remove PID file" error message comes from
libdaemon_0.14-7.1/libdaemon/dpid.c, in the daemon_pid_file_is_running()
function that has been called above:
if (kill(pid, 0) != 0 && errno != EPERM) {
int saved_errno = errno;
daemon_log(LOG_WARNING, "Process %lu died: %s; trying to remove PID file. (%s)", (unsigned long) pid, strerror(errno), fn);
unlink(fn);
errno = saved_errno;
goto finish;
}
So, what happens when avahi-daemon restarts while there is a
stale PID file:
1. avahi-daemon calls daemon_pid_file_is_running().
2. This function gets the PID of the old daemon from the PID file: pid.
3. It then tests: kill(pid, 0) != 0
4a. As the old daemon has just died, there is little chance that a new
process with the same PID is running, so that this test is true and
one gets the "trying to remove PID file." message in the logs.
4b. In rare cases, e.g. if the new daemon gets the same PID as the old
one, the test is false, and daemon_pid_file_is_running() returns
the pid.
5. In case 4b, the (pid = daemon_pid_file_is_running()) >= 0 test is
true and one gets a failure because avahi-daemon thinks that there
is another avahi-daemon running (while this is not the case).
To have a reproducer of the failure due to 4b, ensure that the PID
from the PID file (i.e. the PID of the old daemon) is the PID of a
running process at the time avahi-daemon is started again. This
could be done by writing[*] some well chosen value to
/proc/sys/kernel/ns_last_pid (this might not work 100% of the time,
but if a sufficient number of tries is done, you may get a failure).
[*] https://stackoverflow.com/a/24224902/3782797
Note: If possible, in addition to the ns_last_pid trick, starting
several processes (which should not exit immediately) just after
the old avahi-daemon terminates (and before the new one starts)
would probably yield a good reproducer.
Then, about the stale PID file, I gave logs to Mistral AI, which
confirmed and explained the issue by "Debian's hardening setup":
--------
The previous instance did exit "cleanly" (`avahi-daemon 0.8 exiting.`
after `Got SIGTERM`), yet it failed to delete its own pid file. The
reason is Debian's hardening setup:
1. On Debian, avahi runs with `drop-root` + `use-chroot` defaults.
Note the `Successfully called chroot()` and `Successfully dropped
remaining capabilities` lines: the daemon chroots into `/etc/avahi`
and runs as the unprivileged `avahi` user. It can no longer
`unlink("/run/avahi-daemon/pid")` itself.
2. So the pid-file removal is delegated to the **chroot helper**,
a separate root-privileged process (visible as `avahi-daemon:
chroot helper`), forked at startup and contacted over a socketpair.
In `main.c`'s exit path, `avahi_chroot_helper_unlink()` sends an
UNLINK command to that helper.
3. When systemd stops the unit, `SIGTERM` is delivered to *all*
processes in the cgroup at once (`KillMode=control-group`, the
default). The main daemon has a SIGTERM handler and spends a moment
shutting down gracefully (leaving multicast groups etc.). The helper
has **no signal handler**, so it dies immediately on SIGTERM.
4. By the time the daemon reaches its cleanup and writes the unlink
command, the helper is gone. The write fails with `EPIPE`, but the
code explicitly treats that as success: in `avahi_chroot_helper_unlink()`,
errors are ignored when `errno == EPIPE || errno == ECONNRESET`. Nothing
is logged, and `/run/avahi-daemon/pid` survives. (If the helper fd were
already closed, the fallback `unlink()` would run *inside the chroot*,
targeting a path that does not exist there, and fail silently too.)
--------
Indeed, I can see 2 avahi-daemon processes, including a chroot helper:
avahi-daemon: running [qaa.local]
avahi-daemon: chroot helper
--
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)
More information about the Pkg-utopia-maintainers
mailing list