From a8f148b8e4098eaeb80e1d704b64aab8aeb1294f Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Tue, 25 Jun 2019 11:46:19 -0700 Subject: Use different Ctty FDs based on the go version. An upcoming change in Go 1.13 [1] changes the semantics of the SysProcAttr.Ctty field. Prior to the change, the FD must be an FD in the child process's FD table (aka "post-shuffle"). After the change, the FD must be an FD in the current process's FD table (aka "pre-shuffle"). To be compatible with both versions this CL introduces a new boolean "CttyFdIsPostShuffle" which indicates whether a pre- or post-shuffle FD should be provided. We use build tags to chose the correct one. 1: https://go-review.googlesource.com/c/go/+/178919/ PiperOrigin-RevId: 255015303 --- runsc/cmd/exec.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'runsc/cmd') diff --git a/runsc/cmd/exec.go b/runsc/cmd/exec.go index 7adc23a77..5a823e89a 100644 --- a/runsc/cmd/exec.go +++ b/runsc/cmd/exec.go @@ -237,6 +237,16 @@ func (ex *Exec) execChildAndWait(waitStatus *syscall.WaitStatus) subcommands.Exi Setctty: true, Ctty: int(tty.Fd()), } + // TODO(b/133868570): Delete this check once Go 1.12 is no + // longer supported. + if console.CttyFdIsPostShuffle { + // In go1.12 and before, the Ctty FD must be the FD in + // the child process's FD table. Since we set + // cmd.Stdin/Stdout/Stderr to the tty FD, we can use + // any of 0, 1, or 2 here. + cmd.SysProcAttr.Ctty = 0 + } + } if err := cmd.Start(); err != nil { -- cgit v1.2.3