mirror of
https://github.com/containers/podman.git
synced 2025-07-03 01:08:02 +08:00
Merge pull request #7168 from QiWang19/exec-fds
Fix close fds of exec --preserve-fds
This commit is contained in:
@ -449,9 +449,12 @@ func (r *ConmonOCIRuntime) startExec(c *Container, sessionID string, options *Ex
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var filesToClose []*os.File
|
||||
if options.PreserveFDs > 0 {
|
||||
for fd := 3; fd < int(3+options.PreserveFDs); fd++ {
|
||||
execCmd.ExtraFiles = append(execCmd.ExtraFiles, os.NewFile(uintptr(fd), fmt.Sprintf("fd-%d", fd)))
|
||||
f := os.NewFile(uintptr(fd), fmt.Sprintf("fd-%d", fd))
|
||||
filesToClose = append(filesToClose, f)
|
||||
execCmd.ExtraFiles = append(execCmd.ExtraFiles, f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,14 +486,10 @@ func (r *ConmonOCIRuntime) startExec(c *Container, sessionID string, options *Ex
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if options.PreserveFDs > 0 {
|
||||
for fd := 3; fd < int(3+options.PreserveFDs); fd++ {
|
||||
// These fds were passed down to the runtime. Close them
|
||||
// and not interfere
|
||||
if err := os.NewFile(uintptr(fd), fmt.Sprintf("fd-%d", fd)).Close(); err != nil {
|
||||
logrus.Debugf("unable to close file fd-%d", fd)
|
||||
}
|
||||
}
|
||||
// These fds were passed down to the runtime. Close them
|
||||
// and not interfere
|
||||
for _, f := range filesToClose {
|
||||
errorhandling.CloseQuiet(f)
|
||||
}
|
||||
|
||||
return execCmd, pipes, nil
|
||||
|
Reference in New Issue
Block a user