mirror of https://github.com/docker/docs.git
Update with container specific waitLock
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
8e87835968
commit
8b60273f76
|
@ -754,7 +754,7 @@ func (container *Container) Start() (err error) {
|
||||||
if err := container.runtime.LogToDisk(container.stderr, container.logPath("json"), "stderr"); err != nil {
|
if err := container.runtime.LogToDisk(container.stderr, container.logPath("json"), "stderr"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
container.waitLock = make(chan struct{})
|
||||||
go container.monitor()
|
go container.monitor()
|
||||||
|
|
||||||
if container.Config.Tty {
|
if container.Config.Tty {
|
||||||
|
@ -1143,7 +1143,6 @@ func (container *Container) releaseNetwork() {
|
||||||
|
|
||||||
func (container *Container) monitor() {
|
func (container *Container) monitor() {
|
||||||
// Wait for the program to exit
|
// Wait for the program to exit
|
||||||
fmt.Printf("--->Before WAIT %s\n", container.ID)
|
|
||||||
if container.process == nil {
|
if container.process == nil {
|
||||||
if err := container.runtime.Wait(container, 0); err != 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)
|
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
|
// Cleanup
|
||||||
container.cleanup()
|
container.cleanup()
|
||||||
|
|
||||||
|
@ -1173,6 +1171,7 @@ func (container *Container) monitor() {
|
||||||
exitCode := container.process.GetExitCode()
|
exitCode := container.process.GetExitCode()
|
||||||
container.State.SetStopped(exitCode)
|
container.State.SetStopped(exitCode)
|
||||||
|
|
||||||
|
close(container.waitLock)
|
||||||
if err := container.ToDisk(); err != nil {
|
if err := container.ToDisk(); err != nil {
|
||||||
// FIXME: there is a race condition here which causes this to fail during the unit tests.
|
// 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
|
// 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.
|
// Wait blocks until the container stops running, then returns its exit code.
|
||||||
func (container *Container) Wait() int {
|
func (container *Container) Wait() int {
|
||||||
<-container.process.WaitLock
|
<-container.waitLock
|
||||||
return container.process.GetExitCode()
|
return container.State.GetExitCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) Resize(h, w int) error {
|
func (container *Container) Resize(h, w int) error {
|
||||||
|
|
|
@ -17,6 +17,7 @@ const (
|
||||||
var (
|
var (
|
||||||
ErrNotRunning = errors.New("Process could not be started")
|
ErrNotRunning = errors.New("Process could not be started")
|
||||||
ErrWaitTimeoutReached = errors.New("Wait timeout reached")
|
ErrWaitTimeoutReached = errors.New("Wait timeout reached")
|
||||||
|
Debug bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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 {
|
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 {
|
func (d *driver) waitForStart(c *execdriver.Process) error {
|
||||||
|
|
Loading…
Reference in New Issue