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