diff --git a/container/init.go b/container/init.go index 923feb4..04c643d 100644 --- a/container/init.go +++ b/container/init.go @@ -11,6 +11,7 @@ import ( "slices" "strconv" "sync" + "sync/atomic" . "syscall" "time" @@ -368,8 +369,8 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) { // when there are no longer any processes left to reap info := make(chan winfo, 1) - // closed when the initial process has started - initialProcessStarted := make(chan struct{}) + // whether initial process has started + var initialProcessStarted atomic.Bool k.new(func(k syscallDispatcher) { k.lockOSThread() @@ -413,11 +414,10 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) { if !errors.Is(err, ECHILD) { k.printf(msg, "unexpected wait4 response: %v", err) - } else if initialProcessStarted != nil { + } else if !initialProcessStarted.Load() { // initial process has not yet been reached and all daemons // terminated or none were started in the first place - <-initialProcessStarted - initialProcessStarted = nil + time.Sleep(500 * time.Microsecond) goto wait4 } @@ -458,7 +458,7 @@ func initEntrypoint(k syscallDispatcher, msg message.Msg) { if err := k.start(cmd); err != nil { k.fatalf(msg, "%v", err) } - close(initialProcessStarted) + initialProcessStarted.Store(true) // handle signals to dump withheld messages sig := make(chan os.Signal, 2)