From 2f74adc8bdeda2499be0a8b2711f68c342695bf2 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 10 Nov 2025 20:35:59 +0900 Subject: container/init: close initial process files on termination This closes them during the adopt wait delay. This also keeps them alive. Signed-off-by: Ophestra --- container/init.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'container/init.go') diff --git a/container/init.go b/container/init.go index fd513efd..592ef302 100644 --- a/container/init.go +++ b/container/init.go @@ -427,6 +427,16 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) { } if w.wpid == cmd.Process.Pid { + // start timeout early + go func() { time.Sleep(params.AdoptWaitDelay); close(timeout) }() + + // close initial process files; this also keeps them alive + for _, f := range extraFiles { + if err := f.Close(); err != nil { + msg.Verbose(err.Error()) + } + } + switch { case w.wstatus.Exited(): r = w.wstatus.ExitStatus() @@ -440,8 +450,6 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) { r = 255 msg.Verbosef("initial process exited with status %#x", w.wstatus) } - - go func() { time.Sleep(params.AdoptWaitDelay); close(timeout) }() } case <-timeout: -- cgit v1.3.1