From e554f301a55ef6ad86995f6b571f923ee16c2d37 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Mon, 6 Nov 2023 14:34:58 +0100 Subject: [PATCH] chore(pkg/driver): add nolint comments. Signed-off-by: Federico Di Pierro --- pkg/driver/distro/centos.go | 2 +- pkg/driver/distro/debian.go | 2 +- pkg/driver/distro/generic.go | 4 ++-- pkg/driver/type/kmod.go | 14 +++++++------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/driver/distro/centos.go b/pkg/driver/distro/centos.go index 1edaa8ee..047ea267 100644 --- a/pkg/driver/distro/centos.go +++ b/pkg/driver/distro/centos.go @@ -26,7 +26,7 @@ type centos struct { } func (c *centos) check(hostRoot string) bool { - file, err := os.Open(hostRoot + "/etc/centos-release") //nolint:gosec + file, err := os.Open(hostRoot + "/etc/centos-release") //nolint:gosec // false positive if err == nil { _ = file.Close() return true diff --git a/pkg/driver/distro/debian.go b/pkg/driver/distro/debian.go index e28f4208..be869f9e 100644 --- a/pkg/driver/distro/debian.go +++ b/pkg/driver/distro/debian.go @@ -35,7 +35,7 @@ var debianKernelReleaseRegex = regexp.MustCompile("-?(rt-|cloud-|)(amd64|arm64)" var debianKernelVersionRegex = regexp.MustCompile("\\d+\\.\\d+\\.\\d+\\-\\d+") func (d *debian) check(hostRoot string) bool { - file, err := os.Open(hostRoot + "/etc/debian_version") //nolint:gosec + file, err := os.Open(hostRoot + "/etc/debian_version") //nolint:gosec // false positive if err == nil { _ = file.Close() return true diff --git a/pkg/driver/distro/generic.go b/pkg/driver/distro/generic.go index 7ee1e754..b29560d9 100644 --- a/pkg/driver/distro/generic.go +++ b/pkg/driver/distro/generic.go @@ -61,7 +61,7 @@ func (g *generic) Download(i driverkernel.Info, opts *options.Driver, driverType // Skip if existent driverFileName := g.toFilename(i, opts, driverType) destination := fmt.Sprintf("%s/.falco/%s/%s/%s", homedir.Get(), driverVer, i.Architecture, driverFileName) - f, err := os.Open(destination) //nolint:gosec + f, err := os.Open(destination) //nolint:gosec // false positive if err == nil { _ = f.Close() g.printer.Logger.Info("Skipping download, driver already present.", g.printer.Logger.Args("path", destination)) @@ -79,7 +79,7 @@ func (g *generic) Download(i driverkernel.Info, opts *options.Driver, driverType continue } - out, err := os.Create(destination) //nolint:gosec + out, err := os.Create(destination) //nolint:gosec // false positive if err != nil { return destination, err } diff --git a/pkg/driver/type/kmod.go b/pkg/driver/type/kmod.go index fded6cdc..d2a2d5e2 100644 --- a/pkg/driver/type/kmod.go +++ b/pkg/driver/type/kmod.go @@ -64,14 +64,14 @@ func (k *kmod) Prepare(printer *output.Printer, driverName string) error { kmodName := strings.ReplaceAll(driverName, "-", "_") printer.Logger.Info("Check if kernel module is still loaded.") lsmodCmdArgs := fmt.Sprintf(`lsmod | cut -d' ' -f1 | grep -qx %q`, kmodName) - _, err = exec.Command("bash", "-c", lsmodCmdArgs).Output() //nolint:gosec + _, err = exec.Command("bash", "-c", lsmodCmdArgs).Output() //nolint:gosec // false positive if err == nil { unloaded := false // Module is still loaded, try to remove it for i := 0; i < maxRmmodWait; i++ { printer.Logger.Info("Kernel module is still loaded.") printer.Logger.Info("Trying to unload it with 'rmmod'.") - if _, err = exec.Command("rmmod", kmodName).Output(); err == nil { //nolint:gosec + if _, err = exec.Command("rmmod", kmodName).Output(); err == nil { //nolint:gosec // false positive printer.Logger.Info("OK! Unloading module succeeded.") unloaded = true break @@ -96,7 +96,7 @@ func (k *kmod) Prepare(printer *output.Printer, driverName string) error { printer.Logger.Info("Check all versions of kernel module in dkms.") dkmsLsCmdArgs := fmt.Sprintf(`dkms status -m %q | tr -d "," | tr -d ":" | tr "/" " " | cut -d' ' -f2`, kmodName) - out, err := exec.Command("bash", "-c", dkmsLsCmdArgs).Output() //nolint:gosec + out, err := exec.Command("bash", "-c", dkmsLsCmdArgs).Output() //nolint:gosec // false positive if err != nil { printer.Logger.Warn("Listing kernel module versions failed.", printer.Logger.Args("reason", err)) return nil @@ -109,7 +109,7 @@ func (k *kmod) Prepare(printer *output.Printer, driverName string) error { printer.Logger.Info("Removing all the following versions from dkms.", printer.Logger.Args("versions", driverVersions)) for _, dVer := range driverVersions { dkmsRmCmdArgs := fmt.Sprintf(`dkms remove -m %s -v %q --all`, kmodName, dVer) - _, err = exec.Command("bash", "-c", dkmsRmCmdArgs).Output() //nolint:gosec + _, err = exec.Command("bash", "-c", dkmsRmCmdArgs).Output() //nolint:gosec // false positive if err == nil { printer.Logger.Info("OK! Removing succeeded.", printer.Logger.Args("version", dVer)) } else { @@ -125,7 +125,7 @@ func (k *kmod) Load(printer *output.Printer, driverName string, fallback bool) e // Try to modprobe any existent version of the kmod; this is a fallback // when both download and build of kmod fail. printer.Logger.Info("Trying to load a pre existent system module, if present.") - _, err := exec.Command("modprobe", driverName).Output() //nolint:gosec + _, err := exec.Command("modprobe", driverName).Output() //nolint:gosec // false positive if err == nil { printer.Logger.Info("Success: module found and loaded with modprobe.") } else { @@ -137,8 +137,8 @@ func (k *kmod) Load(printer *output.Printer, driverName string, fallback bool) e chconCmdArgs := fmt.Sprintf(`chcon -t modules_object_t %q`, driverName) // We don't want to catch any error from this call // chcon(1): change file SELinux security context - _, _ = exec.Command("bash", "-c", chconCmdArgs).Output() //nolint:gosec - _, err := exec.Command("insmod", driverName).Output() //nolint:gosec + _, _ = exec.Command("bash", "-c", chconCmdArgs).Output() //nolint:gosec // false positive + _, err := exec.Command("insmod", driverName).Output() //nolint:gosec // false positive if err == nil { printer.Logger.Info("Success: module found and loaded in dkms.") } else {