diff options
author | Ruben Pollan <meskio@sindominio.net> | 2018-10-23 12:27:02 -0500 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2018-10-25 14:22:06 -0500 |
commit | 2fb1e65d17fba1cbf2d53939abb0e26845894602 (patch) | |
tree | fae9cf4e0dd569cb7ba28bc3a0df54cab21be767 | |
parent | 3425458fa72d26501408db06a47d23542b49c982 (diff) |
[bug] check the process name to see if the pid file is valid
When there is a pid file from a previous crash, in some situations the
pid has being reused by the operative system for other processes.
Let's check that the exectuable name maches the name of the systray
binary.
- Resolves: #50
-rw-r--r-- | pid.go | 18 |
1 files changed, 7 insertions, 11 deletions
@@ -6,11 +6,12 @@ import ( "log" "os" "path/filepath" - "runtime" "strconv" + "strings" "syscall" "0xacab.org/leap/bitmask-systray/bitmask" + "github.com/mitchellh/go-ps" ) var pidFile = filepath.Join(bitmask.ConfigPath, "systray.pid") @@ -85,19 +86,14 @@ func pidRunning(pid int) bool { if pid == 0 { return false } - - proc, err := os.FindProcess(pid) - if runtime.GOOS == "windows" { - return err == nil - } - + proc, err := ps.FindProcess(pid) if err != nil { log.Printf("An error ocurred finding process: %v", err) return false } - err = proc.Signal(syscall.Signal(0)) - if err == nil { - return true + if proc == nil { + return false } - return false + log.Printf("There is a running process with the pid %d and executable: %s", pid, proc.Executable()) + return strings.Contains(os.Args[0], proc.Executable()) } |