From 589867d7169499ca18a97c8ea844958250f504f7 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Thu, 7 Sep 2023 14:56:43 +0200 Subject: [PATCH] podman: don't restart after kill Also add a new `StoppedByUser` field to the container-inspect state which can be useful during debugging and is now also used in the regression test. Note that I moved the `false` check one test above such that we can compare the previous Podman version which should just be stuck in the `wait $ctr` command since it will continue restarting. Signed-off-by: Valentin Rothberg --- libpod/container_api.go | 2 +- libpod/container_inspect.go | 1 + libpod/define/container_inspect.go | 1 + test/system/130-kill.bats | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libpod/container_api.go b/libpod/container_api.go index 1c630081f5..337ff7c39d 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -292,7 +292,7 @@ func (c *Container) Kill(signal uint) error { return c.waitForConmonToExitAndSave() } - return nil + return c.save() } // Attach attaches to a container. diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go index 19242632fc..7578e9e178 100644 --- a/libpod/container_inspect.go +++ b/libpod/container_inspect.go @@ -140,6 +140,7 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver CheckpointPath: runtimeInfo.CheckpointPath, CheckpointLog: runtimeInfo.CheckpointLog, RestoreLog: runtimeInfo.RestoreLog, + StoppedByUser: c.state.StoppedByUser, }, Image: config.RootfsImageID, ImageName: config.RootfsImageName, diff --git a/libpod/define/container_inspect.go b/libpod/define/container_inspect.go index 457de626c9..de4f700fa4 100644 --- a/libpod/define/container_inspect.go +++ b/libpod/define/container_inspect.go @@ -228,6 +228,7 @@ type InspectContainerState struct { CheckpointPath string `json:"CheckpointPath,omitempty"` RestoreLog string `json:"RestoreLog,omitempty"` Restored bool `json:"Restored,omitempty"` + StoppedByUser bool `json:"StoppedByUser,omitempty"` } // Healthcheck returns the HealthCheckResults. This is used for old podman compat diff --git a/test/system/130-kill.bats b/test/system/130-kill.bats index ad06bbade3..013edc3d5c 100644 --- a/test/system/130-kill.bats +++ b/test/system/130-kill.bats @@ -145,6 +145,8 @@ load helpers @test "podman wait - exit codes" { random_name=$(random_string 10) run_podman create --name=$random_name $IMAGE /no/such/command + run_podman container inspect --format "{{.State.StoppedByUser}}" $random_name + is "$output" "false" "container not marked to be stopped by a user" # Container never ran -> exit code == 0 run_podman wait $random_name # Container did not start successfully -> exit code != 0 @@ -153,4 +155,18 @@ load helpers run_podman wait $random_name } +@test "podman kill - no restart" { + ctr=$(random_string 10) + run_podman run -d --restart=always --name=$ctr $IMAGE \ + sh -c "trap 'exit 42' SIGTERM; echo READY; while :; do sleep 0.2; done" + run_podman container inspect --format "{{.State.Status}}" $ctr + is "$output" "running" "make sure container is running" + # Send SIGTERM and make sure the container exits. + run_podman kill -s=TERM $ctr + run_podman wait $ctr + is "$output" "42" "container exits with 42 on receiving SIGTERM" + run_podman container inspect --format "{{.State.StoppedByUser}}" $ctr + is "$output" "true" "container is marked to be stopped by a user" +} + # vim: filetype=sh