Pass pipes into Exec function

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-02-21 16:28:43 -08:00
parent b9bc36a8bb
commit b3d2325c5f
2 changed files with 10 additions and 8 deletions

View file

@ -19,7 +19,7 @@ import (
// Exec performes setup outside of a namespace so that a container can be // Exec performes setup outside of a namespace so that a container can be
// executed. Exec is a high level function for working with container namespaces. // executed. Exec is a high level function for working with container namespaces.
func Exec(container *libcontainer.Container, logFile string, args []string) (int, error) { func Exec(container *libcontainer.Container, stdin io.Reader, stdout, stderr io.Writer, logFile string, args []string) (int, error) {
var ( var (
master *os.File master *os.File
console string console string
@ -97,23 +97,23 @@ func Exec(container *libcontainer.Container, logFile string, args []string) (int
if container.Tty { if container.Tty {
log.Printf("starting copy for tty") log.Printf("starting copy for tty")
go io.Copy(os.Stdout, master) go io.Copy(stdout, master)
go io.Copy(master, os.Stdin) go io.Copy(master, stdin)
state, err := setupWindow(master) state, err := setupWindow(master)
if err != nil { if err != nil {
command.Process.Kill() command.Process.Kill()
return -1, err return -1, err
} }
defer term.RestoreTerminal(os.Stdin.Fd(), state) defer term.RestoreTerminal(uintptr(syscall.Stdin), state)
} else { } else {
log.Printf("starting copy for std pipes") log.Printf("starting copy for std pipes")
go func() { go func() {
defer inPipe.Close() defer inPipe.Close()
io.Copy(inPipe, os.Stdin) io.Copy(inPipe, stdin)
}() }()
go io.Copy(os.Stdout, outPipe) go io.Copy(stdout, outPipe)
go io.Copy(os.Stderr, errPipe) go io.Copy(stderr, errPipe)
} }
log.Printf("waiting on process") log.Printf("waiting on process")

View file

@ -57,7 +57,9 @@ func main() {
if nspid > 0 { if nspid > 0 {
exitCode, err = nsinit.ExecIn(container, nspid, flag.Args()[1:]) exitCode, err = nsinit.ExecIn(container, nspid, flag.Args()[1:])
} else { } else {
exitCode, err = nsinit.Exec(container, logFile, flag.Args()[1:]) exitCode, err = nsinit.Exec(container,
os.Stdin, os.Stdout, os.Stderr,
logFile, flag.Args()[1:])
} }
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)