Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libpod: Factor out the call to PidFdOpen from (*Container).WaitForExit #16182

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions libpod/container_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,21 +516,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
Expand Down
7 changes: 7 additions & 0 deletions libpod/container_internal_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 15 additions & 0 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}