From 872663148e00c4d272fc67e8d369a5012ccbac5a Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Wed, 4 Mar 2015 23:22:01 +0300 Subject: [PATCH] paranoia: Don't return -1 as PID in error cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I have seen a few times, when kill() was called for this value on error paths and nobody survived except the init process. man 2 kill If pid equals -1, then sig is sent to every process for which the call‐ ing process has permission to send signals, except for process 1 (init), but see below. Signed-off-by: Andrey Vagin --- process.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/process.go b/process.go index 1f769abb4..12f90daf7 100644 --- a/process.go +++ b/process.go @@ -3,6 +3,7 @@ package libcontainer import ( "fmt" "io" + "math" "os" ) @@ -54,8 +55,10 @@ func (p Process) Wait() (*os.ProcessState, error) { // Pid returns the process ID func (p Process) Pid() (int, error) { + // math.MinInt32 is returned here, because it's invalid value + // for the kill() system call. if p.ops == nil { - return -1, newGenericError(fmt.Errorf("invalid process"), ProcessNotExecuted) + return math.MinInt32, newGenericError(fmt.Errorf("invalid process"), ProcessNotExecuted) } return p.ops.pid(), nil }