diff options
Diffstat (limited to 'runsc')
-rw-r--r-- | runsc/container/container.go | 9 | ||||
-rw-r--r-- | runsc/container/container_test.go | 6 |
2 files changed, 15 insertions, 0 deletions
diff --git a/runsc/container/container.go b/runsc/container/container.go index 30323138a..c4e5bf9f6 100644 --- a/runsc/container/container.go +++ b/runsc/container/container.go @@ -352,6 +352,9 @@ func (c *Container) Pid() int { // Wait waits for the container to exit, and returns its WaitStatus. func (c *Container) Wait() (syscall.WaitStatus, error) { log.Debugf("Wait on container %q", c.ID) + if c.Status == Stopped { + return 0, fmt.Errorf("container is stopped") + } return c.Sandbox.Wait(c.ID) } @@ -359,6 +362,9 @@ func (c *Container) Wait() (syscall.WaitStatus, error) { // returns its WaitStatus. func (c *Container) WaitRootPID(pid int32) (syscall.WaitStatus, error) { log.Debugf("Wait on pid %d in sandbox %q", pid, c.Sandbox.ID) + if c.Status == Stopped { + return 0, fmt.Errorf("container is stopped") + } return c.Sandbox.WaitPID(pid, c.Sandbox.ID) } @@ -366,6 +372,9 @@ func (c *Container) WaitRootPID(pid int32) (syscall.WaitStatus, error) { // its WaitStatus. func (c *Container) WaitPID(pid int32) (syscall.WaitStatus, error) { log.Debugf("Wait on pid %d in container %q", pid, c.ID) + if c.Status == Stopped { + return 0, fmt.Errorf("container is stopped") + } return c.Sandbox.WaitPID(pid, c.ID) } diff --git a/runsc/container/container_test.go b/runsc/container/container_test.go index a6bb39c5d..d2f3cc14a 100644 --- a/runsc/container/container_test.go +++ b/runsc/container/container_test.go @@ -1211,6 +1211,9 @@ func TestMultiContainerWait(t *testing.T) { } else if es := ws.ExitStatus(); es != 0 { t.Errorf("process %q exited with non-zero status %d", strings.Join(containers[1].Spec.Process.Args, " "), es) } + if _, err := containers[1].Wait(); err == nil { + t.Errorf("wait for stopped process %q should fail", strings.Join(containers[1].Spec.Process.Args, " ")) + } // After Wait returns, ensure that the root container is running and // the child has finished. @@ -1231,6 +1234,9 @@ func TestMultiContainerWait(t *testing.T) { } else if es := ws.ExitStatus(); es != 0 { t.Errorf("PID %d exited with non-zero status %d", pid, es) } + if _, err := containers[0].WaitPID(pid); err == nil { + t.Errorf("wait for stopped PID %d should fail", pid) + } }() } |