From 8b60273f76723897a9831ca125500ede85e05b5d Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 10 Jan 2014 15:34:03 -0800 Subject: [PATCH] Update with container specific waitLock Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- container.go | 9 ++++----- execdriver/lxc/driver.go | 8 +++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/container.go b/container.go index f801302154..33e39815e5 100644 --- a/container.go +++ b/container.go @@ -754,7 +754,7 @@ func (container *Container) Start() (err error) { if err := container.runtime.LogToDisk(container.stderr, container.logPath("json"), "stderr"); err != nil { return err } - + container.waitLock = make(chan struct{}) go container.monitor() if container.Config.Tty { @@ -1143,7 +1143,6 @@ func (container *Container) releaseNetwork() { func (container *Container) monitor() { // Wait for the program to exit - fmt.Printf("--->Before WAIT %s\n", container.ID) if container.process == nil { if err := container.runtime.Wait(container, 0); err != nil { utils.Debugf("monitor: cmd.Wait reported exit status %s for container %s", err, container.ID) @@ -1161,7 +1160,6 @@ func (container *Container) monitor() { } } - fmt.Printf("--->After WAIT %s\n", container.ID) // Cleanup container.cleanup() @@ -1173,6 +1171,7 @@ func (container *Container) monitor() { exitCode := container.process.GetExitCode() container.State.SetStopped(exitCode) + close(container.waitLock) if err := container.ToDisk(); err != nil { // FIXME: there is a race condition here which causes this to fail during the unit tests. // If another goroutine was waiting for Wait() to return before removing the container's root @@ -1286,8 +1285,8 @@ func (container *Container) Restart(seconds int) error { // Wait blocks until the container stops running, then returns its exit code. func (container *Container) Wait() int { - <-container.process.WaitLock - return container.process.GetExitCode() + <-container.waitLock + return container.State.GetExitCode() } func (container *Container) Resize(h, w int) error { diff --git a/execdriver/lxc/driver.go b/execdriver/lxc/driver.go index 64e89c5c21..e9bddf1af5 100644 --- a/execdriver/lxc/driver.go +++ b/execdriver/lxc/driver.go @@ -17,6 +17,7 @@ const ( var ( ErrNotRunning = errors.New("Process could not be started") ErrWaitTimeoutReached = errors.New("Wait timeout reached") + Debug bool ) func init() { @@ -120,7 +121,12 @@ func (d *driver) Wait(id string, duration time.Duration) error { } func (d *driver) kill(c *execdriver.Process, sig int) error { - return exec.Command("lxc-kill", "-n", c.ID, strconv.Itoa(sig)).Run() + output, err := exec.Command("lxc-kill", "-n", c.ID, strconv.Itoa(sig)).CombinedOutput() + if err != nil { + fmt.Printf("--->%s\n", output) + return fmt.Errorf("Err: %s Output: %s", err, output) + } + return nil } func (d *driver) waitForStart(c *execdriver.Process) error {