mirror of
https://github.com/containers/podman.git
synced 2025-07-03 09:17:15 +08:00
Merge pull request #16182 from dfr/freebsd-pidfd
libpod: Factor out the call to PidFdOpen from (*Container).WaitForExit
This commit is contained in:
@ -521,21 +521,11 @@ func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration)
|
|||||||
var conmonTimer time.Timer
|
var conmonTimer time.Timer
|
||||||
conmonTimerSet := false
|
conmonTimerSet := false
|
||||||
|
|
||||||
conmonPidFd := -1
|
conmonPidFd := c.getConmonPidFd()
|
||||||
conmonPidFdTriggered := false
|
if conmonPidFd != -1 {
|
||||||
|
defer unix.Close(conmonPidFd)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
conmonPidFdTriggered := false
|
||||||
|
|
||||||
getExitCode := func() (bool, int32, error) {
|
getExitCode := func() (bool, int32, error) {
|
||||||
containerRemoved := false
|
containerRemoved := false
|
||||||
|
@ -272,3 +272,10 @@ func setVolumeAtime(mountPoint string, st os.FileInfo) error {
|
|||||||
func (c *Container) makePlatformBindMounts() error {
|
func (c *Container) makePlatformBindMounts() error {
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
@ -665,3 +665,18 @@ func (c *Container) makePlatformBindMounts() error {
|
|||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user