mirror of
https://github.com/containers/podman.git
synced 2025-05-17 23:26:08 +08:00
podman wait: return 0 if container never ran
Make sure to return/exit with 0 when waiting for a container that never ran. Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
@ -551,6 +551,10 @@ func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration)
|
||||
|
||||
exitCode, err := c.runtime.state.GetContainerExitCode(id)
|
||||
if err != nil {
|
||||
if errors.Is(err, define.ErrNoSuchExitCode) && c.ensureState(define.ContainerStateConfigured, define.ContainerStateCreated) {
|
||||
// The container never ran.
|
||||
return true, 0, nil
|
||||
}
|
||||
return true, -1, err
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ func (r *ConmonOCIRuntime) UpdateContainerStatus(ctr *Container) error {
|
||||
ctr.state.ExitCode = -1
|
||||
ctr.state.FinishedTime = time.Now()
|
||||
ctr.state.State = define.ContainerStateExited
|
||||
return nil
|
||||
return ctr.runtime.state.AddContainerExitCode(ctr.ID(), ctr.state.ExitCode)
|
||||
}
|
||||
return fmt.Errorf("error getting container %s state. stderr/out: %s: %w", ctr.ID(), out, err)
|
||||
}
|
||||
|
@ -140,4 +140,15 @@ load helpers
|
||||
run_podman rm -f $random_name
|
||||
}
|
||||
|
||||
@test "podman wait - exit codes" {
|
||||
random_name=$(random_string 10)
|
||||
run_podman create --name=$random_name $IMAGE /no/such/command
|
||||
# Container never ran -> exit code == 0
|
||||
run_podman wait $random_name
|
||||
# Container did not start successfully -> exit code != 0
|
||||
run_podman 125 start $random_name
|
||||
# FIXME(#14873): while older Podmans return 0 on wait, Docker does not.
|
||||
run_podman wait $random_name
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
|
Reference in New Issue
Block a user