Skip to content

Commit 291bf60

Browse files
authored
Merge pull request #1354 from crosbymichael/dup-io
Don't fchown when inheriting io
2 parents dcbcdf2 + eebdb64 commit 291bf60

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

tty.go

+4-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"io"
88
"os"
99
"sync"
10-
"syscall"
1110

1211
"github.com/docker/docker/pkg/term"
1312
"github.com/opencontainers/runc/libcontainer"
@@ -28,9 +27,9 @@ func (t *tty) copyIO(w io.Writer, r io.ReadCloser) {
2827
r.Close()
2928
}
3029

31-
// setup standard pipes so that the TTY of the calling runc process
32-
// is not inherited by the container.
33-
func createStdioPipes(p *libcontainer.Process, rootuid, rootgid int) (*tty, error) {
30+
// setup pipes for the process so that advanced features like c/r are able to easily checkpoint
31+
// and restore the process's IO without depending on a host specific path or device
32+
func setupProcessPipes(p *libcontainer.Process, rootuid, rootgid int) (*tty, error) {
3433
i, err := p.InitializeIO(rootuid, rootgid)
3534
if err != nil {
3635
return nil, err
@@ -62,19 +61,10 @@ func createStdioPipes(p *libcontainer.Process, rootuid, rootgid int) (*tty, erro
6261
return t, nil
6362
}
6463

65-
func dupStdio(process *libcontainer.Process, rootuid, rootgid int) error {
64+
func inheritStdio(process *libcontainer.Process) error {
6665
process.Stdin = os.Stdin
6766
process.Stdout = os.Stdout
6867
process.Stderr = os.Stderr
69-
for _, fd := range []uintptr{
70-
os.Stdin.Fd(),
71-
os.Stdout.Fd(),
72-
os.Stderr.Fd(),
73-
} {
74-
if err := syscall.Fchown(int(fd), rootuid, rootgid); err != nil {
75-
return err
76-
}
77-
}
7868
return nil
7969
}
8070

utils_linux.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,15 @@ func setupIO(process *libcontainer.Process, rootuid, rootgid int, createTTY, det
110110
process.Stderr = nil
111111
return &tty{}, nil
112112
}
113-
114-
// When we detach, we just dup over stdio and call it a day. There's no
115-
// requirement that we set up anything nice for our caller or the
116-
// container.
113+
// when runc will detach the caller provides the stdio to runc via runc's 0,1,2
114+
// and the container's process inherits runc's stdio.
117115
if detach {
118-
if err := dupStdio(process, rootuid, rootgid); err != nil {
116+
if err := inheritStdio(process); err != nil {
119117
return nil, err
120118
}
121119
return &tty{}, nil
122120
}
123-
124-
// XXX: This doesn't sit right with me. It's ugly.
125-
return createStdioPipes(process, rootuid, rootgid)
121+
return setupProcessPipes(process, rootuid, rootgid)
126122
}
127123

128124
// createPidFile creates a file with the processes pid inside it atomically

0 commit comments

Comments
 (0)