paranoia: Don't return -1 as PID in error cases

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 <avagin@openvz.org>
This commit is contained in:
Andrey Vagin
2015-03-04 23:22:01 +03:00
parent a72f710d89
commit 872663148e
+4 -1
View File
@@ -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
}