mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03: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:
|
enable:
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- errorlint
|
- errorlint
|
||||||
|
- nolintlint
|
||||||
- unconvert
|
- unconvert
|
||||||
- unparam
|
- unparam
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ func marshal(path string, v interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close() //nolint: errcheck
|
defer f.Close()
|
||||||
return utils.WriteJSON(f, v)
|
return utils.WriteJSON(f, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func testCheckpoint(t *testing.T, userns bool) {
|
|||||||
|
|
||||||
err = container.Run(&pconfig)
|
err = container.Run(&pconfig)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
pid, err := pconfig.Pid()
|
pid, err := pconfig.Pid()
|
||||||
@@ -141,7 +141,7 @@ func testCheckpoint(t *testing.T, userns bool) {
|
|||||||
|
|
||||||
err = container.Restore(restoreProcessConfig, checkpointOpts)
|
err = container.Restore(restoreProcessConfig, checkpointOpts)
|
||||||
_ = restoreStdinR.Close()
|
_ = restoreStdinR.Close()
|
||||||
defer restoreStdinW.Close() //nolint: errcheck
|
defer restoreStdinW.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ func TestEnter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = container.Run(&pconfig)
|
err = container.Run(&pconfig)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
pid, err := pconfig.Pid()
|
pid, err := pconfig.Pid()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
@@ -190,7 +190,7 @@ func TestEnter(t *testing.T) {
|
|||||||
|
|
||||||
err = container.Run(&pconfig2)
|
err = container.Run(&pconfig2)
|
||||||
_ = stdinR2.Close()
|
_ = stdinR2.Close()
|
||||||
defer stdinW2.Close() //nolint: errcheck
|
defer stdinW2.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
pid2, err := pconfig2.Pid()
|
pid2, err := pconfig2.Pid()
|
||||||
@@ -458,7 +458,7 @@ func testFreeze(t *testing.T, withSystemd bool, useSet bool) {
|
|||||||
}
|
}
|
||||||
err = container.Run(pconfig)
|
err = container.Run(pconfig)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
if !useSet {
|
if !useSet {
|
||||||
@@ -738,7 +738,7 @@ func TestContainerState(t *testing.T) {
|
|||||||
err = container.Run(p)
|
err = container.Run(p)
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
|
|
||||||
st, err := container.State()
|
st, err := container.State()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
@@ -1164,7 +1164,7 @@ func TestRootfsPropagationSlaveMount(t *testing.T) {
|
|||||||
|
|
||||||
err = container.Run(pconfig)
|
err = container.Run(pconfig)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
// Create mnt2host under dir1host and bind mount itself on top of it.
|
// 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)
|
err = container.Run(pconfig2)
|
||||||
_ = stdinR2.Close()
|
_ = stdinR2.Close()
|
||||||
defer stdinW2.Close() //nolint: errcheck
|
defer stdinW2.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
_ = stdinW2.Close()
|
_ = stdinW2.Close()
|
||||||
@@ -1276,7 +1276,7 @@ func TestRootfsPropagationSharedMount(t *testing.T) {
|
|||||||
|
|
||||||
err = container.Run(pconfig)
|
err = container.Run(pconfig)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
// Create mnt2cont under dir1host. This will become visible inside container
|
// Create mnt2cont under dir1host. This will become visible inside container
|
||||||
@@ -1311,7 +1311,7 @@ func TestRootfsPropagationSharedMount(t *testing.T) {
|
|||||||
|
|
||||||
err = container.Run(pconfig2)
|
err = container.Run(pconfig2)
|
||||||
_ = stdinR2.Close()
|
_ = stdinR2.Close()
|
||||||
defer stdinW2.Close() //nolint: errcheck
|
defer stdinW2.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
// Wait for process
|
// Wait for process
|
||||||
@@ -1430,7 +1430,7 @@ func TestInitJoinPID(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = container1.Run(init1)
|
err = container1.Run(init1)
|
||||||
_ = stdinR1.Close()
|
_ = stdinR1.Close()
|
||||||
defer stdinW1.Close() //nolint: errcheck
|
defer stdinW1.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
// get the state of the first container
|
// get the state of the first container
|
||||||
@@ -1457,7 +1457,7 @@ func TestInitJoinPID(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = container2.Run(init2)
|
err = container2.Run(init2)
|
||||||
_ = stdinR2.Close()
|
_ = stdinR2.Close()
|
||||||
defer stdinW2.Close() //nolint: errcheck
|
defer stdinW2.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
// get the state of the second container
|
// get the state of the second container
|
||||||
state2, err := container2.State()
|
state2, err := container2.State()
|
||||||
@@ -1529,7 +1529,7 @@ func TestInitJoinNetworkAndUser(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = container1.Run(init1)
|
err = container1.Run(init1)
|
||||||
_ = stdinR1.Close()
|
_ = stdinR1.Close()
|
||||||
defer stdinW1.Close() //nolint: errcheck
|
defer stdinW1.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
// get the state of the first container
|
// get the state of the first container
|
||||||
@@ -1563,7 +1563,7 @@ func TestInitJoinNetworkAndUser(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = container2.Run(init2)
|
err = container2.Run(init2)
|
||||||
_ = stdinR2.Close()
|
_ = stdinR2.Close()
|
||||||
defer stdinW2.Close() //nolint: errcheck
|
defer stdinW2.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
// get the state of the second container
|
// get the state of the second container
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func TestExecIn(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = container.Run(process)
|
err = container.Run(process)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
buffers := newStdBuffers()
|
buffers := newStdBuffers()
|
||||||
@@ -98,7 +98,7 @@ func testExecInRlimit(t *testing.T, userns bool) {
|
|||||||
}
|
}
|
||||||
err = container.Run(process)
|
err = container.Run(process)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
buffers := newStdBuffers()
|
buffers := newStdBuffers()
|
||||||
@@ -149,7 +149,7 @@ func TestExecInAdditionalGroups(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = container.Run(process)
|
err = container.Run(process)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
@@ -338,7 +338,7 @@ func TestExecInEnvironment(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = container.Run(process)
|
err = container.Run(process)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
execEnv := []string{
|
execEnv := []string{
|
||||||
@@ -408,7 +408,7 @@ func TestExecinPassExtraFiles(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = container.Run(process)
|
err = container.Run(process)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
@@ -473,7 +473,7 @@ func TestExecInOomScoreAdj(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = container.Run(process)
|
err = container.Run(process)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
buffers := newStdBuffers()
|
buffers := newStdBuffers()
|
||||||
@@ -521,7 +521,7 @@ func TestExecInUserns(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = container.Run(process)
|
err = container.Run(process)
|
||||||
_ = stdinR.Close()
|
_ = stdinR.Close()
|
||||||
defer stdinW.Close() //nolint: errcheck
|
defer stdinW.Close()
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
|
||||||
initPID, err := process.Pid()
|
initPID, err := process.Pid()
|
||||||
|
|||||||
@@ -873,7 +873,7 @@ func reOpenDevNull() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close() //nolint: errcheck
|
defer file.Close()
|
||||||
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}
|
||||||
}
|
}
|
||||||
@@ -999,7 +999,7 @@ func rootfsParentMountPrivate(path string) error {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err != unix.EINVAL || path == "/" { //nolint:errorlint // unix errors are bare
|
if err != unix.EINVAL || path == "/" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
path = filepath.Dir(path)
|
path = filepath.Dir(path)
|
||||||
@@ -1067,13 +1067,13 @@ func pivotRoot(rootfs string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return &os.PathError{Op: "open", Path: "/", Err: err}
|
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)
|
newroot, err := unix.Open(rootfs, unix.O_DIRECTORY|unix.O_RDONLY, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &os.PathError{Op: "open", Path: rootfs, Err: err}
|
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.
|
// Change to the new root so that the pivot_root actually acts on it.
|
||||||
if err := unix.Fchdir(newroot); err != nil {
|
if err := unix.Fchdir(newroot); err != nil {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func RecvFile(socket *os.File) (_ *os.File, Err error) {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
n, oobn, _, _, err = unix.Recvmsg(int(sockfd), name, oob, unix.MSG_CMSG_CLOEXEC)
|
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
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ func SendRawFd(socket *os.File, msg string, fd uintptr) error {
|
|||||||
oob := unix.UnixRights(int(fd))
|
oob := unix.UnixRights(int(fd))
|
||||||
for {
|
for {
|
||||||
err := unix.Sendmsg(int(socket.Fd()), []byte(msg), oob, nil, 0)
|
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)
|
return os.NewSyscallError("sendmsg", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user