diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-10-16 11:05:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-16 11:05:45 +0200 |
commit | 8172460f2a09910d611d2d61655fb3682caca09f (patch) | |
tree | 8569cfb4c571e215d0323614da7be563b3cfa6f6 /libpod/container_internal.go | |
parent | 7b54aeb6e3dca3511daa1e511625f7e446fbc710 (diff) | |
parent | cab7bfbb211f2496af9f86208588e26954fc9b2a (diff) | |
download | podman-8172460f2a09910d611d2d61655fb3682caca09f.tar.gz podman-8172460f2a09910d611d2d61655fb3682caca09f.tar.bz2 podman-8172460f2a09910d611d2d61655fb3682caca09f.zip |
Merge pull request #4273 from mheon/no_runtime
Add a MissingRuntime implementation
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r-- | libpod/container_internal.go | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index a7ac23f73..0043c9651 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -252,7 +252,7 @@ func (c *Container) waitForExitFileAndSync() error { return err } - if err := c.ociRuntime.UpdateContainerStatus(c, false); err != nil { + if err := c.checkExitFile(); err != nil { return err } @@ -386,10 +386,11 @@ func (c *Container) syncContainer() error { (c.state.State != define.ContainerStateConfigured) && (c.state.State != define.ContainerStateExited) { oldState := c.state.State - // TODO: optionally replace this with a stat for the exit file - if err := c.ociRuntime.UpdateContainerStatus(c, false); err != nil { + + if err := c.checkExitFile(); err != nil { return err } + // Only save back to DB if state changed if c.state.State != oldState { // Check for a restart policy match @@ -1811,3 +1812,35 @@ func (c *Container) sortUserVolumes(ctrSpec *spec.Spec) ([]*ContainerNamedVolume } return namedUserVolumes, userMounts } + +// Check for an exit file, and handle one if present +func (c *Container) checkExitFile() error { + // If the container's not running, nothing to do. + if c.state.State != define.ContainerStateRunning && c.state.State != define.ContainerStatePaused { + return nil + } + + exitFile, err := c.exitFilePath() + if err != nil { + return err + } + + // Check for the exit file + info, err := os.Stat(exitFile) + if err != nil { + if os.IsNotExist(err) { + // Container is still running, no error + return nil + } + + return errors.Wrapf(err, "error running stat on container %s exit file", c.ID()) + } + + // Alright, it exists. Transition to Stopped state. + c.state.State = define.ContainerStateStopped + c.state.PID = 0 + c.state.ConmonPID = 0 + + // Read the exit file to get our stopped time and exit code. + return c.handleExitFile(exitFile, info) +} |