2017-07-28 14:31:02 +00:00
|
|
|
package libcontainer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
|
|
|
// mount initializes the console inside the rootfs mounting with the specified mount label
|
|
|
|
// and applying the correct ownership of the console.
|
2018-01-19 21:37:10 +00:00
|
|
|
func mountConsole(slavePath string) error {
|
2017-07-28 14:31:02 +00:00
|
|
|
oldMask := unix.Umask(0000)
|
|
|
|
defer unix.Umask(oldMask)
|
|
|
|
f, err := os.Create("/dev/console")
|
|
|
|
if err != nil && !os.IsExist(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if f != nil {
|
|
|
|
f.Close()
|
|
|
|
}
|
2018-01-19 21:37:10 +00:00
|
|
|
return unix.Mount(slavePath, "/dev/console", "bind", unix.MS_BIND, "")
|
2017-07-28 14:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// dupStdio opens the slavePath for the console and dups the fds to the current
|
|
|
|
// processes stdio, fd 0,1,2.
|
2018-01-19 21:37:10 +00:00
|
|
|
func dupStdio(slavePath string) error {
|
|
|
|
fd, err := unix.Open(slavePath, unix.O_RDWR, 0)
|
2017-07-28 14:31:02 +00:00
|
|
|
if err != nil {
|
2018-01-19 21:37:10 +00:00
|
|
|
return &os.PathError{
|
|
|
|
Op: "open",
|
|
|
|
Path: slavePath,
|
|
|
|
Err: err,
|
|
|
|
}
|
2017-07-28 14:31:02 +00:00
|
|
|
}
|
|
|
|
for _, i := range []int{0, 1, 2} {
|
|
|
|
if err := unix.Dup3(fd, i, 0); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|