@@ -335,7 +335,7 @@ func (c *linuxContainer) deleteExecFifo() {
335335}
336336
337337func (c * linuxContainer ) newParentProcess (p * Process , doInit bool ) (parentProcess , error ) {
338- parentPipe , childPipe , err := newPipe ( )
338+ parentPipe , childPipe , err := utils . NewSockPair ( "init" )
339339 if err != nil {
340340 return nil , newSystemErrorWithCause (err , "creating new init pipe" )
341341 }
@@ -370,9 +370,17 @@ func (c *linuxContainer) commandTemplate(p *Process, childPipe *os.File) (*exec.
370370 if cmd .SysProcAttr == nil {
371371 cmd .SysProcAttr = & syscall.SysProcAttr {}
372372 }
373- cmd .ExtraFiles = append (p .ExtraFiles , childPipe )
373+ cmd .ExtraFiles = append (cmd .ExtraFiles , p .ExtraFiles ... )
374+ if p .ConsoleSocket != nil {
375+ cmd .ExtraFiles = append (cmd .ExtraFiles , p .ConsoleSocket )
376+ cmd .Env = append (cmd .Env ,
377+ fmt .Sprintf ("_LIBCONTAINER_CONSOLE=%d" , stdioFdCount + len (cmd .ExtraFiles )- 1 ),
378+ )
379+ }
380+ cmd .ExtraFiles = append (cmd .ExtraFiles , childPipe )
374381 cmd .Env = append (cmd .Env ,
375- fmt .Sprintf ("_LIBCONTAINER_INITPIPE=%d" , stdioFdCount + len (cmd .ExtraFiles )- 1 ))
382+ fmt .Sprintf ("_LIBCONTAINER_INITPIPE=%d" , stdioFdCount + len (cmd .ExtraFiles )- 1 ),
383+ )
376384 // NOTE: when running a container with no PID namespace and the parent process spawning the container is
377385 // PID1 the pdeathsig is being delivered to the container's init process by the kernel for some reason
378386 // even with the parent still running.
@@ -395,7 +403,6 @@ func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, c
395403 if err != nil {
396404 return nil , err
397405 }
398- p .consoleChan = make (chan * os.File , 1 )
399406 return & initProcess {
400407 cmd : cmd ,
401408 childPipe : childPipe ,
@@ -422,8 +429,6 @@ func (c *linuxContainer) newSetnsProcess(p *Process, cmd *exec.Cmd, parentPipe,
422429 if err != nil {
423430 return nil , err
424431 }
425- // TODO: set on container for process management
426- p .consoleChan = make (chan * os.File , 1 )
427432 return & setnsProcess {
428433 cmd : cmd ,
429434 cgroupPaths : c .cgroupManager .GetPaths (),
@@ -463,28 +468,10 @@ func (c *linuxContainer) newInitConfig(process *Process) *initConfig {
463468 if len (process .Rlimits ) > 0 {
464469 cfg .Rlimits = process .Rlimits
465470 }
466- /*
467- * TODO: This should not be automatically computed. We should implement
468- * this as a field in libcontainer.Process, and then we only dup the
469- * new console over the file descriptors which were not explicitly
470- * set with process.Std{in,out,err}. The reason I've left this as-is
471- * is because the GetConsole() interface is new, there's no need to
472- * polish this interface right now.
473- */
474- if process .Stdin == nil && process .Stdout == nil && process .Stderr == nil {
475- cfg .CreateConsole = true
476- }
471+ cfg .CreateConsole = process .ConsoleSocket != nil
477472 return cfg
478473}
479474
480- func newPipe () (parent * os.File , child * os.File , err error ) {
481- fds , err := syscall .Socketpair (syscall .AF_LOCAL , syscall .SOCK_STREAM | syscall .SOCK_CLOEXEC , 0 )
482- if err != nil {
483- return nil , nil , err
484- }
485- return os .NewFile (uintptr (fds [1 ]), "parent" ), os .NewFile (uintptr (fds [0 ]), "child" ), nil
486- }
487-
488475func (c * linuxContainer ) Destroy () error {
489476 c .m .Lock ()
490477 defer c .m .Unlock ()
0 commit comments