diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 97b0c4005..3a51ec1b1 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -324,16 +324,6 @@ func (c *Container) start(process *Process) (retErr error) { defer process.closeClonedExes() logsDone := parent.forwardChildLogs() - if logsDone != nil { - defer func() { - // Wait for log forwarder to finish. This depends on - // runc init closing the _LIBCONTAINER_LOGPIPE log fd. - err := <-logsDone - if err != nil && retErr == nil { - retErr = fmt.Errorf("unable to forward init logs: %w", err) - } - }() - } // Before starting "runc init", mark all non-stdio open files as O_CLOEXEC // to make sure we don't leak any files into "runc init". Any files to be @@ -348,6 +338,17 @@ func (c *Container) start(process *Process) (retErr error) { return fmt.Errorf("unable to start container process: %w", err) } + if logsDone != nil { + defer func() { + // Wait for log forwarder to finish. This depends on + // runc init closing the _LIBCONTAINER_LOGPIPE log fd. + err := <-logsDone + if err != nil && retErr == nil { + retErr = fmt.Errorf("unable to forward init logs: %w", err) + } + }() + } + if process.Init { c.fifo.Close() if c.config.Hooks != nil {