mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
.golangci.yml: add nolintlint, fix found issues
The errrolint linter can finally ignore errors from Close, and it also ignores direct comparisons of errors from x/sys/unix. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@ linters:
|
||||
enable:
|
||||
- gofumpt
|
||||
- errorlint
|
||||
- nolintlint
|
||||
- unconvert
|
||||
- unparam
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user