From fcbf19f04d83717a95c6e11c5f8d959b303e6dee Mon Sep 17 00:00:00 2001 From: mingqing Date: Thu, 14 Jan 2016 15:43:40 +0800 Subject: [PATCH] fix pidfile, pid is num use '/proc + string(pid)' can't found it Signed-off-by: mingqing --- pidfile/pidfile.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pidfile/pidfile.go b/pidfile/pidfile.go index db3535b..58cc401 100644 --- a/pidfile/pidfile.go +++ b/pidfile/pidfile.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" "strconv" + "strings" ) // PIDFile is a file used to store the process ID of a running process. @@ -17,9 +18,10 @@ type PIDFile struct { } func checkPIDFileAlreadyExists(path string) error { - if pidString, err := ioutil.ReadFile(path); err == nil { - if pid, err := strconv.Atoi(string(pidString)); err == nil { - if _, err := os.Stat(filepath.Join("/proc", string(pid))); err == nil { + if pidByte, err := ioutil.ReadFile(path); err == nil { + pidString := strings.TrimSpace(string(pidByte)) + if pid, err := strconv.Atoi(pidString); err == nil { + if _, err := os.Stat(filepath.Join("/proc", strconv.Itoa(pid))); err == nil { return fmt.Errorf("pid file found, ensure docker is not running or delete %s", path) } }