mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-06-21 12:09:31 -04:00
zmdc wrote ZM_PID only once at startup and removed it only at shutdown, so if the pid file was removed out-of-band while the daemon kept running (a partial/aborted stop that orphaned it, or /run tmpfiles cleanup), systemd (Type=forking, PIDFile=) lost its handle: the service showed dead/failed, stop no-op'd the orphaned tree, and start failed because ZM was already up. Add ensure_pid(), called each iteration of the main server loop, which rewrites ZM_PID only when it is missing or its contents do not match our pid. Shutdown-safe: the shutdown unlink runs only after the loop exits. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>