Skip to content

Commit 10adde3

Browse files
committed
fix stdio permission error for runc run without detach
Signed-off-by: lifubang <[email protected]>
1 parent 01ab55f commit 10adde3

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

libcontainer/process_linux.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ func getPipeFds(pid int) ([]string, error) {
917917
// opposite side for each. Do not use this if you want to have a pseudoterminal
918918
// set up for you by libcontainer (TODO: fix that too).
919919
// TODO: This is mostly unnecessary, and should be handled by clients.
920-
func (p *Process) InitializeIO(rootuid, rootgid int) (i *IO, err error) {
920+
func (p *Process) InitializeIO(containerUID, containerGID int) (i *IO, err error) {
921921
var fds []uintptr
922922
i = &IO{}
923923
// cleanup in case of an error
@@ -949,7 +949,7 @@ func (p *Process) InitializeIO(rootuid, rootgid int) (i *IO, err error) {
949949
p.Stderr, i.Stderr = w, r
950950
// change ownership of the pipes in case we are in a user namespace
951951
for _, fd := range fds {
952-
if err := unix.Fchown(int(fd), rootuid, rootgid); err != nil {
952+
if err := unix.Fchown(int(fd), containerUID, containerGID); err != nil {
953953
return nil, &os.PathError{Op: "fchown", Path: "fd " + strconv.Itoa(int(fd)), Err: err}
954954
}
955955
}

tty.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func (t *tty) copyIO(w io.Writer, r io.ReadCloser) {
3131

3232
// setup pipes for the process so that advanced features like c/r are able to easily checkpoint
3333
// and restore the process's IO without depending on a host specific path or device
34-
func setupProcessPipes(p *libcontainer.Process, rootuid, rootgid int) (*tty, error) {
35-
i, err := p.InitializeIO(rootuid, rootgid)
34+
func setupProcessPipes(p *libcontainer.Process, containerUID, containerGID int) (*tty, error) {
35+
i, err := p.InitializeIO(containerUID, containerGID)
3636
if err != nil {
3737
return nil, err
3838
}

utils_linux.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func newProcess(p specs.Process) (*libcontainer.Process, error) {
9494
}
9595

9696
// setupIO modifies the given process config according to the options.
97-
func setupIO(process *libcontainer.Process, rootuid, rootgid int, createTTY, detach bool, sockpath string) (*tty, error) {
97+
func setupIO(process *libcontainer.Process, containerUID, containerGID int, createTTY, detach bool, sockpath string) (*tty, error) {
9898
if createTTY {
9999
process.Stdin = nil
100100
process.Stdout = nil
@@ -140,7 +140,7 @@ func setupIO(process *libcontainer.Process, rootuid, rootgid int, createTTY, det
140140
inheritStdio(process)
141141
return &tty{}, nil
142142
}
143-
return setupProcessPipes(process, rootuid, rootgid)
143+
return setupProcessPipes(process, containerUID, containerGID)
144144
}
145145

146146
// createPidFile creates a file containing the PID,
@@ -237,11 +237,11 @@ func (r *runner) run(config *specs.Process) (int, error) {
237237
}
238238
process.ExtraFiles = append(process.ExtraFiles, os.NewFile(uintptr(i), "PreserveFD:"+strconv.Itoa(i)))
239239
}
240-
rootuid, err := r.container.Config().HostRootUID()
240+
containerUID, err := r.container.Config().HostUID(int(config.User.UID))
241241
if err != nil {
242242
return -1, err
243243
}
244-
rootgid, err := r.container.Config().HostRootGID()
244+
containerGID, err := r.container.Config().HostGID(int(config.User.GID))
245245
if err != nil {
246246
return -1, err
247247
}
@@ -250,7 +250,7 @@ func (r *runner) run(config *specs.Process) (int, error) {
250250
// with detaching containers, and then we get a tty after the container has
251251
// started.
252252
handler := newSignalHandler(r.enableSubreaper, r.notifySocket)
253-
tty, err := setupIO(process, rootuid, rootgid, config.Terminal, detach, r.consoleSocket)
253+
tty, err := setupIO(process, containerUID, containerGID, config.Terminal, detach, r.consoleSocket)
254254
if err != nil {
255255
return -1, err
256256
}

0 commit comments

Comments
 (0)