fix: verify /proc/PID/cmdline in isRinging to prevent PID reuse false positives
This commit is contained in:
+6
-3
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user