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:
parent
401dd3d8e0
commit
75529a202f
1 changed files with 19 additions and 8 deletions
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/dotcloud/docker/rcli"
|
||||
"github.com/dotcloud/docker/future"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
@ -174,15 +175,25 @@ func main() {
|
|||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
go func() {
|
||||
if _, err := io.Copy(os.Stdout, conn); err != nil {
|
||||
Fatal(err)
|
||||
receive_stdout := future.Go(func() error {
|
||||
_, err := io.Copy(os.Stdout, conn)
|
||||
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)
|
||||
os.Exit(0)
|
||||
}()
|
||||
if _, err := io.Copy(conn, os.Stdin); err != nil {
|
||||
return err
|
||||
})
|
||||
if err := <-receive_stdout; err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
Restore(0, oldState)
|
||||
if IsTerminal(0) {
|
||||
Restore(0, oldState)
|
||||
} else {
|
||||
if err := <-send_stdin; err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue