Skip to content

Commit

Permalink
Fix podman stop -t -1 CID
Browse files Browse the repository at this point in the history
Currently if a user specifies a negative time to stop a container the
code ends up specifying the negative time to time.Duration which treats
it as 0. By settine the default to max.Unint32 we end up with a positive
number which indicates > 68 years which is probably close enough to
infinity for our use case.

Fixes: containers#21811

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Feb 26, 2024
1 parent e99ecec commit 13aae2d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
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)
}
7 changes: 1 addition & 6 deletions test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1087,12 +1087,7 @@ $IMAGE--c_ok" \
"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

0 comments on commit 13aae2d

Please sign in to comment.