66 "fmt"
77 "io"
88 "os"
9- "syscall"
109
1110 "github.com/docker/docker/pkg/term"
1211 "github.com/opencontainers/runc/libcontainer"
@@ -25,38 +24,20 @@ func newTty(create bool, p *libcontainer.Process, rootuid int) (*tty, error) {
2524// setup standard pipes so that the TTY of the calling runc process
2625// is not inherited by the container.
2726func createStdioPipes (p * libcontainer.Process , rootuid int ) (* tty , error ) {
28- var (
29- t = & tty {}
30- fds []int
31- )
32- r , w , err := os .Pipe ()
27+ i , err := p .InitializeIO (rootuid )
3328 if err != nil {
3429 return nil , err
3530 }
36- fds = append (fds , int (r .Fd ()), int (w .Fd ()))
37- go io .Copy (w , os .Stdin )
38- t .closers = append (t .closers , w )
39- p .Stdin = r
40- if r , w , err = os .Pipe (); err != nil {
41- return nil , err
42- }
43- fds = append (fds , int (r .Fd ()), int (w .Fd ()))
44- go io .Copy (os .Stdout , r )
45- p .Stdout = w
46- t .closers = append (t .closers , r )
47- if r , w , err = os .Pipe (); err != nil {
48- return nil , err
49- }
50- fds = append (fds , int (r .Fd ()), int (w .Fd ()))
51- go io .Copy (os .Stderr , r )
52- p .Stderr = w
53- t .closers = append (t .closers , r )
54- // change the ownership of the pipe fds incase we are in a user namespace.
55- for _ , fd := range fds {
56- if err := syscall .Fchown (fd , rootuid , rootuid ); err != nil {
57- return nil , err
58- }
31+ t := & tty {
32+ closers : []io.Closer {
33+ i .Stdin ,
34+ i .Stdout ,
35+ i .Stderr ,
36+ },
5937 }
38+ go io .Copy (i .Stdin , os .Stdin )
39+ go io .Copy (os .Stdout , i .Stdout )
40+ go io .Copy (os .Stderr , i .Stderr )
6041 return t , nil
6142}
6243
@@ -78,9 +59,6 @@ func createTty(p *libcontainer.Process, rootuid int) (*tty, error) {
7859 console ,
7960 },
8061 }
81- p .Stderr = nil
82- p .Stdout = nil
83- p .Stdin = nil
8462 return t , nil
8563}
8664
0 commit comments