diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-07-31 08:25:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-31 08:25:05 -0400 |
commit | 3cf8237bc0b350c72ecc9a7ea364cb2e6a1c3bc0 (patch) | |
tree | 3c72abf1f88486c7ad3316f999b3bdef0ce98e16 | |
parent | bb96c8918b0df7a1179a5ca61f9adae07e0b4620 (diff) | |
parent | 57967414ae3ff9abaa21da21375c121ecfe47a08 (diff) | |
download | podman-3cf8237bc0b350c72ecc9a7ea364cb2e6a1c3bc0.tar.gz podman-3cf8237bc0b350c72ecc9a7ea364cb2e6a1c3bc0.tar.bz2 podman-3cf8237bc0b350c72ecc9a7ea364cb2e6a1c3bc0.zip |
Merge pull request #7120 from QiWang19/preserve-fd
Fix close fds of run --preserve-fds
-rw-r--r-- | libpod/oci_conmon_linux.go | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go index e677ece31..67593a68b 100644 --- a/libpod/oci_conmon_linux.go +++ b/libpod/oci_conmon_linux.go @@ -954,9 +954,12 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co return err } + var filesToClose []*os.File if ctr.config.PreserveFDs > 0 { for fd := 3; fd < int(3+ctr.config.PreserveFDs); fd++ { - cmd.ExtraFiles = append(cmd.ExtraFiles, os.NewFile(uintptr(fd), fmt.Sprintf("fd-%d", fd))) + f := os.NewFile(uintptr(fd), fmt.Sprintf("fd-%d", fd)) + filesToClose = append(filesToClose, f) + cmd.ExtraFiles = append(cmd.ExtraFiles, f) } } @@ -1052,14 +1055,10 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co } } - if ctr.config.PreserveFDs > 0 { - for fd := 3; fd < int(3+ctr.config.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 nil |