summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorMatthew Heon <mheon@redhat.com>2018-07-13 10:24:17 -0400
committerMatthew Heon <mheon@redhat.com>2018-07-13 14:28:41 -0400
commit028374b99e5c9dd23236a10495ea0aebe819b51f (patch)
treebcae62cde75f78ce639b5925f1a485dec98d3218 /libpod
parent14a6d51a8432fc0c3324fec02e8729d3032f2af2 (diff)
downloadpodman-028374b99e5c9dd23236a10495ea0aebe819b51f.tar.gz
podman-028374b99e5c9dd23236a10495ea0aebe819b51f.tar.bz2
podman-028374b99e5c9dd23236a10495ea0aebe819b51f.zip
Record whether the container has exited
Use this to supplement exit codes returned from containers, to make sure we know when exit codes are invalid (as the container has not yet exited) Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container.go12
-rw-r--r--libpod/container_internal.go2
-rw-r--r--libpod/oci.go1
3 files changed, 11 insertions, 4 deletions
diff --git a/libpod/container.go b/libpod/container.go
index f882868ed..38f07bd5b 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -135,6 +135,8 @@ type containerState struct {
FinishedTime time.Time `json:"finishedTime,omitempty"`
// ExitCode is the exit code returned when the container stopped
ExitCode int32 `json:"exitCode,omitempty"`
+ // Exited is whether the container has exited
+ Exited bool `json:"exited,omitempty"`
// OOMKilled indicates that the container was killed as it ran out of
// memory
OOMKilled bool `json:"oomKilled,omitempty"`
@@ -667,16 +669,18 @@ func (c *Container) FinishedTime() (time.Time, error) {
}
// ExitCode returns the exit code of the container as
-// an int32
-func (c *Container) ExitCode() (int32, error) {
+// an int32, and whether the container has exited.
+// If the container has not exited, exit code will always be 0.
+// If the container restarts, the exit code is reset to 0.
+func (c *Container) ExitCode() (int32, bool, error) {
if !c.batched {
c.lock.Lock()
defer c.lock.Unlock()
if err := c.syncContainer(); err != nil {
- return 0, errors.Wrapf(err, "error updating container %s state", c.ID())
+ return 0, false, errors.Wrapf(err, "error updating container %s state", c.ID())
}
}
- return c.state.ExitCode, nil
+ return c.state.ExitCode, c.state.Exited, nil
}
// OOMKilled returns whether the container was killed by an OOM condition
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 905402c47..010d01315 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -586,6 +586,8 @@ func (c *Container) reinit(ctx context.Context) error {
// Set and save now to make sure that, if the init() below fails
// we still have a valid state
c.state.State = ContainerStateConfigured
+ c.state.ExitCode = 0
+ c.state.Exited = false
if err := c.save(); err != nil {
return err
}
diff --git a/libpod/oci.go b/libpod/oci.go
index c0478b3b6..3eaf159e7 100644
--- a/libpod/oci.go
+++ b/libpod/oci.go
@@ -450,6 +450,7 @@ func (r *OCIRuntime) updateContainerStatus(ctr *Container) error {
ctr.state.OOMKilled = true
}
+ ctr.state.Exited = true
}
return nil