diff options
author | Matthew Heon <mheon@redhat.com> | 2018-01-29 11:59:33 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-01-30 05:02:12 +0000 |
commit | c60d8a0671b48ffdeda68895e0b7d97b252d66d9 (patch) | |
tree | 6be6b971913ae7763b79d7eef68dc71284a841c5 /libpod/container_internal.go | |
parent | dd133a1ad25f75e5ddd53ed6cf59eedfb6838f54 (diff) | |
download | podman-c60d8a0671b48ffdeda68895e0b7d97b252d66d9.tar.gz podman-c60d8a0671b48ffdeda68895e0b7d97b252d66d9.tar.bz2 podman-c60d8a0671b48ffdeda68895e0b7d97b252d66d9.zip |
Add StopWithTimeout API function for containers
Normal Stop should not need a timeout, and should use the default
Add a function that does accept a timeout aside it
Signed-off-by: Matthew Heon <mheon@redhat.com>
Closes: #272
Approved by: rhatdan
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r-- | libpod/container_internal.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 9b785bfa5..fd8e826ba 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -302,6 +302,28 @@ func (c *Container) save() error { return nil } +// Internal, non-locking function to stop container +func (c *Container) stop(timeout uint) error { + logrus.Debugf("Stopping ctr %s with timeout %d", c.ID(), timeout) + + if c.state.State == ContainerStateConfigured || + c.state.State == ContainerStateUnknown || + c.state.State == ContainerStatePaused { + return errors.Wrapf(ErrCtrStateInvalid, "can only stop created, running, or stopped containers") + } + + if err := c.runtime.ociRuntime.stopContainer(c, timeout); err != nil { + return err + } + + // Sync the container's state to pick up return code + if err := c.runtime.ociRuntime.updateContainerStatus(c); err != nil { + return err + } + + return c.cleanupStorage() +} + // mountStorage sets up the container's root filesystem // It mounts the image and any other requested mounts // TODO: Add ability to override mount label so we can use this for Mount() too |