aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/init.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-15 21:35:19 +0900
committerOphestra <cat@gensokyo.uk>2025-10-15 21:35:19 +0900
commitae65491223a460b0a902993ac81ac91ca69c91fa (patch)
tree1464488cb130bcf91b9967b14302046d79ca0bea /container/init.go
parent52e3324ef44b5f5607d363bb3608100a7b62cf5b (diff)
container/init: use one channel for wait4
When using two channels it is possible for the other case to be reached before all pending winfo are consumed, causing incorrect reporting. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/init.go')
-rw-r--r--container/init.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/container/init.go b/container/init.go
index ff72c403..e38127fd 100644
--- a/container/init.go
+++ b/container/init.go
@@ -353,10 +353,14 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) {
wpid int
wstatus WaitStatus
}
+
+ // info is closed as the wait4 thread terminates
+ // when there are no longer any processes left to reap
info := make(chan winfo, 1)
- done := make(chan struct{})
k.new(func(k syscallDispatcher) {
+ k.lockOSThread()
+
var (
err error
wpid = -2
@@ -382,7 +386,7 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) {
k.printf(msg, "unexpected wait4 response: %v", err)
}
- close(done)
+ close(info)
})
// handle signals to dump withheld messages
@@ -411,7 +415,13 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) {
msg.BeforeExit()
k.exit(0)
- case w := <-info:
+ case w, ok := <-info:
+ if !ok {
+ msg.BeforeExit()
+ k.exit(r)
+ continue // unreachable
+ }
+
if w.wpid == cmd.Process.Pid {
// initial process exited, output is most likely available again
msg.Resume()
@@ -433,10 +443,6 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) {
go func() { time.Sleep(params.AdoptWaitDelay); close(timeout) }()
}
- case <-done:
- msg.BeforeExit()
- k.exit(r)
-
case <-timeout:
k.printf(msg, "timeout exceeded waiting for lingering processes")
msg.BeforeExit()