diff --git a/.golangci.yml b/.golangci.yml index c6959dd69..64c285cd0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,6 +8,7 @@ linters: enable: - gofumpt - errorlint + - nolintlint - unconvert - unparam diff --git a/libcontainer/factory_linux_test.go b/libcontainer/factory_linux_test.go index bbbbd3465..22dcd3412 100644 --- a/libcontainer/factory_linux_test.go +++ b/libcontainer/factory_linux_test.go @@ -86,7 +86,7 @@ func marshal(path string, v interface{}) error { if err != nil { return err } - defer f.Close() //nolint: errcheck + defer f.Close() return utils.WriteJSON(f, v) } diff --git a/libcontainer/integration/checkpoint_test.go b/libcontainer/integration/checkpoint_test.go index 8d4d6fe47..fa4a4975c 100644 --- a/libcontainer/integration/checkpoint_test.go +++ b/libcontainer/integration/checkpoint_test.go @@ -67,7 +67,7 @@ func testCheckpoint(t *testing.T, userns bool) { err = container.Run(&pconfig) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() ok(t, err) pid, err := pconfig.Pid() @@ -141,7 +141,7 @@ func testCheckpoint(t *testing.T, userns bool) { err = container.Restore(restoreProcessConfig, checkpointOpts) _ = restoreStdinR.Close() - defer restoreStdinW.Close() //nolint: errcheck + defer restoreStdinW.Close() if err != nil { t.Fatal(err) } diff --git a/libcontainer/integration/exec_test.go b/libcontainer/integration/exec_test.go index 5bfec5d73..17312563b 100644 --- a/libcontainer/integration/exec_test.go +++ b/libcontainer/integration/exec_test.go @@ -172,7 +172,7 @@ func TestEnter(t *testing.T) { } err = container.Run(&pconfig) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() ok(t, err) pid, err := pconfig.Pid() ok(t, err) @@ -190,7 +190,7 @@ func TestEnter(t *testing.T) { err = container.Run(&pconfig2) _ = stdinR2.Close() - defer stdinW2.Close() //nolint: errcheck + defer stdinW2.Close() ok(t, err) pid2, err := pconfig2.Pid() @@ -458,7 +458,7 @@ func testFreeze(t *testing.T, withSystemd bool, useSet bool) { } err = container.Run(pconfig) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() ok(t, err) if !useSet { @@ -738,7 +738,7 @@ func TestContainerState(t *testing.T) { err = container.Run(p) ok(t, err) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() st, err := container.State() ok(t, err) @@ -1164,7 +1164,7 @@ func TestRootfsPropagationSlaveMount(t *testing.T) { err = container.Run(pconfig) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() ok(t, err) // Create mnt2host under dir1host and bind mount itself on top of it. @@ -1194,7 +1194,7 @@ func TestRootfsPropagationSlaveMount(t *testing.T) { err = container.Run(pconfig2) _ = stdinR2.Close() - defer stdinW2.Close() //nolint: errcheck + defer stdinW2.Close() ok(t, err) _ = stdinW2.Close() @@ -1276,7 +1276,7 @@ func TestRootfsPropagationSharedMount(t *testing.T) { err = container.Run(pconfig) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() ok(t, err) // Create mnt2cont under dir1host. This will become visible inside container @@ -1311,7 +1311,7 @@ func TestRootfsPropagationSharedMount(t *testing.T) { err = container.Run(pconfig2) _ = stdinR2.Close() - defer stdinW2.Close() //nolint: errcheck + defer stdinW2.Close() ok(t, err) // Wait for process @@ -1430,7 +1430,7 @@ func TestInitJoinPID(t *testing.T) { } err = container1.Run(init1) _ = stdinR1.Close() - defer stdinW1.Close() //nolint: errcheck + defer stdinW1.Close() ok(t, err) // get the state of the first container @@ -1457,7 +1457,7 @@ func TestInitJoinPID(t *testing.T) { } err = container2.Run(init2) _ = stdinR2.Close() - defer stdinW2.Close() //nolint: errcheck + defer stdinW2.Close() ok(t, err) // get the state of the second container state2, err := container2.State() @@ -1529,7 +1529,7 @@ func TestInitJoinNetworkAndUser(t *testing.T) { } err = container1.Run(init1) _ = stdinR1.Close() - defer stdinW1.Close() //nolint: errcheck + defer stdinW1.Close() ok(t, err) // get the state of the first container @@ -1563,7 +1563,7 @@ func TestInitJoinNetworkAndUser(t *testing.T) { } err = container2.Run(init2) _ = stdinR2.Close() - defer stdinW2.Close() //nolint: errcheck + defer stdinW2.Close() ok(t, err) // get the state of the second container diff --git a/libcontainer/integration/execin_test.go b/libcontainer/integration/execin_test.go index e6be1f544..831a43744 100644 --- a/libcontainer/integration/execin_test.go +++ b/libcontainer/integration/execin_test.go @@ -40,7 +40,7 @@ func TestExecIn(t *testing.T) { } err = container.Run(process) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() ok(t, err) buffers := newStdBuffers() @@ -98,7 +98,7 @@ func testExecInRlimit(t *testing.T, userns bool) { } err = container.Run(process) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() ok(t, err) buffers := newStdBuffers() @@ -149,7 +149,7 @@ func TestExecInAdditionalGroups(t *testing.T) { } err = container.Run(process) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() ok(t, err) var stdout bytes.Buffer @@ -338,7 +338,7 @@ func TestExecInEnvironment(t *testing.T) { } err = container.Run(process) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() ok(t, err) execEnv := []string{ @@ -408,7 +408,7 @@ func TestExecinPassExtraFiles(t *testing.T) { } err = container.Run(process) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() ok(t, err) var stdout bytes.Buffer @@ -473,7 +473,7 @@ func TestExecInOomScoreAdj(t *testing.T) { } err = container.Run(process) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() ok(t, err) buffers := newStdBuffers() @@ -521,7 +521,7 @@ func TestExecInUserns(t *testing.T) { } err = container.Run(process) _ = stdinR.Close() - defer stdinW.Close() //nolint: errcheck + defer stdinW.Close() ok(t, err) initPID, err := process.Pid() diff --git a/libcontainer/rootfs_linux.go b/libcontainer/rootfs_linux.go index e46109a2f..3df948eeb 100644 --- a/libcontainer/rootfs_linux.go +++ b/libcontainer/rootfs_linux.go @@ -873,7 +873,7 @@ func reOpenDevNull() error { if err != nil { return err } - defer file.Close() //nolint: errcheck + defer file.Close() if err := unix.Fstat(int(file.Fd()), &devNullStat); err != nil { return &os.PathError{Op: "fstat", Path: file.Name(), Err: err} } @@ -999,7 +999,7 @@ func rootfsParentMountPrivate(path string) error { if err == nil { return nil } - if err != unix.EINVAL || path == "/" { //nolint:errorlint // unix errors are bare + if err != unix.EINVAL || path == "/" { break } path = filepath.Dir(path) @@ -1067,13 +1067,13 @@ func pivotRoot(rootfs string) error { if err != nil { return &os.PathError{Op: "open", Path: "/", Err: err} } - defer unix.Close(oldroot) //nolint: errcheck + defer unix.Close(oldroot) newroot, err := unix.Open(rootfs, unix.O_DIRECTORY|unix.O_RDONLY, 0) if err != nil { return &os.PathError{Op: "open", Path: rootfs, Err: err} } - defer unix.Close(newroot) //nolint: errcheck + defer unix.Close(newroot) // Change to the new root so that the pivot_root actually acts on it. if err := unix.Fchdir(newroot); err != nil { diff --git a/libcontainer/utils/cmsg.go b/libcontainer/utils/cmsg.go index 3aca5bdac..8b63a1295 100644 --- a/libcontainer/utils/cmsg.go +++ b/libcontainer/utils/cmsg.go @@ -49,7 +49,7 @@ func RecvFile(socket *os.File) (_ *os.File, Err error) { for { n, oobn, _, _, err = unix.Recvmsg(int(sockfd), name, oob, unix.MSG_CMSG_CLOEXEC) - if err != unix.EINTR { //nolint:errorlint // unix errors are bare + if err != unix.EINTR { break } } @@ -128,7 +128,7 @@ func SendRawFd(socket *os.File, msg string, fd uintptr) error { oob := unix.UnixRights(int(fd)) for { err := unix.Sendmsg(int(socket.Fd()), []byte(msg), oob, nil, 0) - if err != unix.EINTR { //nolint:errorlint // unix errors are bare + if err != unix.EINTR { return os.NewSyscallError("sendmsg", err) } }