Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix podman stop -t -1 CID #21826

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1332,10 +1332,10 @@ func ParseRestartPolicy(policy string) (string, uint, error) {
return policyType, retriesUint, nil
}

// ConvertTimeout converts negative timeout to MaxInt, which indicates approximately infinity, waiting to stop containers
// ConvertTimeout converts negative timeout to MaxUint32, which indicates approximately infinity, waiting to stop containers
func ConvertTimeout(timeout int) uint {
if timeout < 0 {
return math.MaxInt
return math.MaxUint32
}
return uint(timeout)
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/util/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"fmt"
"math"
"testing"
"time"

Expand Down Expand Up @@ -573,3 +574,17 @@ func TestConvertMappings(t *testing.T) {
assert.Equal(t, start[i].Size, convertedBack[i].Size)
}
}

func TestConvertTimeout(t *testing.T) {
timeout := ConvertTimeout(0)
assert.Equal(t, uint(0), timeout)

timeout = ConvertTimeout(100)
assert.Equal(t, uint(100), timeout)

timeout = ConvertTimeout(-1)
assert.Equal(t, uint(math.MaxUint32), timeout)

timeout = ConvertTimeout(-100)
assert.Equal(t, uint(math.MaxUint32), timeout)
}
9 changes: 2 additions & 7 deletions test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1079,20 +1079,15 @@ $IMAGE--c_ok" \
run_podman stop -t 0 $cid

# Actual test for 15895: with --systemd, no ttyN devices are passed through
run_podman run -d --privileged --systemd=always $IMAGE top
run_podman run -d --privileged --stop-signal=TERM --systemd=always $IMAGE top
cid="$output"

run_podman exec $cid sh -c "find /dev -regex '/dev/tty[0-9].*' | wc -w"
assert "$output" = "0" \
"ls /dev/tty[0-9] with --systemd=always: should have no ttyN devices"

# Make sure run_podman stop supports -1 option
# FIXME: do we really really mean to say FFFFFFFFFFFFFFFF here???
run_podman 0+w stop -t -1 $cid
if ! is_remote; then
require_warning "StopSignal \(37\) failed to stop container .* in 18446744073709551615 seconds, resorting to SIGKILL" \
"stop -t -1 (negative 1) issues warning"
fi
run_podman stop -t -1 $cid
run_podman rm -t -1 -f $cid
}

Expand Down
Loading