diff --git a/execdriver/native/driver.go b/execdriver/native/driver.go index e0ed5685e4..31b5ae290c 100644 --- a/execdriver/native/driver.go +++ b/execdriver/native/driver.go @@ -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 -} diff --git a/execdriver/native/info.go b/execdriver/native/info.go new file mode 100644 index 0000000000..a2ab7f2a0a --- /dev/null +++ b/execdriver/native/info.go @@ -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 +} diff --git a/execdriver/native/term.go b/execdriver/native/term.go index b32a80e4df..9b8e813aab 100644 --- a/execdriver/native/term.go +++ b/execdriver/native/term.go @@ -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 +}