Merge pull request #16901 from Luap99/service-close-fd

podman service: close duplicated /dev/null fd
This commit is contained in:
OpenShift Merge Robot 2022-12-22 03:51:03 -05:00 committed by GitHub
commit 5211446516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -94,15 +94,17 @@ func restService(flags *pflag.FlagSet, cfg *entities.PodmanConfig, opts entities
libpodRuntime.SetRemoteURI(uri.String())
}
// Close stdin, so shortnames will not prompt
// Set stdin to /dev/null, so shortnames will not prompt
devNullfile, err := os.Open(os.DevNull)
if err != nil {
return err
}
defer devNullfile.Close()
if err := unix.Dup2(int(devNullfile.Fd()), int(os.Stdin.Fd())); err != nil {
devNullfile.Close()
return err
}
// Close the fd right away to not leak it during the entire time of the service.
devNullfile.Close()
if err := utils.MaybeMoveToSubCgroup(); err != nil {
// it is a best effort operation, so just print the