summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-02-27 10:59:53 -0600
committerBrent Baude <bbaude@redhat.com>2020-02-28 09:36:53 -0600
commit09048731000e73b44a0243a0339d8c122eb8a165 (patch)
treedb939805cbb41f4ddd2db610256ba2186a8367db /libpod
parentbaf27fa25eed668b5a73a1d7d4fe16214f1c260f (diff)
downloadpodman-09048731000e73b44a0243a0339d8c122eb8a165.tar.gz
podman-09048731000e73b44a0243a0339d8c122eb8a165.tar.bz2
podman-09048731000e73b44a0243a0339d8c122eb8a165.zip
rework apiv2 wait endpoint|binding
added the ability to wait on a condition (stopped, running, paused...) for a container. if a condition is not provided, wait will default to the stopped condition which uses the original wait code paths. if the condition is stopped, the container exit code will be returned. also, correct a mux issue we discovered. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_api.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index d612341bc..77fa372cc 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -629,6 +629,26 @@ func (c *Container) WaitWithInterval(waitTimeout time.Duration) (int32, error) {
}
}
+func (c *Container) WaitForConditionWithInterval(waitTimeout time.Duration, condition define.ContainerStatus) (int32, error) {
+ if !c.valid {
+ return -1, define.ErrCtrRemoved
+ }
+ if condition == define.ContainerStateStopped || condition == define.ContainerStateExited {
+ return c.WaitWithInterval(waitTimeout)
+ }
+ for {
+ state, err := c.State()
+ if err != nil {
+ return -1, err
+ }
+ if state == condition {
+ break
+ }
+ time.Sleep(waitTimeout)
+ }
+ return -1, nil
+}
+
// Cleanup unmounts all mount points in container and cleans up container storage
// It also cleans up the network stack
func (c *Container) Cleanup(ctx context.Context) error {