mirror of
https://github.com/opencontainers/runc.git
synced 2025-04-18 19:44:09 +03:00
Use for range over integers
This appears in Go 1.22 (see https://tip.golang.org/ref/spec#For_range). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
f64edc4d6d
commit
17570625c0
@ -15,7 +15,7 @@ import (
|
||||
|
||||
func killContainer(container *libcontainer.Container) error {
|
||||
_ = container.Signal(unix.SIGKILL)
|
||||
for i := 0; i < 100; i++ {
|
||||
for range 100 {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
if err := container.Signal(unix.Signal(0)); err != nil {
|
||||
return container.Destroy()
|
||||
|
@ -832,7 +832,7 @@ func logCriuErrors(dir, file string) {
|
||||
logrus.Warn("...")
|
||||
}
|
||||
// Print the last lines.
|
||||
for add := 0; add < max; add++ {
|
||||
for add := range max {
|
||||
i := (idx + add) % max
|
||||
s := lines[i]
|
||||
actLineNo := lineNo + add - max + 1
|
||||
@ -961,7 +961,7 @@ func (c *Container) criuSwrk(process *Process, req *criurpc.CriuReq, opts *CriuO
|
||||
|
||||
val := reflect.ValueOf(req.GetOpts())
|
||||
v := reflect.Indirect(val)
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
for i := range v.NumField() {
|
||||
st := v.Type()
|
||||
name := st.Field(i).Name
|
||||
if 'A' <= name[0] && name[0] <= 'Z' {
|
||||
|
@ -191,7 +191,7 @@ func validateID(id string) error {
|
||||
}
|
||||
|
||||
// Allowed characters: 0-9 A-Z a-z _ + - .
|
||||
for i := 0; i < len(id); i++ {
|
||||
for i := range len(id) {
|
||||
c := id[i]
|
||||
switch {
|
||||
case c >= 'a' && c <= 'z':
|
||||
|
@ -60,7 +60,7 @@ func genBigEnv(count int) []string {
|
||||
}
|
||||
|
||||
envs := make([]string, count)
|
||||
for i := 0; i < count; i++ {
|
||||
for i := range count {
|
||||
key := strings.ToUpper(randStr(10))
|
||||
value := randStr(20)
|
||||
envs[i] = key + "=" + value
|
||||
|
@ -209,7 +209,7 @@ func TestExecInError(t *testing.T) {
|
||||
}()
|
||||
ok(t, err)
|
||||
|
||||
for i := 0; i < 42; i++ {
|
||||
for range 42 {
|
||||
unexistent := &libcontainer.Process{
|
||||
Cwd: "/",
|
||||
Args: []string{"unexistent"},
|
||||
@ -263,7 +263,7 @@ func TestExecInTTY(t *testing.T) {
|
||||
|
||||
// Repeat to increase chances to catch a race; see
|
||||
// https://github.com/opencontainers/runc/issues/2425.
|
||||
for i := 0; i < 300; i++ {
|
||||
for range 300 {
|
||||
var stdout bytes.Buffer
|
||||
|
||||
parent, child, err := utils.NewSockPair("console")
|
||||
|
@ -60,7 +60,7 @@ func testUpdateDevices(t *testing.T, systemd bool) {
|
||||
}
|
||||
defaultDevices := config.Cgroups.Resources.Devices
|
||||
|
||||
for i := 0; i < 300; i++ {
|
||||
for i := range 300 {
|
||||
// Check the access
|
||||
buf.Reset()
|
||||
err = container.Run(devCheck)
|
||||
|
@ -877,7 +877,7 @@ func getPipeFds(pid int) ([]string, error) {
|
||||
fds := make([]string, 3)
|
||||
|
||||
dirPath := filepath.Join("/proc", strconv.Itoa(pid), "/fd")
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
// XXX: This breaks if the path is not a valid symlink (which can
|
||||
// happen in certain particularly unlucky mount namespace setups).
|
||||
f := filepath.Join(dirPath, strconv.Itoa(i))
|
||||
|
@ -878,7 +878,7 @@ func reOpenDevNull() error {
|
||||
if err := unix.Fstat(int(file.Fd()), &devNullStat); err != nil {
|
||||
return &os.PathError{Op: "fstat", Path: file.Name(), Err: err}
|
||||
}
|
||||
for fd := 0; fd < 3; fd++ {
|
||||
for fd := range 3 {
|
||||
if err := unix.Fstat(fd, &stat); err != nil {
|
||||
return &os.PathError{Op: "fstat", Path: "fd " + strconv.Itoa(fd), Err: err}
|
||||
}
|
||||
@ -1211,7 +1211,7 @@ func remountReadonly(m *configs.Mount) error {
|
||||
dest = m.Destination
|
||||
flags = m.Flags
|
||||
)
|
||||
for i := 0; i < 5; i++ {
|
||||
for range 5 {
|
||||
// There is a special case in the kernel for
|
||||
// MS_REMOUNT | MS_BIND, which allows us to change only the
|
||||
// flags even as an unprivileged user (i.e. user namespace)
|
||||
|
@ -626,7 +626,7 @@ func checkPropertyName(s string) error {
|
||||
}
|
||||
// Check ASCII characters rather than Unicode runes,
|
||||
// so we have to use indexes rather than range.
|
||||
for i := 0; i < len(s); i++ {
|
||||
for i := range len(s) {
|
||||
ch := s[i]
|
||||
if (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') {
|
||||
continue
|
||||
|
Loading…
x
Reference in New Issue
Block a user