mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
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:
+4
-1
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user