fix: verify /proc/PID/cmdline in isRinging to prevent PID reuse false positives

This commit is contained in:
2026-06-18 16:45:52 +02:00
parent b62a1d10c1
commit 1a8e4e2186
2 changed files with 34 additions and 4 deletions
+6 -3
View File
@@ -19,12 +19,15 @@ def is_wecker_ringing() -> bool:
if not os.path.exists(PID_FILE):
return False
try:
pid: int
with open(PID_FILE) as f:
pid = int(f.read().strip())
os.kill(pid, 0)
return True
except (ValueError, ProcessLookupError, PermissionError, OSError):
# Guard against PID reuse: verify the running process is actually wecker.py.
cmdline_path = f"/proc/{pid}/cmdline"
with open(cmdline_path, "rb") as f:
cmdline = f.read().replace(b"\0", b" ").decode()
return "wecker.py" in cmdline
except (ValueError, ProcessLookupError, PermissionError, OSError, FileNotFoundError):
return False