libct: simplify exec fifo wait using poll(2)#5271
Conversation
e91e67c to
1889c08
Compare
| // or the init process has exited. It does not consume the data — it only | ||
| // returns once a subsequent read on f will not block indefinitely. | ||
| func waitForFifoReady(f *os.File, pid int) error { | ||
| pidFd, err := unix.PidfdOpen(pid, 0) |
There was a problem hiding this comment.
You can use https://pkg.go.dev/os#Process.WithHandle here:
proc, _ := os.FindProcess(pid) // or add process() to parentProcess interface
var readyErr error
err := proc.WithHandle(func(pidfd uintptr) {
readyErr = waitForReadyPidfd(f, int(pidfd))
})
if err != nil { // pidfd not supported
return waitForFifoReadyPolling(f, pid)
}This works better because WithHandle will only call the function if pidfd is fully supported by the kernel (there are many kernels with different nuances and you can rely on the Go runtime check).
There was a problem hiding this comment.
os.Process.WithHandle became available in Go 1.26 but runc's go.mod is currently at go 1.25.0. We'll need to bump the version or I can continue using raw unix.PidfOpen for now.
There was a problem hiding this comment.
Maybe add a // TODO: switch to os.Process.WithHandle once go < 1.26 is no longer supported. or somesuch.
kolyshkin
left a comment
There was a problem hiding this comment.
Thanks for working on this! Left a few comments, but overall this looks good.
|
this is nice one |
73c4cd4 to
460ea7f
Compare
Replace the goroutine + channel + 100ms time.After + blocking open in handleFifo with a poll(2) loop on a non-blocking open. Use pidfd_open(2) where available to wait for init exit without timeout, falling back to /proc state checks with 100ms timeout on older kernels. Fixes opencontainers#5251 Signed-off-by: Mohammed Aminu Futa <mohammedfuta2000@gmail.com>
460ea7f to
72a9bd5
Compare
Replace the goroutine + channel + 100ms time.After + blocking-open in handleFifo with a poll(2) loop on a non-blocking-open. Use pidfd_open(2) where available to wait for init exit without timeout, falling back to /proc state checks with 100ms timeout on older kernels. Allowing us to wait on both write to execfifo and state of init process simultaneously.
Fixes #5251