Maybe logic flaw causing concurrency issue with startup and signal handling
Observation:
In Debian Bullseye/Bookworm virtual machines with single CPU, xdm, cron, logrotate installed, xdm fails with about 10% rate on startup. System logs show, that xdm startup and logrotate startup were activated by systemd at the same time. xdm seems to have created a pid file and touched xdm.log when logrotate moves xdm.log away and sends SIGUSR2 to trigger logrotation.
Logrotate does:
postrotate
if [ -r /var/run/xdm.pid ]; then \
kill -s USR2 $(cat /var/run/xdm.pid); \
fi
endscript
Systemd reports:
Oct 15 11:45:12 localhost systemd[1]: xdm.service: Main process exited, code=killed, status=12/USR2
Oct 15 11:45:12 localhost systemd[1]: xdm.service: Failed with result 'signal'.
Hypothetical cause:
According to
https://gitlab.freedesktop.org/xorg/app/xdm/-/blob/master/xdm/dm.c?ref_type=heads
main function
159 if ((oldpid = StorePid ()))
creates the pid but the signal handler is only installed later on in
246 StartDisplays ();
via calling StartServer and StartServerOnce.
Therefore logrotate may send the signal after the pidfile is ready but before the signal handler was setup correctly.
Due to the nature of the issue, the concurrency problem is a little tricky to debug. Can therefore someone with xdm design knowledge confirm, that my interpretation of the xdm code and reasoning is correct and signal handler setup is really done after pid file writing?