mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
podman: podman rm -f doesn't leave processes
follow-up to 6886e80b45caae27dda81a9b44d8dd179c414580 when "podman -rm -f" is used on a container in "stopping" state, also make sure it is terminated before removing it from the local storage. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> (cherry picked from commit 4cf06fe7e074cb9a09670f8308ade12f30bb958d)
This commit is contained in:
@ -698,7 +698,7 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force, remo
|
||||
}
|
||||
|
||||
// Check that the container's in a good state to be removed.
|
||||
if c.state.State == define.ContainerStateRunning {
|
||||
if c.ensureState(define.ContainerStateRunning, define.ContainerStateStopping) {
|
||||
time := c.StopTimeout()
|
||||
if timeout != nil {
|
||||
time = *timeout
|
||||
|
@ -103,9 +103,8 @@ load helpers
|
||||
is "$output" "" "Should print no output"
|
||||
}
|
||||
|
||||
@test "podman container rm doesn't affect stopping containers" {
|
||||
local cname=c$(random_string 30)
|
||||
run_podman run -d --name $cname \
|
||||
function __run_healthcheck_container() {
|
||||
run_podman run -d --name $1 \
|
||||
--health-cmd /bin/false \
|
||||
--health-interval 1s \
|
||||
--health-retries 2 \
|
||||
@ -115,6 +114,11 @@ load helpers
|
||||
--health-start-period 0 \
|
||||
--stop-signal SIGTERM \
|
||||
$IMAGE sleep infinity
|
||||
}
|
||||
|
||||
@test "podman container rm doesn't affect stopping containers" {
|
||||
local cname=c$(random_string 30)
|
||||
__run_healthcheck_container $cname
|
||||
local cid=$output
|
||||
|
||||
# We'll use the PID later to confirm that container is not running
|
||||
@ -149,4 +153,29 @@ load helpers
|
||||
fi
|
||||
}
|
||||
|
||||
@test "podman container rm --force doesn't leave running processes" {
|
||||
local cname=c$(random_string 30)
|
||||
__run_healthcheck_container $cname
|
||||
local cid=$output
|
||||
|
||||
# We'll use the PID later to confirm that container is not running
|
||||
run_podman inspect --format '{{.State.Pid}}' $cname
|
||||
local pid=$output
|
||||
|
||||
for i in {1..10}; do
|
||||
run_podman inspect $cname --format '{{.State.Status}}'
|
||||
if [ "$output" = "stopping" ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
run_podman rm -f $cname
|
||||
|
||||
if kill -0 $pid; then
|
||||
die "Container $cname process is still running (pid $pid)"
|
||||
fi
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
|
Reference in New Issue
Block a user