mirror of
https://github.com/containers/podman.git
synced 2025-05-29 22:46:25 +08:00
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>
This commit is contained in:
@ -75,7 +75,7 @@ func BatchContainerOp(ctr *libpod.Container, opts PsOptions) (BatchContainerStru
|
|||||||
return errors.Wrapf(err, "unable to obtain container state")
|
return errors.Wrapf(err, "unable to obtain container state")
|
||||||
}
|
}
|
||||||
|
|
||||||
exitCode, err = c.ExitCode()
|
exitCode, _, err = c.ExitCode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "unable to obtain container exit code")
|
return errors.Wrapf(err, "unable to obtain container exit code")
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ func generateContainerFilterFuncs(filter, filterValue string, runtime *libpod.Ru
|
|||||||
return nil, errors.Wrapf(err, "exited code out of range %q", filterValue)
|
return nil, errors.Wrapf(err, "exited code out of range %q", filterValue)
|
||||||
}
|
}
|
||||||
return func(c *libpod.Container) bool {
|
return func(c *libpod.Container) bool {
|
||||||
ec, err := c.ExitCode()
|
ec, _, err := c.ExitCode()
|
||||||
if ec == int32(exitCode) && err == nil {
|
if ec == int32(exitCode) && err == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,8 @@ type containerState struct {
|
|||||||
FinishedTime time.Time `json:"finishedTime,omitempty"`
|
FinishedTime time.Time `json:"finishedTime,omitempty"`
|
||||||
// ExitCode is the exit code returned when the container stopped
|
// ExitCode is the exit code returned when the container stopped
|
||||||
ExitCode int32 `json:"exitCode,omitempty"`
|
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
|
// OOMKilled indicates that the container was killed as it ran out of
|
||||||
// memory
|
// memory
|
||||||
OOMKilled bool `json:"oomKilled,omitempty"`
|
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
|
// ExitCode returns the exit code of the container as
|
||||||
// an int32
|
// an int32, and whether the container has exited.
|
||||||
func (c *Container) ExitCode() (int32, error) {
|
// 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 {
|
if !c.batched {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
if err := c.syncContainer(); err != nil {
|
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
|
// OOMKilled returns whether the container was killed by an OOM condition
|
||||||
|
@ -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
|
// Set and save now to make sure that, if the init() below fails
|
||||||
// we still have a valid state
|
// we still have a valid state
|
||||||
c.state.State = ContainerStateConfigured
|
c.state.State = ContainerStateConfigured
|
||||||
|
c.state.ExitCode = 0
|
||||||
|
c.state.Exited = false
|
||||||
if err := c.save(); err != nil {
|
if err := c.save(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -450,6 +450,7 @@ func (r *OCIRuntime) updateContainerStatus(ctr *Container) error {
|
|||||||
ctr.state.OOMKilled = true
|
ctr.state.OOMKilled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctr.state.Exited = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user