Refactor driver to use Exec function from nsini

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-02-22 01:21:26 -08:00
parent 1271ddcd61
commit a42c6fafbe
2 changed files with 15 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
) )
type StateWriter interface { type StateWriter interface {
@ -12,13 +13,14 @@ type StateWriter interface {
} }
type DefaultStateWriter struct { type DefaultStateWriter struct {
Root string
} }
// writePidFile writes the namespaced processes pid to .nspid in the rootfs for the container // writePidFile writes the namespaced processes pid to .nspid in the rootfs for the container
func (*DefaultStateWriter) WritePid(pid int) error { func (d *DefaultStateWriter) WritePid(pid int) error {
return ioutil.WriteFile(".nspid", []byte(fmt.Sprint(pid)), 0655) return ioutil.WriteFile(filepath.Join(d.Root, ".nspid"), []byte(fmt.Sprint(pid)), 0655)
} }
func (*DefaultStateWriter) DeletePid() error { func (d *DefaultStateWriter) DeletePid() error {
return os.Remove(".nspid") return os.Remove(filepath.Join(d.Root, ".nspid"))
} }

View file

@ -11,6 +11,7 @@ type Terminal interface {
io.Closer io.Closer
SetMaster(*os.File) SetMaster(*os.File)
Attach(*exec.Cmd) error Attach(*exec.Cmd) error
Resize(h, w int) error
} }
func NewTerminal(stdin io.Reader, stdout, stderr io.Writer, tty bool) Terminal { func NewTerminal(stdin io.Reader, stdout, stderr io.Writer, tty bool) Terminal {
@ -35,6 +36,10 @@ type TtyTerminal struct {
state *term.State state *term.State
} }
func (t *TtyTerminal) Resize(h, w int) error {
return term.SetWinsize(t.master.Fd(), &term.Winsize{Height: uint16(h), Width: uint16(w)})
}
func (t *TtyTerminal) SetMaster(master *os.File) { func (t *TtyTerminal) SetMaster(master *os.File) {
t.master = master t.master = master
} }
@ -83,6 +88,10 @@ func (s *StdTerminal) Close() error {
return nil return nil
} }
func (s *StdTerminal) Resize(h, w int) error {
return nil
}
func (s *StdTerminal) Attach(command *exec.Cmd) error { func (s *StdTerminal) Attach(command *exec.Cmd) error {
inPipe, err := command.StdinPipe() inPipe, err := command.StdinPipe()
if err != nil { if err != nil {