From 13217f52f8ab7e9db53a1a91b2d5832f1c736cb8 Mon Sep 17 00:00:00 2001 From: burakgizlice Date: Mon, 16 Feb 2026 09:50:55 +0300 Subject: [PATCH] fix: detect stale PID files from recycled PIDs The daemon startup check only used kill -0 to verify if the PID from the PID file was alive. If the OS recycled that PID for an unrelated process, hyprvoice would refuse to start with "daemon already running" even though no hyprvoice instance was running. Now also reads /proc//cmdline to verify the process is actually hyprvoice before treating it as a running daemon. If it's a different process, the PID file is treated as stale and removed. Co-Authored-By: Claude Opus 4.6 --- internal/bus/bus.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/bus/bus.go b/internal/bus/bus.go index 7f87dbc..9b4d2f5 100644 --- a/internal/bus/bus.go +++ b/internal/bus/bus.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "strconv" + "strings" "syscall" ) @@ -99,6 +100,19 @@ func (pm *pidManager) isProcessAlive(pid int) bool { return false } + // Verify the process is actually hyprvoice and not a recycled PID + cmdline, err := os.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid)) + if err != nil { + log.Printf("Process %d alive but cannot read cmdline, assuming stale: %v", pid, err) + return false + } + + exe := string(cmdline) + if len(exe) == 0 || !strings.Contains(exe, "hyprvoice") { + log.Printf("Process %d is alive but is not hyprvoice (cmdline: %q), stale PID file", pid, exe) + return false + } + return true }