Pass pipes into Exec function
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
782da799f8
commit
6ee2801819
|
@ -19,7 +19,7 @@ import (
|
|||
|
||||
// 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.
|
||||
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 (
|
||||
master *os.File
|
||||
console string
|
||||
|
@ -97,23 +97,23 @@ func Exec(container *libcontainer.Container, logFile string, args []string) (int
|
|||
|
||||
if container.Tty {
|
||||
log.Printf("starting copy for tty")
|
||||
go io.Copy(os.Stdout, master)
|
||||
go io.Copy(master, os.Stdin)
|
||||
go io.Copy(stdout, master)
|
||||
go io.Copy(master, stdin)
|
||||
|
||||
state, err := setupWindow(master)
|
||||
if err != nil {
|
||||
command.Process.Kill()
|
||||
return -1, err
|
||||
}
|
||||
defer term.RestoreTerminal(os.Stdin.Fd(), state)
|
||||
defer term.RestoreTerminal(uintptr(syscall.Stdin), state)
|
||||
} else {
|
||||
log.Printf("starting copy for std pipes")
|
||||
go func() {
|
||||
defer inPipe.Close()
|
||||
io.Copy(inPipe, os.Stdin)
|
||||
io.Copy(inPipe, stdin)
|
||||
}()
|
||||
go io.Copy(os.Stdout, outPipe)
|
||||
go io.Copy(os.Stderr, errPipe)
|
||||
go io.Copy(stdout, outPipe)
|
||||
go io.Copy(stderr, errPipe)
|
||||
}
|
||||
|
||||
log.Printf("waiting on process")
|
||||
|
|
|
@ -57,7 +57,9 @@ func main() {
|
|||
if nspid > 0 {
|
||||
exitCode, err = nsinit.ExecIn(container, nspid, flag.Args()[1:])
|
||||
} 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 {
|
||||
log.Fatal(err)
|
||||
|
|
Loading…
Reference in New Issue