@@ -337,6 +337,7 @@ func (c *linuxContainer) start(process *Process) error {
337337 if err != nil {
338338 return newSystemErrorWithCause (err , "creating new parent process" )
339339 }
340+ parent .forwardChildLogs ()
340341 if err := parent .start (); err != nil {
341342 // terminate the process to ensure that it properly is reaped.
342343 if err := ignoreTerminateErrors (parent .terminate ()); err != nil {
@@ -438,16 +439,24 @@ func (c *linuxContainer) includeExecFifo(cmd *exec.Cmd) error {
438439}
439440
440441func (c * linuxContainer ) newParentProcess (p * Process ) (parentProcess , error ) {
441- parentPipe , childPipe , err := utils .NewSockPair ("init" )
442+ parentInitPipe , childInitPipe , err := utils .NewSockPair ("init" )
442443 if err != nil {
443444 return nil , newSystemErrorWithCause (err , "creating new init pipe" )
444445 }
445- cmd , err := c .commandTemplate (p , childPipe )
446+ messageSockPair := filePair {parentInitPipe , childInitPipe }
447+
448+ parentLogPipe , childLogPipe , err := os .Pipe ()
449+ if err != nil {
450+ return nil , fmt .Errorf ("Unable to create the log pipe: %s" , err )
451+ }
452+ logFilePair := filePair {parentLogPipe , childLogPipe }
453+
454+ cmd , err := c .commandTemplate (p , childInitPipe , childLogPipe )
446455 if err != nil {
447456 return nil , newSystemErrorWithCause (err , "creating new command template" )
448457 }
449458 if ! p .Init {
450- return c .newSetnsProcess (p , cmd , parentPipe , childPipe )
459+ return c .newSetnsProcess (p , cmd , messageSockPair , logFilePair )
451460 }
452461
453462 // We only set up fifoFd if we're not doing a `runc exec`. The historic
@@ -458,10 +467,10 @@ func (c *linuxContainer) newParentProcess(p *Process) (parentProcess, error) {
458467 if err := c .includeExecFifo (cmd ); err != nil {
459468 return nil , newSystemErrorWithCause (err , "including execfifo in cmd.Exec setup" )
460469 }
461- return c .newInitProcess (p , cmd , parentPipe , childPipe )
470+ return c .newInitProcess (p , cmd , messageSockPair , logFilePair )
462471}
463472
464- func (c * linuxContainer ) commandTemplate (p * Process , childPipe * os.File ) (* exec.Cmd , error ) {
473+ func (c * linuxContainer ) commandTemplate (p * Process , childInitPipe * os. File , childLogPipe * os.File ) (* exec.Cmd , error ) {
465474 cmd := exec .Command (c .initPath , c .initArgs [1 :]... )
466475 cmd .Args [0 ] = c .initArgs [0 ]
467476 cmd .Stdin = p .Stdin
@@ -479,11 +488,18 @@ func (c *linuxContainer) commandTemplate(p *Process, childPipe *os.File) (*exec.
479488 fmt .Sprintf ("_LIBCONTAINER_CONSOLE=%d" , stdioFdCount + len (cmd .ExtraFiles )- 1 ),
480489 )
481490 }
482- cmd .ExtraFiles = append (cmd .ExtraFiles , childPipe )
491+ cmd .ExtraFiles = append (cmd .ExtraFiles , childInitPipe )
483492 cmd .Env = append (cmd .Env ,
484493 fmt .Sprintf ("_LIBCONTAINER_INITPIPE=%d" , stdioFdCount + len (cmd .ExtraFiles )- 1 ),
485494 fmt .Sprintf ("_LIBCONTAINER_STATEDIR=%s" , c .root ),
486495 )
496+
497+ cmd .ExtraFiles = append (cmd .ExtraFiles , childLogPipe )
498+ cmd .Env = append (cmd .Env ,
499+ fmt .Sprintf ("_LIBCONTAINER_LOGPIPE=%d" , stdioFdCount + len (cmd .ExtraFiles )- 1 ),
500+ fmt .Sprintf ("_LIBCONTAINER_LOGLEVEL=%s" , p .LogLevel ),
501+ )
502+
487503 // NOTE: when running a container with no PID namespace and the parent process spawning the container is
488504 // PID1 the pdeathsig is being delivered to the container's init process by the kernel for some reason
489505 // even with the parent still running.
@@ -493,7 +509,7 @@ func (c *linuxContainer) commandTemplate(p *Process, childPipe *os.File) (*exec.
493509 return cmd , nil
494510}
495511
496- func (c * linuxContainer ) newInitProcess (p * Process , cmd * exec.Cmd , parentPipe , childPipe * os. File ) (* initProcess , error ) {
512+ func (c * linuxContainer ) newInitProcess (p * Process , cmd * exec.Cmd , messageSockPair , logFilePair filePair ) (* initProcess , error ) {
497513 cmd .Env = append (cmd .Env , "_LIBCONTAINER_INITTYPE=" + string (initStandard ))
498514 nsMaps := make (map [configs.NamespaceType ]string )
499515 for _ , ns := range c .config .Namespaces {
@@ -508,8 +524,8 @@ func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, c
508524 }
509525 init := & initProcess {
510526 cmd : cmd ,
511- childPipe : childPipe ,
512- parentPipe : parentPipe ,
527+ messageSockPair : messageSockPair ,
528+ logFilePair : logFilePair ,
513529 manager : c .cgroupManager ,
514530 intelRdtManager : c .intelRdtManager ,
515531 config : c .newInitConfig (p ),
@@ -522,7 +538,7 @@ func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, c
522538 return init , nil
523539}
524540
525- func (c * linuxContainer ) newSetnsProcess (p * Process , cmd * exec.Cmd , parentPipe , childPipe * os. File ) (* setnsProcess , error ) {
541+ func (c * linuxContainer ) newSetnsProcess (p * Process , cmd * exec.Cmd , messageSockPair , logFilePair filePair ) (* setnsProcess , error ) {
526542 cmd .Env = append (cmd .Env , "_LIBCONTAINER_INITTYPE=" + string (initSetns ))
527543 state , err := c .currentState ()
528544 if err != nil {
@@ -539,8 +555,8 @@ func (c *linuxContainer) newSetnsProcess(p *Process, cmd *exec.Cmd, parentPipe,
539555 cgroupPaths : c .cgroupManager .GetPaths (),
540556 rootlessCgroups : c .config .RootlessCgroups ,
541557 intelRdtPath : state .IntelRdtPath ,
542- childPipe : childPipe ,
543- parentPipe : parentPipe ,
558+ messageSockPair : messageSockPair ,
559+ logFilePair : logFilePair ,
544560 config : c .newInitConfig (p ),
545561 process : p ,
546562 bootstrapData : data ,
0 commit comments