Merge pull request #155 from tonistiigi/stdin-closer-fix
Fix closing stdin before everything has been written to pipe
This commit is contained in:
commit
c056573b53
2 changed files with 21 additions and 5 deletions
|
@ -89,7 +89,9 @@ func start() error {
|
||||||
switch msg {
|
switch msg {
|
||||||
case 0:
|
case 0:
|
||||||
// close stdin
|
// close stdin
|
||||||
p.shimIO.Stdin.Close()
|
if p.stdinCloser != nil {
|
||||||
|
p.stdinCloser.Close()
|
||||||
|
}
|
||||||
case 1:
|
case 1:
|
||||||
if p.console == nil {
|
if p.console == nil {
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -28,6 +28,7 @@ type process struct {
|
||||||
containerPid int
|
containerPid int
|
||||||
checkpoint *runtime.Checkpoint
|
checkpoint *runtime.Checkpoint
|
||||||
shimIO *IO
|
shimIO *IO
|
||||||
|
stdinCloser io.Closer
|
||||||
console libcontainer.Console
|
console libcontainer.Console
|
||||||
consolePath string
|
consolePath string
|
||||||
state *runtime.ProcessState
|
state *runtime.ProcessState
|
||||||
|
@ -186,6 +187,12 @@ func (p *process) openIO() error {
|
||||||
uid = p.state.RootUID
|
uid = p.state.RootUID
|
||||||
gid = p.state.RootGID
|
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 {
|
if p.state.Terminal {
|
||||||
console, err := libcontainer.NewConsole(uid, gid)
|
console, err := libcontainer.NewConsole(uid, gid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -193,7 +200,7 @@ func (p *process) openIO() error {
|
||||||
}
|
}
|
||||||
p.console = console
|
p.console = console
|
||||||
p.consolePath = console.Path()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -217,9 +224,6 @@ func (p *process) openIO() error {
|
||||||
p.shimIO = i
|
p.shimIO = i
|
||||||
// non-tty
|
// non-tty
|
||||||
for name, dest := range map[string]func(f *os.File){
|
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.state.Stdout: func(f *os.File) {
|
||||||
p.Add(1)
|
p.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -241,6 +245,16 @@ func (p *process) openIO() error {
|
||||||
}
|
}
|
||||||
dest(f)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue