mirror of https://github.com/docker/docs.git
Move setup pty and standard pipes to funcs
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
1e81387edc
commit
8a38ead219
35
container.go
35
container.go
|
@ -308,10 +308,10 @@ func (container *Container) generateLXCConfig() error {
|
||||||
return LxcTemplateCompiled.Execute(fo, container)
|
return LxcTemplateCompiled.Execute(fo, container)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) startPty(startCallback execdriver.StartCallback) (int, error) {
|
func (container *Container) setupPty() error {
|
||||||
ptyMaster, ptySlave, err := pty.Open()
|
ptyMaster, ptySlave, err := pty.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return err
|
||||||
}
|
}
|
||||||
container.ptyMaster = ptyMaster
|
container.ptyMaster = ptyMaster
|
||||||
container.process.Stdout = ptySlave
|
container.process.Stdout = ptySlave
|
||||||
|
@ -336,17 +336,16 @@ func (container *Container) startPty(startCallback execdriver.StartCallback) (in
|
||||||
utils.Debugf("startPty: end of stdin pipe")
|
utils.Debugf("startPty: end of stdin pipe")
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
return container.runtime.Run(container, startCallback)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) start(startCallback execdriver.StartCallback) (int, error) {
|
func (container *Container) setupStd() error {
|
||||||
container.process.Stdout = container.stdout
|
container.process.Stdout = container.stdout
|
||||||
container.process.Stderr = container.stderr
|
container.process.Stderr = container.stderr
|
||||||
if container.Config.OpenStdin {
|
if container.Config.OpenStdin {
|
||||||
stdin, err := container.process.StdinPipe()
|
stdin, err := container.process.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return err
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
defer stdin.Close()
|
defer stdin.Close()
|
||||||
|
@ -355,7 +354,7 @@ func (container *Container) start(startCallback execdriver.StartCallback) (int,
|
||||||
utils.Debugf("start: end of stdin pipe")
|
utils.Debugf("start: end of stdin pipe")
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
return container.runtime.Run(container, startCallback)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, stdout io.Writer, stderr io.Writer) chan error {
|
func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, stdout io.Writer, stderr io.Writer) chan error {
|
||||||
|
@ -697,12 +696,24 @@ func (container *Container) Start() (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
container.waitLock = make(chan struct{})
|
container.waitLock = make(chan struct{})
|
||||||
container.State.SetRunning(0)
|
|
||||||
|
// Setup pipes
|
||||||
|
if container.Config.Tty {
|
||||||
|
err = container.setupPty()
|
||||||
|
} else {
|
||||||
|
err = container.setupStd()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
waitLock := make(chan struct{})
|
waitLock := make(chan struct{})
|
||||||
f := func(process *execdriver.Process) {
|
f := func(process *execdriver.Process) {
|
||||||
container.State.SetRunning(process.Pid())
|
container.State.SetRunning(process.Pid())
|
||||||
if process.Tty {
|
if process.Tty {
|
||||||
|
// The callback is called after the process Start()
|
||||||
|
// so we are in the parent process. In TTY mode, stdin/out/err is the PtySlace
|
||||||
|
// which we close here.
|
||||||
if c, ok := process.Stdout.(io.Closer); ok {
|
if c, ok := process.Stdout.(io.Closer); ok {
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
|
@ -1091,7 +1102,7 @@ func (container *Container) releaseNetwork() {
|
||||||
container.NetworkSettings = &NetworkSettings{}
|
container.NetworkSettings = &NetworkSettings{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) monitor(f execdriver.StartCallback) {
|
func (container *Container) monitor(callback execdriver.StartCallback) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
exitCode int
|
exitCode int
|
||||||
|
@ -1101,11 +1112,7 @@ func (container *Container) monitor(f execdriver.StartCallback) {
|
||||||
// This happends when you have a GHOST container with lxc
|
// This happends when you have a GHOST container with lxc
|
||||||
err = container.runtime.Wait(container, 0)
|
err = container.runtime.Wait(container, 0)
|
||||||
} else {
|
} else {
|
||||||
if container.Config.Tty {
|
exitCode, err = container.runtime.Run(container, callback)
|
||||||
exitCode, err = container.startPty(f)
|
|
||||||
} else {
|
|
||||||
exitCode, err = container.start(f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil { //TODO: @crosbymichael @creack report error
|
if err != nil { //TODO: @crosbymichael @creack report error
|
||||||
|
|
Loading…
Reference in New Issue