From b41e42f42b59ea3b3b91a97bf89d7898d32e0861 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Fri, 8 Jul 2022 13:53:27 +0200 Subject: test/system/130-kill.bats: use $IMAGE A copy-paste error led to use `alpine` instead. Signed-off-by: Valentin Rothberg --- test/system/130-kill.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/system') diff --git a/test/system/130-kill.bats b/test/system/130-kill.bats index 96b633a42..3d800936a 100644 --- a/test/system/130-kill.bats +++ b/test/system/130-kill.bats @@ -133,7 +133,7 @@ load helpers @test "podman kill - concurrent stop" { # 14761 - concurrent kill/stop must record the exit code random_name=$(random_string 10) - run_podman run -d --replace --name=$random_name alpine sh -c "trap 'echo Received SIGTERM, ignoring' SIGTERM; echo READY; while :; do sleep 0.2; done" + run_podman run -d --replace --name=$random_name $IMAGE sh -c "trap 'echo Received SIGTERM, ignoring' SIGTERM; echo READY; while :; do sleep 0.2; done" $PODMAN stop -t 1 $random_name & run_podman kill $random_name run_podman wait $random_name -- cgit v1.2.3-54-g00ecf From 62cdc387de982feb796af71252a3fe3d504d570c Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Fri, 8 Jul 2022 15:17:43 +0200 Subject: 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 --- libpod/container_api.go | 4 ++++ libpod/oci_conmon_linux.go | 2 +- test/system/130-kill.bats | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'test/system') diff --git a/libpod/container_api.go b/libpod/container_api.go index dbd5fc1fb..742eb6d3e 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -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 } diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go index 0cdfe90e9..121e750f4 100644 --- a/libpod/oci_conmon_linux.go +++ b/libpod/oci_conmon_linux.go @@ -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) } diff --git a/test/system/130-kill.bats b/test/system/130-kill.bats index 3d800936a..7522c475d 100644 --- a/test/system/130-kill.bats +++ b/test/system/130-kill.bats @@ -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 -- cgit v1.2.3-54-g00ecf