mirror of
https://github.com/containers/podman.git
synced 2025-07-04 10:10:32 +08:00
Ensure podman ps --sync
functions
The backend for `ps --sync` has been nonfunctional for a long while now - probably since v2.0. It's questionable how useful the flag is in modern Podman (the original case it was intended to catch, Conmon gone via SIGKILL, should be handled now via pinging the process with a signal to ensure it's still alive) but having the ability to force a refresh of container state from the OCI runtime is still useful. Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
@ -690,7 +690,7 @@ func (c *Container) Sync() error {
|
||||
|
||||
// If runtime knows about the container, update its status in runtime
|
||||
// And then save back to disk
|
||||
if c.ensureState(define.ContainerStateCreated, define.ContainerStateRunning, define.ContainerStatePaused, define.ContainerStateStopped) {
|
||||
if c.ensureState(define.ContainerStateCreated, define.ContainerStateRunning, define.ContainerStatePaused, define.ContainerStateStopped, define.ContainerStateStopping) {
|
||||
oldState := c.state.State
|
||||
if err := c.ociRuntime.UpdateContainerStatus(c); err != nil {
|
||||
return err
|
||||
|
@ -351,6 +351,12 @@ func (r *ConmonOCIRuntime) UpdateContainerStatus(ctr *Container) error {
|
||||
return ctr.handleExitFile(exitFile, fi)
|
||||
}
|
||||
|
||||
// Handle ContainerStateStopping - keep it unless the container
|
||||
// transitioned to no longer running.
|
||||
if oldState == define.ContainerStateStopping && (ctr.state.State == define.ContainerStatePaused || ctr.state.State == define.ContainerStateRunning) {
|
||||
ctr.state.State = define.ContainerStateStopping
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -136,6 +136,12 @@ func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities
|
||||
)
|
||||
|
||||
batchErr := ctr.Batch(func(c *libpod.Container) error {
|
||||
if opts.Sync {
|
||||
if err := c.Sync(); err != nil {
|
||||
return errors.Wrapf(err, "unable to update container state from OCI runtime")
|
||||
}
|
||||
}
|
||||
|
||||
conConfig = c.Config()
|
||||
conState, err = c.State()
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user