summaryrefslogtreecommitdiffhomepage
path: root/runsc/container/container.go
diff options
context:
space:
mode:
authorLantao Liu <lantaol@google.com>2018-07-02 14:51:20 -0700
committerShentubot <shentubot@google.com>2018-07-02 14:52:21 -0700
commit126296ce2adce615005ae16edb8b80e3bfae56cd (patch)
tree7851ede599ca90f9a09c601e7b5a76a340e5d098 /runsc/container/container.go
parentfa64c2a1517d20c08447bb2230f2903ec3baade9 (diff)
runsc: fix panic for `runsc wait` on stopped container.
PiperOrigin-RevId: 203016694 Change-Id: Ic51ef754aa6d7d1b3b35491aff96a63d7992e122
Diffstat (limited to 'runsc/container/container.go')
-rw-r--r--runsc/container/container.go9
1 files changed, 9 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)
}