Skip to content

Commit

Permalink
chore(pkg/driver): add nolint comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Nov 6, 2023
1 parent 9116f52 commit e554f30
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/driver/distro/centos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/distro/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var debianKernelReleaseRegex = regexp.MustCompile("-?(rt-|cloud-|)(amd64|arm64)"
var debianKernelVersionRegex = regexp.MustCompile("\\d+\\.\\d+\\.\\d+\\-\\d+")

Check failure on line 35 in pkg/driver/distro/debian.go

View workflow job for this annotation

GitHub Actions / Lint golang files

S1007: should use raw string (`...`) with regexp.MustCompile to avoid having to escape twice (gosimple)

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
Expand Down
4 changes: 2 additions & 2 deletions pkg/driver/distro/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/driver/type/kmod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit e554f30

Please sign in to comment.