diff options
author | Lantao Liu <lantaol@google.com> | 2018-09-28 15:51:51 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-09-28 15:53:25 -0700 |
commit | f21dde566641ee9d80730cc04f16d75df8b05036 (patch) | |
tree | 2b41e1f30bd739ad4af0b147f8b1537fe95baf39 | |
parent | 49ff81a42b51a3fa2ee139e1e86179fa0c427a86 (diff) |
runsc: allow `kill --all` when container is in stopped state.
PiperOrigin-RevId: 215009105
Change-Id: I1ab12eddf7694c4db98f6dafca9dae352a33f7c4
-rw-r--r-- | runsc/container/container.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/runsc/container/container.go b/runsc/container/container.go index e65800b8d..e09ed9347 100644 --- a/runsc/container/container.go +++ b/runsc/container/container.go @@ -472,9 +472,17 @@ func (c *Container) WaitPID(pid int32, clearStatus bool) (syscall.WaitStatus, er // TODO: Distinguish different error types. func (c *Container) Signal(sig syscall.Signal, all bool) error { log.Debugf("Signal container %q: %v", c.ID, sig) - if err := c.requireStatus("signal", Running); err != nil { + // Signaling container in Stopped state is allowed. When all=false, + // an error will be returned anyway; when all=true, this allows + // sending signal to other processes inside the container even + // after the init process exits. This is especially useful for + // container cleanup. + if err := c.requireStatus("signal", Running, Stopped); err != nil { return err } + if !c.isSandboxRunning() { + return fmt.Errorf("container is not running") + } // TODO: Query the container for its state, then save it. return c.Sandbox.Signal(c.ID, sig, all) } |