Merge pull request #11202 from coolljt0725/fix_start_hijacked

Fix start container failed hijack the stdin of terminal
This commit is contained in:
Phil Estes 2015-03-06 13:48:02 -05:00
commit cfe5767045
1 changed files with 11 additions and 8 deletions

View File

@ -712,6 +712,16 @@ func (cli *DockerCli) CmdStart(args ...string) error {
utils.ParseFlags(cmd, args, true) utils.ParseFlags(cmd, args, true)
hijacked := make(chan io.Closer) hijacked := make(chan io.Closer)
// Block the return until the chan gets closed
defer func() {
log.Debugf("CmdStart() returned, defer waiting for hijack to finish.")
if _, ok := <-hijacked; ok {
log.Errorf("Hijack did not finish (chan still open)")
}
if *openStdin || *attach {
cli.in.Close()
}
}()
if *attach || *openStdin { if *attach || *openStdin {
if cmd.NArg() > 1 { if cmd.NArg() > 1 {
@ -769,26 +779,19 @@ func (cli *DockerCli) CmdStart(args ...string) error {
} }
} }
var encounteredError error
for _, name := range cmd.Args() { for _, name := range cmd.Args() {
_, _, err := readBody(cli.call("POST", "/containers/"+name+"/start", nil, false)) _, _, err := readBody(cli.call("POST", "/containers/"+name+"/start", nil, false))
if err != nil { if err != nil {
if !*attach && !*openStdin { if !*attach && !*openStdin {
fmt.Fprintf(cli.err, "%s\n", err) fmt.Fprintf(cli.err, "%s\n", err)
} }
encounteredError = fmt.Errorf("Error: failed to start one or more containers") return fmt.Errorf("Error: failed to start one or more containers")
} else { } else {
if !*attach && !*openStdin { if !*attach && !*openStdin {
fmt.Fprintf(cli.out, "%s\n", name) fmt.Fprintf(cli.out, "%s\n", name)
} }
} }
} }
if encounteredError != nil {
if *openStdin || *attach {
cli.in.Close()
}
return encounteredError
}
if *openStdin || *attach { if *openStdin || *attach {
if tty && cli.isTerminalOut { if tty && cli.isTerminalOut {