Skip to content

Commit 3cf2f8c

Browse files
committed
Handle more states during refresh
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 <[email protected]>
1 parent 9983e87 commit 3cf2f8c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

libpod/container_internal.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,19 @@ func resetContainerState(state *ContainerState) {
622622
state.ConmonPID = 0
623623
state.Mountpoint = ""
624624
state.Mounted = false
625-
if state.State != define.ContainerStateExited {
625+
// Reset state.
626+
// Almost all states are reset to either Configured or Exited,
627+
// except ContainerStateRemoving which is preserved.
628+
switch state.State {
629+
case define.ContainerStateStopped, define.ContainerStateExited, define.ContainerStateStopping, define.ContainerStateRunning, define.ContainerStatePaused:
630+
// All containers that ran at any point during the last boot
631+
// must be placed in the Exited state.
632+
state.State = define.ContainerStateExited
633+
case define.ContainerStateConfigured, define.ContainerStateCreated:
634+
state.State = define.ContainerStateConfigured
635+
case define.ContainerStateUnknown:
636+
// Something really strange must have happened to get us here.
637+
// Reset to configured, maybe the reboot cleared things up?
626638
state.State = define.ContainerStateConfigured
627639
}
628640
state.ExecSessions = make(map[string]*ExecSession)

libpod/runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ func (r *Runtime) refresh(ctx context.Context, alivePath string) error {
861861
}
862862
// This is the only place it's safe to use ctr.state.State unlocked
863863
// We're holding the alive lock, guaranteed to be the only Libpod on the system right now.
864-
if ctr.AutoRemove() && ctr.state.State == define.ContainerStateExited {
864+
if (ctr.AutoRemove() && ctr.state.State == define.ContainerStateExited) || ctr.state.State == define.ContainerStateRemoving {
865865
opts := ctrRmOpts{
866866
// Don't force-remove, we're supposed to be fresh off a reboot
867867
// If we have to force something is seriously wrong

0 commit comments

Comments
 (0)