Don't open slave in parent

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@docker.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby
2014-07-15 18:24:15 -07:00
parent 18e12838d6
commit b56aa0658a
2 changed files with 18 additions and 23 deletions
+5 -8
View File
@@ -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
+13 -15
View File
@@ -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) {