summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-07-31 11:34:23 -0400
committerGitHub <noreply@github.com>2020-07-31 11:34:23 -0400
commit7a15be546adffe4f884abfbd4ed02f69ac7659e0 (patch)
tree769f4189072bc22addc757362d0de50b6d6ee59d /libpod
parent3cf8237bc0b350c72ecc9a7ea364cb2e6a1c3bc0 (diff)
parent3fccb699e4ba2748bd3f7d156335ea2ea34c33f8 (diff)
downloadpodman-7a15be546adffe4f884abfbd4ed02f69ac7659e0.tar.gz
podman-7a15be546adffe4f884abfbd4ed02f69ac7659e0.tar.bz2
podman-7a15be546adffe4f884abfbd4ed02f69ac7659e0.zip
Merge pull request #7168 from QiWang19/exec-fds
Fix close fds of exec --preserve-fds
Diffstat (limited to 'libpod')
-rw-r--r--libpod/oci_conmon_exec_linux.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/libpod/oci_conmon_exec_linux.go b/libpod/oci_conmon_exec_linux.go
index f8d87759a..cfe3745fa 100644
--- a/libpod/oci_conmon_exec_linux.go
+++ b/libpod/oci_conmon_exec_linux.go
@@ -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