...

Source file src/github.com/opencontainers/runc/libcontainer/console_linux.go

Documentation: github.com/opencontainers/runc/libcontainer

     1  package libcontainer
     2  
     3  import (
     4  	"os"
     5  
     6  	"golang.org/x/sys/unix"
     7  )
     8  
     9  // mount initializes the console inside the rootfs mounting with the specified mount label
    10  // and applying the correct ownership of the console.
    11  func mountConsole(slavePath string) error {
    12  	oldMask := unix.Umask(0o000)
    13  	defer unix.Umask(oldMask)
    14  	f, err := os.Create("/dev/console")
    15  	if err != nil && !os.IsExist(err) {
    16  		return err
    17  	}
    18  	if f != nil {
    19  		f.Close()
    20  	}
    21  	return mount(slavePath, "/dev/console", "", "bind", unix.MS_BIND, "")
    22  }
    23  
    24  // dupStdio opens the slavePath for the console and dups the fds to the current
    25  // processes stdio, fd 0,1,2.
    26  func dupStdio(slavePath string) error {
    27  	fd, err := unix.Open(slavePath, unix.O_RDWR, 0)
    28  	if err != nil {
    29  		return &os.PathError{
    30  			Op:   "open",
    31  			Path: slavePath,
    32  			Err:  err,
    33  		}
    34  	}
    35  	for _, i := range []int{0, 1, 2} {
    36  		if err := unix.Dup3(fd, i, 0); err != nil {
    37  			return err
    38  		}
    39  	}
    40  	return nil
    41  }
    42  

View as plain text