Move rest of console functions to pkg
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
9cb39c7274
commit
d4ea33bf43
|
@ -44,3 +44,17 @@ func Setup(rootfs, consolePath, mountLabel string) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OpenAndDup(consolePath string) error {
|
||||||
|
slave, err := system.OpenTerminal(consolePath, syscall.O_RDWR)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("open terminal %s", err)
|
||||||
|
}
|
||||||
|
if err := system.Dup2(slave.Fd(), 0); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := system.Dup2(slave.Fd(), 1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return system.Dup2(slave.Fd(), 2)
|
||||||
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/dotcloud/docker/pkg/label"
|
"github.com/dotcloud/docker/pkg/label"
|
||||||
"github.com/dotcloud/docker/pkg/libcontainer"
|
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||||
"github.com/dotcloud/docker/pkg/libcontainer/capabilities"
|
"github.com/dotcloud/docker/pkg/libcontainer/capabilities"
|
||||||
|
"github.com/dotcloud/docker/pkg/libcontainer/console"
|
||||||
"github.com/dotcloud/docker/pkg/libcontainer/mount"
|
"github.com/dotcloud/docker/pkg/libcontainer/mount"
|
||||||
"github.com/dotcloud/docker/pkg/libcontainer/network"
|
"github.com/dotcloud/docker/pkg/libcontainer/network"
|
||||||
"github.com/dotcloud/docker/pkg/libcontainer/security/apparmor"
|
"github.com/dotcloud/docker/pkg/libcontainer/security/apparmor"
|
||||||
|
@ -22,7 +23,7 @@ import (
|
||||||
|
|
||||||
// Init is the init process that first runs inside a new namespace to setup mounts, users, networking,
|
// Init is the init process that first runs inside a new namespace to setup mounts, users, networking,
|
||||||
// and other options required for the new container.
|
// and other options required for the new container.
|
||||||
func (ns *linuxNs) Init(container *libcontainer.Container, uncleanRootfs, console string, syncPipe *SyncPipe, args []string) error {
|
func (ns *linuxNs) Init(container *libcontainer.Container, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) error {
|
||||||
rootfs, err := utils.ResolveRootfs(uncleanRootfs)
|
rootfs, err := utils.ResolveRootfs(uncleanRootfs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -38,20 +39,16 @@ func (ns *linuxNs) Init(container *libcontainer.Container, uncleanRootfs, consol
|
||||||
ns.logger.Println("received context from parent")
|
ns.logger.Println("received context from parent")
|
||||||
syncPipe.Close()
|
syncPipe.Close()
|
||||||
|
|
||||||
if console != "" {
|
if consolePath != "" {
|
||||||
ns.logger.Printf("setting up %s as console\n", console)
|
ns.logger.Printf("setting up %s as console\n", consolePath)
|
||||||
slave, err := system.OpenTerminal(console, syscall.O_RDWR)
|
if err := console.OpenAndDup(consolePath); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return fmt.Errorf("open terminal %s", err)
|
|
||||||
}
|
|
||||||
if err := dupSlave(slave); err != nil {
|
|
||||||
return fmt.Errorf("dup2 slave %s", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, err := system.Setsid(); err != nil {
|
if _, err := system.Setsid(); err != nil {
|
||||||
return fmt.Errorf("setsid %s", err)
|
return fmt.Errorf("setsid %s", err)
|
||||||
}
|
}
|
||||||
if console != "" {
|
if consolePath != "" {
|
||||||
if err := system.Setctty(); err != nil {
|
if err := system.Setctty(); err != nil {
|
||||||
return fmt.Errorf("setctty %s", err)
|
return fmt.Errorf("setctty %s", err)
|
||||||
}
|
}
|
||||||
|
@ -62,7 +59,7 @@ func (ns *linuxNs) Init(container *libcontainer.Container, uncleanRootfs, consol
|
||||||
|
|
||||||
label.Init()
|
label.Init()
|
||||||
ns.logger.Println("setup mount namespace")
|
ns.logger.Println("setup mount namespace")
|
||||||
if err := mount.InitializeMountNamespace(rootfs, console, container); err != nil {
|
if err := mount.InitializeMountNamespace(rootfs, consolePath, container); err != nil {
|
||||||
return fmt.Errorf("setup mount namespace %s", err)
|
return fmt.Errorf("setup mount namespace %s", err)
|
||||||
}
|
}
|
||||||
if err := system.Sethostname(container.Hostname); err != nil {
|
if err := system.Sethostname(container.Hostname); err != nil {
|
||||||
|
@ -116,21 +113,6 @@ func setupUser(container *libcontainer.Container) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// dupSlave dup2 the pty slave's fd into stdout and stdin and ensures that
|
|
||||||
// the slave's fd is 0, or stdin
|
|
||||||
func dupSlave(slave *os.File) error {
|
|
||||||
if err := system.Dup2(slave.Fd(), 0); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := system.Dup2(slave.Fd(), 1); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := system.Dup2(slave.Fd(), 2); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// setupVethNetwork uses the Network config if it is not nil to initialize
|
// setupVethNetwork uses the Network config if it is not nil to initialize
|
||||||
// the new veth interface inside the container for use by changing the name to eth0
|
// the new veth interface inside the container for use by changing the name to eth0
|
||||||
// setting the MTU and IP address along with the default gateway
|
// setting the MTU and IP address along with the default gateway
|
||||||
|
|
Loading…
Reference in New Issue