1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Move types around in native driver

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-02-24 21:21:35 -08:00
parent f8453cd049
commit 8db740a38e
3 changed files with 55 additions and 59 deletions

View file

@ -5,11 +5,9 @@ import (
"errors"
"fmt"
"github.com/dotcloud/docker/execdriver"
"github.com/dotcloud/docker/execdriver/lxc"
"github.com/dotcloud/docker/pkg/cgroups"
"github.com/dotcloud/docker/pkg/libcontainer"
"github.com/dotcloud/docker/pkg/libcontainer/nsinit"
"io"
"io/ioutil"
"os"
"os/exec"
@ -20,7 +18,7 @@ import (
)
const (
DriverName = "namespaces"
DriverName = "native"
Version = "0.1"
)
@ -30,7 +28,10 @@ var (
func init() {
execdriver.RegisterInitFunc(DriverName, func(args *execdriver.InitArgs) error {
var container *libcontainer.Container
var (
container *libcontainer.Container
ns = nsinit.NewNsInit(&nsinit.DefaultCommandFactory{}, &nsinit.DefaultStateWriter{})
)
f, err := os.Open("container.json")
if err != nil {
return err
@ -49,7 +50,6 @@ func init() {
if err != nil {
return err
}
ns := nsinit.NewNsInit(&nsinit.DefaultCommandFactory{}, &nsinit.DefaultStateWriter{})
if err := ns.Init(container, cwd, args.Console, syncPipe, args.Args); err != nil {
return err
}
@ -61,19 +61,6 @@ type driver struct {
root string
}
type info struct {
ID string
driver *driver
}
func (i *info) IsRunning() bool {
p := filepath.Join(i.driver.root, "containers", i.ID, "root", ".nspid")
if _, err := os.Stat(p); err == nil {
return true
}
return false
}
func NewDriver(root string) (*driver, error) {
return &driver{
root: root,
@ -90,8 +77,8 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
c: c,
dsw: &nsinit.DefaultStateWriter{c.Rootfs},
}
ns = nsinit.NewNsInit(factory, stateWriter)
)
ns := nsinit.NewNsInit(factory, stateWriter)
if c.Tty {
term = &dockerTtyTerm{
pipes: pipes,
@ -280,33 +267,3 @@ func createContainer(c *execdriver.Command) *libcontainer.Container {
}
return container
}
type dockerStdTerm struct {
lxc.StdConsole
pipes *execdriver.Pipes
}
func (d *dockerStdTerm) Attach(cmd *exec.Cmd) error {
return d.AttachPipes(cmd, d.pipes)
}
func (d *dockerStdTerm) SetMaster(master *os.File) {
// do nothing
}
type dockerTtyTerm struct {
lxc.TtyConsole
pipes *execdriver.Pipes
}
func (t *dockerTtyTerm) Attach(cmd *exec.Cmd) error {
go io.Copy(t.pipes.Stdout, t.MasterPty)
if t.pipes.Stdin != nil {
go io.Copy(t.MasterPty, t.pipes.Stdin)
}
return nil
}
func (t *dockerTtyTerm) SetMaster(master *os.File) {
t.MasterPty = master
}

22
execdriver/native/info.go Normal file
View file

@ -0,0 +1,22 @@
package native
import (
"os"
"path/filepath"
)
type info struct {
ID string
driver *driver
}
// IsRunning is determined by looking for the
// .nspid file for a container. If the file exists then the
// container is currently running
func (i *info) IsRunning() bool {
p := filepath.Join(i.driver.root, "containers", i.ID, "root", ".nspid")
if _, err := os.Stat(p); err == nil {
return true
}
return false
}

View file

@ -1,26 +1,43 @@
/*
These types are wrappers around the libcontainer Terminal interface so that
we can resuse the docker implementations where possible.
*/
package native
import (
"github.com/dotcloud/docker/execdriver"
"github.com/dotcloud/docker/pkg/term"
"github.com/dotcloud/docker/execdriver/lxc"
"io"
"os"
"os/exec"
)
type NsinitTerm struct {
master *os.File
type dockerStdTerm struct {
lxc.StdConsole
pipes *execdriver.Pipes
}
func NewTerm(pipes *execdriver.Pipes, master *os.File) *NsinitTerm {
return &NsinitTerm{master}
func (d *dockerStdTerm) Attach(cmd *exec.Cmd) error {
return d.AttachPipes(cmd, d.pipes)
}
func (t *NsinitTerm) Close() error {
return t.master.Close()
func (d *dockerStdTerm) SetMaster(master *os.File) {
// do nothing
}
func (t *NsinitTerm) Resize(h, w int) error {
if t.master != nil {
return term.SetWinsize(t.master.Fd(), &term.Winsize{Height: uint16(h), Width: uint16(w)})
type dockerTtyTerm struct {
lxc.TtyConsole
pipes *execdriver.Pipes
}
func (t *dockerTtyTerm) Attach(cmd *exec.Cmd) error {
go io.Copy(t.pipes.Stdout, t.MasterPty)
if t.pipes.Stdin != nil {
go io.Copy(t.MasterPty, t.pipes.Stdin)
}
return nil
}
func (t *dockerTtyTerm) SetMaster(master *os.File) {
t.MasterPty = master
}