summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2018-10-23 12:27:02 -0500
committerRuben Pollan <meskio@sindominio.net>2018-10-25 14:22:06 -0500
commit2fb1e65d17fba1cbf2d53939abb0e26845894602 (patch)
treefae9cf4e0dd569cb7ba28bc3a0df54cab21be767
parent3425458fa72d26501408db06a47d23542b49c982 (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.go18
1 files changed, 7 insertions, 11 deletions
diff --git a/pid.go b/pid.go
index 3b8e132..2c283ac 100644
--- a/pid.go
+++ b/pid.go
@@ -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())
}