mirror of https://github.com/containers/podman.git
Merge pull request #7120 from QiWang19/preserve-fd
Fix close fds of run --preserve-fds
This commit is contained in:
commit
3cf8237bc0
|
@ -954,9 +954,12 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var filesToClose []*os.File
|
||||||
if ctr.config.PreserveFDs > 0 {
|
if ctr.config.PreserveFDs > 0 {
|
||||||
for fd := 3; fd < int(3+ctr.config.PreserveFDs); fd++ {
|
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 {
|
// These fds were passed down to the runtime. Close them
|
||||||
for fd := 3; fd < int(3+ctr.config.PreserveFDs); fd++ {
|
// and not interfere
|
||||||
// These fds were passed down to the runtime. Close them
|
for _, f := range filesToClose {
|
||||||
// and not interfere
|
errorhandling.CloseQuiet(f)
|
||||||
if err := os.NewFile(uintptr(fd), fmt.Sprintf("fd-%d", fd)).Close(); err != nil {
|
|
||||||
logrus.Debugf("unable to close file fd-%d", fd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue