summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2017-11-24 09:08:59 -0600
committerAtomic Bot <atomic-devel@projectatomic.io>2017-11-27 19:05:59 +0000
commit52ea0deee64c7466635452c62354604bdc7b48b4 (patch)
treef2c49a453f51370d6eb9da6c186117b33480e8fa /libpod
parent99f905243be351c4ca3c878dfe1a86e38169569d (diff)
downloadpodman-52ea0deee64c7466635452c62354604bdc7b48b4.tar.gz
podman-52ea0deee64c7466635452c62354604bdc7b48b4.tar.bz2
podman-52ea0deee64c7466635452c62354604bdc7b48b4.zip
kpod_wait
Convert to libpod container backend Signed-off-by: baude <bbaude@redhat.com> Closes: #70 Approved by: rhatdan
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/libpod/container.go b/libpod/container.go
index 8bd1a0abf..9ec0fb121 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -19,6 +19,7 @@ import (
crioAnnotations "github.com/projectatomic/libpod/pkg/annotations"
"github.com/sirupsen/logrus"
"github.com/ulule/deepcopier"
+ "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/remotecommand"
)
@@ -639,3 +640,35 @@ func (c *Container) Export(path string) error {
func (c *Container) Commit() (*storage.Image, error) {
return nil, ErrNotImplemented
}
+
+// Wait blocks on a container to exit and returns its exit code
+func (c *Container) Wait() (int32, error) {
+ err := wait.PollImmediateInfinite(1,
+ func() (bool, error) {
+ stopped, err := c.isStopped()
+ if err != nil {
+ return false, err
+ }
+ if !stopped {
+ return false, nil
+ } else { // nolint
+ return true, nil // nolint
+ } // nolint
+ },
+ )
+ if err != nil {
+ return 0, err
+ }
+ exitCode := c.state.ExitCode
+ return exitCode, nil
+}
+
+func (c *Container) isStopped() (bool, error) {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+ err := c.syncContainer()
+ if err != nil {
+ return true, err
+ }
+ return c.state.State == ContainerStateStopped, nil
+}