From b56aa0658a308a2cd69861a4872ee61fb3838675 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Tue, 15 Jul 2014 18:24:15 -0700 Subject: [PATCH] Don't open slave in parent Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- namespaces/exec.go | 13 +++++-------- nsinit/exec.go | 28 +++++++++++++--------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/namespaces/exec.go b/namespaces/exec.go index 1359dfb8b..6f3838fd2 100644 --- a/namespaces/exec.go +++ b/namespaces/exec.go @@ -21,10 +21,9 @@ import ( // Move this to libcontainer package. // Exec performs 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.Config, stdin io.Reader, stdout, stderr io.Writer, rootfs, dataPath string, args []string, createCommand CreateCommand, startCallback func()) (int, error) { +func Exec(container *libcontainer.Config, stdin io.Reader, stdout, stderr io.Writer, console string, rootfs, dataPath string, args []string, createCommand CreateCommand, startCallback func()) (int, error) { var ( - console string - err error + err error ) // create a pipe so that we can syncronize with the namespaced process and @@ -35,12 +34,10 @@ func Exec(container *libcontainer.Config, stdin io.Reader, stdout, stderr io.Wri } defer syncPipe.Close() - if f, ok := stdin.(*os.File); ok { - console = f.Name() - } - command := createCommand(container, console, rootfs, dataPath, os.Args[0], syncPipe.Child(), args) - + // Note: these are only used in non-tty mode + // if there is a tty for the container it will be opened within the namespace and the + // fds will be duped to stdin, stdiout, and stderr command.Stdin = stdin command.Stdout = stdout command.Stderr = stderr diff --git a/nsinit/exec.go b/nsinit/exec.go index fac057f69..690af5f5e 100644 --- a/nsinit/exec.go +++ b/nsinit/exec.go @@ -69,27 +69,25 @@ func startContainer(container *libcontainer.Config, dataPath string, args []stri } var ( - master *os.File - slavePath string - err error - stdin = os.Stdin - stdout = os.Stdout - stderr = os.Stderr + master *os.File + console string + err error + + stdin = os.Stdin + stdout = os.Stdout + stderr = os.Stderr ) if container.Tty { - master, slavePath, err = consolepkg.CreateMasterAndConsole() + stdin = nil + stdout = nil + stderr = nil + + master, console, err = consolepkg.CreateMasterAndConsole() if err != nil { return -1, err } - slave, err := consolepkg.OpenTerminal(slavePath, syscall.O_RDWR|syscall.O_NOCTTY) - if err != nil { - return -1, err - } - - stdin, stdout, stderr = slave, slave, slave - go io.Copy(master, os.Stdin) go io.Copy(os.Stdout, master) @@ -116,7 +114,7 @@ func startContainer(container *libcontainer.Config, dataPath string, args []stri }() } - return namespaces.Exec(container, stdin, stdout, stderr, "", dataPath, args, createCommand, startCallback) + return namespaces.Exec(container, stdin, stdout, stderr, console, "", dataPath, args, createCommand, startCallback) } func resizeTty(master *os.File) {