diff --git a/container.go b/container.go index 0a0715890a..92da2c4e99 100644 --- a/container.go +++ b/container.go @@ -761,6 +761,8 @@ func (container *Container) Start() (err error) { return err } + container.State.SetRunning(container.process.Pid()) + // Init the lock container.waitLock = make(chan struct{}) @@ -1161,6 +1163,9 @@ func (container *Container) monitor() { container.stdin, container.stdinPipe = io.Pipe() } + exitCode := container.process.GetExitCode() + container.State.SetStopped(exitCode) + // Release the lock close(container.waitLock) diff --git a/execdriver/driver.go b/execdriver/driver.go index 543c7890d1..61d2b9e90c 100644 --- a/execdriver/driver.go +++ b/execdriver/driver.go @@ -4,7 +4,6 @@ import ( "errors" "io" "os/exec" - "sync" "syscall" "time" ) @@ -28,44 +27,7 @@ type Network struct { Mtu int } -type State struct { - sync.RWMutex - running bool - pid int - exitCode int - startedAt time.Time - finishedAt time.Time -} - -func (s *State) IsRunning() bool { - s.RLock() - defer s.RUnlock() - return s.running -} - -func (s *State) SetRunning() error { - s.Lock() - defer s.Unlock() - s.running = true - return nil -} - -func (s *State) SetStopped(exitCode int) error { - s.Lock() - defer s.Unlock() - s.exitCode = exitCode - s.running = false - return nil -} - -// Container / Process / Whatever, we can redefine the conatiner here -// to be what it should be and not have to carry the baggage of the -// container type in the core with backward compat. This is what a -// driver needs to execute a process inside of a conatiner. This is what -// a container is at it's core. type Process struct { - State State - Name string // unique name for the conatienr Privileged bool User string @@ -93,6 +55,10 @@ func (c *Process) SetCmd(cmd *exec.Cmd) error { return nil } +func (c *Process) Pid() int { + return c.cmd.Process.Pid +} + func (c *Process) StdinPipe() (io.WriteCloser, error) { return c.cmd.StdinPipe() } diff --git a/execdriver/lxc/driver.go b/execdriver/lxc/driver.go index b36e20986f..bed11c6809 100644 --- a/execdriver/lxc/driver.go +++ b/execdriver/lxc/driver.go @@ -38,10 +38,6 @@ func NewDriver(root string) (execdriver.Driver, error) { } func (d *driver) Start(c *execdriver.Process) error { - if c.State.IsRunning() { - return nil - } - params := []string{ startPath, "-n", c.Name, @@ -104,13 +100,10 @@ func (d *driver) Stop(c *execdriver.Process) error { return err } } - exitCode := c.GetExitCode() - return c.State.SetStopped(exitCode) + return nil } func (d *driver) Kill(c *execdriver.Process, sig int) error { - c.State.Lock() - defer c.State.Unlock() return d.kill(c, sig) } @@ -146,8 +139,7 @@ begin: return err } } - exitCode := c.GetExitCode() - return c.State.SetStopped(exitCode) + return nil } func (d *driver) kill(c *execdriver.Process, sig int) error { @@ -177,9 +169,11 @@ func (d *driver) waitForStart(cmd *exec.Cmd, c *execdriver.Process) error { // the end of this loop for now := time.Now(); time.Since(now) < 5*time.Second; { // If the container dies while waiting for it, just return - if !c.State.IsRunning() { - return nil - } + /* + if !c.State.IsRunning() { + return nil + } + */ output, err := exec.Command("lxc-info", "-s", "-n", c.Name).CombinedOutput() if err != nil { output, err = exec.Command("lxc-info", "-s", "-n", c.Name).CombinedOutput()