Merge pull request #16182 from dfr/freebsd-pidfd

libpod: Factor out the call to PidFdOpen from (*Container).WaitForExit
This commit is contained in:
OpenShift Merge Robot
2022-10-17 09:55:43 -04:00
committed by GitHub
3 changed files with 26 additions and 14 deletions

View File

@ -521,21 +521,11 @@ func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration)
var conmonTimer time.Timer
conmonTimerSet := false
conmonPidFd := -1
conmonPidFdTriggered := false
if c.state.ConmonPID != 0 {
// Track lifetime of conmon precisely using pidfd_open + poll.
// There are many cases for this to fail, for instance conmon is dead
// or pidfd_open is not supported (pre linux 5.3), so fall back to the
// traditional loop with poll + sleep
if fd, err := unix.PidfdOpen(c.state.ConmonPID, 0); err == nil {
conmonPidFd = fd
defer unix.Close(conmonPidFd)
} else if err != unix.ENOSYS && err != unix.ESRCH {
logrus.Debugf("PidfdOpen(%d) failed: %v", c.state.ConmonPID, err)
}
conmonPidFd := c.getConmonPidFd()
if conmonPidFd != -1 {
defer unix.Close(conmonPidFd)
}
conmonPidFdTriggered := false
getExitCode := func() (bool, int32, error) {
containerRemoved := false

View File

@ -272,3 +272,10 @@ func setVolumeAtime(mountPoint string, st os.FileInfo) error {
func (c *Container) makePlatformBindMounts() error {
return nil
}
func (c *Container) getConmonPidFd() int {
// Note: kqueue(2) could be used here but that would require
// factoring out the call to unix.PollFd from WaitForExit so
// keeping things simple for now.
return -1
}

View File

@ -665,3 +665,18 @@ func (c *Container) makePlatformBindMounts() error {
}
return nil
}
func (c *Container) getConmonPidFd() int {
if c.state.ConmonPID != 0 {
// Track lifetime of conmon precisely using pidfd_open + poll.
// There are many cases for this to fail, for instance conmon is dead
// or pidfd_open is not supported (pre linux 5.3), so fall back to the
// traditional loop with poll + sleep
if fd, err := unix.PidfdOpen(c.state.ConmonPID, 0); err == nil {
return fd
} else if err != unix.ENOSYS && err != unix.ESRCH {
logrus.Debugf("PidfdOpen(%d) failed: %v", c.state.ConmonPID, err)
}
}
return -1
}