fix: use ps for cross-platform daemon detection
Replace Linux-specific /proc/<pid>/cmdline with ps command for isGasTownDaemon() to work on macOS and Linux. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Steve Yegge
parent
6bfe61f796
commit
b71188d0b4
@@ -1,7 +1,6 @@
|
|||||||
package daemon
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -722,17 +721,16 @@ func IsRunning(townRoot string) (bool, int, error) {
|
|||||||
|
|
||||||
// isGasTownDaemon checks if a PID is actually a gt daemon run process.
|
// isGasTownDaemon checks if a PID is actually a gt daemon run process.
|
||||||
// This prevents false positives from PID reuse.
|
// This prevents false positives from PID reuse.
|
||||||
|
// Uses ps command for cross-platform compatibility (Linux, macOS).
|
||||||
func isGasTownDaemon(pid int) bool {
|
func isGasTownDaemon(pid int) bool {
|
||||||
// Read /proc/<pid>/cmdline to verify process name
|
// Use ps to get command for the PID (works on Linux and macOS)
|
||||||
cmdlineFile := fmt.Sprintf("/proc/%d/cmdline", pid)
|
cmd := exec.Command("ps", "-p", strconv.Itoa(pid), "-o", "command=")
|
||||||
data, err := os.ReadFile(cmdlineFile)
|
output, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmdline is null-separated, convert to space-separated
|
cmdline := strings.TrimSpace(string(output))
|
||||||
cmdline := string(bytes.ReplaceAll(data, []byte{0}, []byte(" ")))
|
|
||||||
cmdline = strings.TrimSpace(cmdline)
|
|
||||||
|
|
||||||
// Check if it's "gt daemon run" or "/path/to/gt daemon run"
|
// Check if it's "gt daemon run" or "/path/to/gt daemon run"
|
||||||
return strings.Contains(cmdline, "gt") && strings.Contains(cmdline, "daemon") && strings.Contains(cmdline, "run")
|
return strings.Contains(cmdline, "gt") && strings.Contains(cmdline, "daemon") && strings.Contains(cmdline, "run")
|
||||||
|
|||||||
Reference in New Issue
Block a user