From 56e478046af2f61e69a970148823b283ef88a768 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 9 Jun 2021 12:30:17 -0700 Subject: [PATCH] *: ignore errorlint warnings about unix.* errors Errors from unix.* are always bare and thus can be used directly. Add //nolint:errorlint annotation to ignore errors such as these: libcontainer/system/xattrs_linux.go:18:7: comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint) case errno == unix.ERANGE: ^ libcontainer/container_linux.go:1259:9: comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint) if e != unix.EINVAL { ^ libcontainer/rootfs_linux.go:919:7: comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint) if err != unix.EINVAL && err != unix.EPERM { ^ libcontainer/rootfs_linux.go:1002:4: switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors (errorlint) switch err { ^ Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/file.go | 2 +- libcontainer/cgroups/fs/cpuset.go | 2 +- libcontainer/cgroups/utils.go | 2 +- libcontainer/container_linux.go | 2 +- libcontainer/init_linux.go | 2 ++ libcontainer/system/xattrs_linux.go | 1 + signals.go | 2 +- 7 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libcontainer/cgroups/file.go b/libcontainer/cgroups/file.go index 5f6ab9fd6..09fef941b 100644 --- a/libcontainer/cgroups/file.go +++ b/libcontainer/cgroups/file.go @@ -81,7 +81,7 @@ func prepareOpenat2() error { }) if err != nil { prepErr = &os.PathError{Op: "openat2", Path: cgroupfsDir, Err: err} - if err != unix.ENOSYS { + if err != unix.ENOSYS { //nolint:errorlint // unix errors are bare logrus.Warnf("falling back to securejoin: %s", prepErr) } else { logrus.Debug("openat2 not available, falling back to securejoin") diff --git a/libcontainer/cgroups/fs/cpuset.go b/libcontainer/cgroups/fs/cpuset.go index 1bdb1931f..2b3f18e15 100644 --- a/libcontainer/cgroups/fs/cpuset.go +++ b/libcontainer/cgroups/fs/cpuset.go @@ -197,7 +197,7 @@ func cpusetEnsureParent(current string) error { } // Treat non-existing directory as cgroupfs as it will be created, // and the root cpuset directory obviously exists. - if err != nil && err != unix.ENOENT { + if err != nil && err != unix.ENOENT { //nolint:errorlint // unix errors are bare return &os.PathError{Op: "statfs", Path: parent, Err: err} } diff --git a/libcontainer/cgroups/utils.go b/libcontainer/cgroups/utils.go index 735721bd1..77629bdac 100644 --- a/libcontainer/cgroups/utils.go +++ b/libcontainer/cgroups/utils.go @@ -210,7 +210,7 @@ func EnterPid(cgroupPaths map[string]string, pid int) error { func rmdir(path string) error { err := unix.Rmdir(path) - if err == nil || err == unix.ENOENT { + if err == nil || err == unix.ENOENT { //nolint:errorlint // unix errors are bare return nil } return &os.PathError{Op: "rmdir", Path: path, Err: err} diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 594943404..4b5f42983 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -1256,7 +1256,7 @@ func (c *linuxContainer) prepareCriuRestoreMounts(mounts []*configs.Mount) error for _, u := range umounts { _ = utils.WithProcfd(c.config.Rootfs, u, func(procfd string) error { if e := unix.Unmount(procfd, unix.MNT_DETACH); e != nil { - if e != unix.EINVAL { + if e != unix.EINVAL { //nolint:errorlint // unix errors are bare // Ignore EINVAL as it means 'target is not a mount point.' // It probably has already been unmounted. logrus.Warnf("Error during cleanup unmounting of %s (%s): %v", procfd, u, e) diff --git a/libcontainer/init_linux.go b/libcontainer/init_linux.go index 687d14f75..54c35207a 100644 --- a/libcontainer/init_linux.go +++ b/libcontainer/init_linux.go @@ -399,6 +399,8 @@ func fixStdioPermissions(config *initConfig, u *user.ExecUser) error { // privileged_wrt_inode_uidgid() has failed). In either case, we // are in a configuration where it's better for us to just not // touch the stdio rather than bail at this point. + + // nolint:errorlint // unix errors are bare if err == unix.EINVAL || err == unix.EPERM { continue } diff --git a/libcontainer/system/xattrs_linux.go b/libcontainer/system/xattrs_linux.go index a6823fc99..01a54fcf5 100644 --- a/libcontainer/system/xattrs_linux.go +++ b/libcontainer/system/xattrs_linux.go @@ -10,6 +10,7 @@ func Lgetxattr(path string, attr string) ([]byte, error) { dest := make([]byte, 128) sz, errno := unix.Lgetxattr(path, attr, dest) + //nolint:errorlint // unix errors are bare switch { case errno == unix.ENODATA: return nil, errno diff --git a/signals.go b/signals.go index 73d8de0fa..250764c76 100644 --- a/signals.go +++ b/signals.go @@ -120,7 +120,7 @@ func (h *signalHandler) reap() (exits []exit, err error) { for { pid, err := unix.Wait4(-1, &ws, unix.WNOHANG, &rus) if err != nil { - if err == unix.ECHILD { + if err == unix.ECHILD { //nolint:errorlint // unix errors are bare return exits, nil } return nil, err