mirror of
https://github.com/rancher/os.git
synced 2025-09-01 23:04:41 +00:00
migrate to upstream libcompose in one and a half go
This commit is contained in:
23
vendor/github.com/opencontainers/runc/tty.go
generated
vendored
23
vendor/github.com/opencontainers/runc/tty.go
generated
vendored
@@ -3,8 +3,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/docker/pkg/term"
|
||||
"github.com/opencontainers/runc/libcontainer"
|
||||
@@ -17,34 +19,45 @@ func newTty(create bool, p *libcontainer.Process, rootuid int) (*tty, error) {
|
||||
if create {
|
||||
return createTty(p, rootuid)
|
||||
}
|
||||
return createStdioPipes(p)
|
||||
return createStdioPipes(p, rootuid)
|
||||
}
|
||||
|
||||
// setup standard pipes so that the TTY of the calling runc process
|
||||
// is not inherited by the container.
|
||||
func createStdioPipes(p *libcontainer.Process) (*tty, error) {
|
||||
t := &tty{}
|
||||
func createStdioPipes(p *libcontainer.Process, rootuid int) (*tty, error) {
|
||||
var (
|
||||
t = &tty{}
|
||||
fds []int
|
||||
)
|
||||
r, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fds = append(fds, int(r.Fd()), int(w.Fd()))
|
||||
go io.Copy(w, os.Stdin)
|
||||
t.closers = append(t.closers, w)
|
||||
p.Stdin = r
|
||||
if r, w, err = os.Pipe(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fds = append(fds, int(r.Fd()), int(w.Fd()))
|
||||
go io.Copy(os.Stdout, r)
|
||||
p.Stdout = w
|
||||
t.closers = append(t.closers, r)
|
||||
if r, w, err = os.Pipe(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fds = append(fds, int(r.Fd()), int(w.Fd()))
|
||||
go io.Copy(os.Stderr, r)
|
||||
p.Stderr = w
|
||||
t.closers = append(t.closers, r)
|
||||
// change the ownership of the pipe fds incase we are in a user namespace.
|
||||
for _, fd := range fds {
|
||||
if err := syscall.Fchown(fd, rootuid, rootuid); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return t, nil
|
||||
|
||||
}
|
||||
|
||||
func createTty(p *libcontainer.Process, rootuid int) (*tty, error) {
|
||||
@@ -56,7 +69,7 @@ func createTty(p *libcontainer.Process, rootuid int) (*tty, error) {
|
||||
go io.Copy(os.Stdout, console)
|
||||
state, err := term.SetRawTerminal(os.Stdin.Fd())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("failed to set the terminal from the stdin: %v", err)
|
||||
}
|
||||
t := &tty{
|
||||
console: console,
|
||||
|
Reference in New Issue
Block a user