From 619fbf6951b82c7899c13b16e85b85310d567258 Mon Sep 17 00:00:00 2001 From: ash-iir <254348575+ash-iir@users.noreply.github.com> Date: Thu, 19 Nov 2026 11:38:10 +0000 Subject: [PATCH] service: don't trust a stale scheduler pid after reboot The pid file survives reboot. When its pid was reused by another process, kill -0 succeeded and the scheduler loop never started for that boot. Match the loop's own command line, which carries the pid file path. Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com> --- module/service.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/module/service.sh b/module/service.sh index 3cbdf1f..70e03ad 100644 --- a/module/service.sh +++ b/module/service.sh @@ -48,8 +48,13 @@ mkdir -p "$LOGS" # honour the skip flag [ -f "$MODDIR/.scheduler.skip" ] && exit 0 -# single-instance guard: bail out if a scheduler loop is already alive -if [ -f "$LOOPPID" ] && kill -0 "$(cat "$LOOPPID" 2>/dev/null)" 2>/dev/null; then exit 0; fi +# single-instance guard: bail out if a scheduler loop is already alive. The pid file +# survives reboot and its pid can be reused by another process, so match the loop's +# own command line (it carries $LOOPPID) instead of trusting kill -0. +_lp="$(cat "$LOOPPID" 2>/dev/null)" +case "$_lp" in ''|*[!0-9]*) : ;; *) + case "$(tr '\0' ' ' < "/proc/$_lp/cmdline" 2>/dev/null)" in *"$LOOPPID"*) exit 0 ;; esac ;; +esac # recurring, detached heartbeat (survives boot, never blocks it): the loop # records its own pid for the guard, then runs scheduler-tick every INTERVAL.