Skip to content

Commit

Permalink
Handle more states during refresh
Browse files Browse the repository at this point in the history
We were preserving ContainerStateExited, which is better than
nothing, but definitely not correct. A container that ran at any
point during the last boot should be moved to Exited state to
preserve the fact that they were run at least one. This means we
have to convert Running, Stopped, Stopping, Paused containers to
exited as well.

Signed-off-by: Matt Heon <mheon@redhat.com>
  • Loading branch information
mheon committed Feb 7, 2024
1 parent 9983e87 commit 3cf2f8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,19 @@ func resetContainerState(state *ContainerState) {
state.ConmonPID = 0
state.Mountpoint = ""
state.Mounted = false
if state.State != define.ContainerStateExited {
// Reset state.
// Almost all states are reset to either Configured or Exited,
// except ContainerStateRemoving which is preserved.
switch state.State {
case define.ContainerStateStopped, define.ContainerStateExited, define.ContainerStateStopping, define.ContainerStateRunning, define.ContainerStatePaused:
// All containers that ran at any point during the last boot
// must be placed in the Exited state.
state.State = define.ContainerStateExited
case define.ContainerStateConfigured, define.ContainerStateCreated:
state.State = define.ContainerStateConfigured
case define.ContainerStateUnknown:
// Something really strange must have happened to get us here.
// Reset to configured, maybe the reboot cleared things up?
state.State = define.ContainerStateConfigured
}
state.ExecSessions = make(map[string]*ExecSession)
Expand Down
2 changes: 1 addition & 1 deletion libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ func (r *Runtime) refresh(ctx context.Context, alivePath string) error {
}
// This is the only place it's safe to use ctr.state.State unlocked
// We're holding the alive lock, guaranteed to be the only Libpod on the system right now.
if ctr.AutoRemove() && ctr.state.State == define.ContainerStateExited {
if (ctr.AutoRemove() && ctr.state.State == define.ContainerStateExited) || ctr.state.State == define.ContainerStateRemoving {
opts := ctrRmOpts{
// Don't force-remove, we're supposed to be fresh off a reboot
// If we have to force something is seriously wrong
Expand Down

0 comments on commit 3cf2f8c

Please sign in to comment.