Skip to content

service.sh: ignore a stale scheduler pid from a previous boot - #25

Open
Solomag wants to merge 2 commits into
VD171:mainfrom
Solomag:fix/service-stale-pid-guard
Open

Solomag wants to merge 2 commits into
VD171:mainfrom
Solomag:fix/service-stale-pid-guard

Conversation

@Solomag

@Solomag Solomag commented Nov 20, 2026 •

Copy link
Copy Markdown

What

service.sh can silently skip the scheduler loop and the VDLU boot update after a reboot, because its single-instance guard trusts a stale pid.

The guard is kill -0 "$(cat scheduler.loop.pid)". The pid file lives in /data/adb/vdbackup/logs/ and survives reboots, and Android reuses pids quickly. In my test the stored pid was alive again as an unrelated system app, so kill -0 succeeded and service.sh exited at the guard: the scheduler loop was not started, and the VDLU boot block below the guard never ran (pid file untouched, vdlu/boot.log empty, no update after 7+ minutes).

This PR records the boot_id (/proc/sys/kernel/random/boot_id) in scheduler.loop.boot next to the pid and only treats the pid as a live loop when it was written during the current boot. Behaviour within one boot is unchanged. If boot_id is unreadable, both sides are empty and the guard behaves as before.

Context: VD171/VD-Modules#1

Checklist

  • The project banner header is present on every new/changed source file.
  • Code and comments are in English; no em/en-dashes.
  • If a UI label changed, all lang/<code>.json and README.<code>.md were updated (no UI change).
  • No real feature (SELinux/uid-gid/modes preservation, etc.) was weakened.
  • Commits are signed off (git commit -s).
  • Tested on a rooted device/emulator (note which): the guard logic was tested in a sandbox on a rooted Android device (KernelSU). Stale pid reused by a live process: old guard says "already running", new guard continues; genuine loop of the current boot: new guard exits. I did not reboot with the patched service.sh installed, so the full boot path is untested.

Notes

uninstall.sh also did kill "$(cat scheduler.loop.pid)" with the same stale-pid exposure (after a reboot it could signal an unrelated process). The second commit applies the same boot_id check there: it only signals the pid when scheduler.loop.boot matches the current boot, and removes the marker on uninstall. If the marker is missing (loop started by an older version), it simply does not kill and the loop ends at the next reboot, which the existing comment already accepts. Syntax-checked with sh -n only.

The single-instance guard used a bare kill -0 on the pid stored in
scheduler.loop.pid. That file survives a reboot and Android reuses pids
quickly, so the stored pid can belong to an unrelated live process. The
guard then exits before the scheduler loop and the VDLU boot update.

Record the boot_id next to the pid and only trust the pid when it was
written during the current boot.

Signed-off-by: Solomag <33348398+Solomag@users.noreply.github.com>
Same stale-pid exposure as service.sh: after a reboot the pid file can
point at an unrelated live process. Compare scheduler.loop.boot with the
current boot_id before signalling, and clean the marker on uninstall.

Signed-off-by: Solomag <33348398+Solomag@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant