Fix closing stdin before everything has been written to pipe

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2016-03-23 10:26:05 -07:00
parent 0c1445dedf
commit fa0efa2906
2 changed files with 21 additions and 5 deletions

View file

@ -89,7 +89,9 @@ func start() error {
switch msg {
case 0:
// close stdin
p.shimIO.Stdin.Close()
if p.stdinCloser != nil {
p.stdinCloser.Close()
}
case 1:
if p.console == nil {
continue

View file

@ -28,6 +28,7 @@ type process struct {
containerPid int
checkpoint *runtime.Checkpoint
shimIO *IO
stdinCloser io.Closer
console libcontainer.Console
consolePath string
state *runtime.ProcessState
@ -186,6 +187,12 @@ func (p *process) openIO() error {
uid = p.state.RootUID
gid = p.state.RootGID
)
go func() {
if stdinCloser, err := os.OpenFile(p.state.Stdin, syscall.O_WRONLY, 0); err == nil {
p.stdinCloser = stdinCloser
}
}()
if p.state.Terminal {
console, err := libcontainer.NewConsole(uid, gid)
if err != nil {
@ -193,7 +200,7 @@ func (p *process) openIO() error {
}
p.console = console
p.consolePath = console.Path()
stdin, err := os.OpenFile(p.state.Stdin, syscall.O_RDWR, 0)
stdin, err := os.OpenFile(p.state.Stdin, syscall.O_RDONLY, 0)
if err != nil {
return err
}
@ -217,9 +224,6 @@ func (p *process) openIO() error {
p.shimIO = i
// non-tty
for name, dest := range map[string]func(f *os.File){
p.state.Stdin: func(f *os.File) {
go io.Copy(i.Stdin, f)
},
p.state.Stdout: func(f *os.File) {
p.Add(1)
go func() {
@ -241,6 +245,16 @@ func (p *process) openIO() error {
}
dest(f)
}
f, err := os.OpenFile(p.state.Stdin, syscall.O_RDONLY, 0)
if err != nil {
return err
}
go func() {
io.Copy(i.Stdin, f)
i.Stdin.Close()
}()
return nil
}