From f21dde566641ee9d80730cc04f16d75df8b05036 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Fri, 28 Sep 2018 15:51:51 -0700 Subject: runsc: allow `kill --all` when container is in stopped state. PiperOrigin-RevId: 215009105 Change-Id: I1ab12eddf7694c4db98f6dafca9dae352a33f7c4 --- runsc/container/container.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'runsc') 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) } -- cgit v1.2.3