Fixed IO edge cases on docker client. Wait for stdin to close before exiting if it's a pipe, but not if it's a terminal. Correctly send stdin EOF to the server with TCP half-close

This commit is contained in:
Solomon Hykes 2013-01-25 11:26:18 -08:00
parent 401dd3d8e0
commit 75529a202f
1 changed files with 19 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"github.com/dotcloud/docker/rcli" "github.com/dotcloud/docker/rcli"
"github.com/dotcloud/docker/future"
"io" "io"
"log" "log"
"os" "os"
@ -174,15 +175,25 @@ func main() {
if err != nil { if err != nil {
Fatal(err) Fatal(err)
} }
go func() { receive_stdout := future.Go(func() error {
if _, err := io.Copy(os.Stdout, conn); err != nil { _, err := io.Copy(os.Stdout, conn)
Fatal(err) return err
})
send_stdin := future.Go(func() error {
_, err := io.Copy(conn, os.Stdin)
if err := conn.CloseWrite(); err != nil {
log.Printf("Couldn't send EOF: " + err.Error())
} }
Restore(0, oldState) return err
os.Exit(0) })
}() if err := <-receive_stdout; err != nil {
if _, err := io.Copy(conn, os.Stdin); err != nil {
Fatal(err) Fatal(err)
} }
Restore(0, oldState) if IsTerminal(0) {
Restore(0, oldState)
} else {
if err := <-send_stdin; err != nil {
Fatal(err)
}
}
} }