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