From 417d7e4743e2b1412466d1214d079e9c01a99272 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 3 Jun 2021 23:30:27 +0200 Subject: [PATCH] Fix some linter errors --- cmds/portmaster-start/lock.go | 3 +- cmds/portmaster-start/logs.go | 2 +- cmds/portmaster-start/recover_linux.go | 4 +- cmds/portmaster-start/run.go | 14 ++-- cmds/portmaster-start/shutdown.go | 2 +- cmds/portmaster-start/version.go | 106 +++++++++++++------------ 6 files changed, 66 insertions(+), 65 deletions(-) diff --git a/cmds/portmaster-start/lock.go b/cmds/portmaster-start/lock.go index 1178ac53..07fe0988 100644 --- a/cmds/portmaster-start/lock.go +++ b/cmds/portmaster-start/lock.go @@ -14,7 +14,6 @@ import ( ) func checkAndCreateInstanceLock(path, name string) (pid int32, err error) { - lockFilePath := filepath.Join(dataRoot.Path, path, fmt.Sprintf("%s-lock.pid", name)) // read current pid file @@ -86,7 +85,7 @@ func createInstanceLock(lockFilePath string) error { } // create lock file - err = ioutil.WriteFile(lockFilePath, []byte(fmt.Sprintf("%d", os.Getpid())), 0666) + err = ioutil.WriteFile(lockFilePath, []byte(fmt.Sprintf("%d", os.Getpid())), 0666) //nolint:gosec if err != nil { return err } diff --git a/cmds/portmaster-start/logs.go b/cmds/portmaster-start/logs.go index 2e73f4ca..c982febb 100644 --- a/cmds/portmaster-start/logs.go +++ b/cmds/portmaster-start/logs.go @@ -96,7 +96,7 @@ func getPmStartLogFile(ext string) *os.File { }, info.Version(), ext) } -//nolint:deadcode,unused // false positive on linux, currently used by windows only +//nolint:unused // false positive on linux, currently used by windows only func logControlError(cErr error) { // check if error present if cErr == nil { diff --git a/cmds/portmaster-start/recover_linux.go b/cmds/portmaster-start/recover_linux.go index ecb6735a..06529431 100644 --- a/cmds/portmaster-start/recover_linux.go +++ b/cmds/portmaster-start/recover_linux.go @@ -19,8 +19,8 @@ var recoverIPTablesCmd = &cobra.Command{ // we don't get the errno of the actual error and need to parse the // output instead. Make sure it's always english by setting LC_ALL=C currentLocale := os.Getenv("LC_ALL") - os.Setenv("LC_ALL", "C") // nolint:errcheck - we tried at least ... - defer os.Setenv("LC_ALL", currentLocale) // nolint:errcheck + os.Setenv("LC_ALL", "C") + defer os.Setenv("LC_ALL", currentLocale) err := interception.DeactivateNfqueueFirewall() if err == nil { diff --git a/cmds/portmaster-start/run.go b/cmds/portmaster-start/run.go index f36e5d80..9564f7fa 100644 --- a/cmds/portmaster-start/run.go +++ b/cmds/portmaster-start/run.go @@ -33,17 +33,17 @@ var ( childIsRunning = abool.NewBool(false) ) -// Options for starting component +// Options for starting component. type Options struct { Name string Identifier string // component identifier + ShortIdentifier string // populated automatically LockPathPrefix string PIDFile bool - ShortIdentifier string // populated automatically - SuppressArgs bool // do not use any args - AllowDownload bool // allow download of component if it is not yet available - AllowHidingWindow bool // allow hiding the window of the subprocess - NoOutput bool // do not use stdout/err if logging to file is available (did not fail to open log file) + SuppressArgs bool // do not use any args + AllowDownload bool // allow download of component if it is not yet available + AllowHidingWindow bool // allow hiding the window of the subprocess + NoOutput bool // do not use stdout/err if logging to file is available (did not fail to open log file) } func init() { @@ -313,7 +313,7 @@ func execute(opts *Options, args []string) (cont bool, err error) { log.Printf("starting %s %s\n", binPath, strings.Join(args, " ")) // create command - exc := exec.Command(binPath, args...) //nolint:gosec // everything is okay + exc := exec.Command(binPath, args...) if !runningInConsole && opts.AllowHidingWindow { // Windows only: diff --git a/cmds/portmaster-start/shutdown.go b/cmds/portmaster-start/shutdown.go index b42218a1..f136f344 100644 --- a/cmds/portmaster-start/shutdown.go +++ b/cmds/portmaster-start/shutdown.go @@ -7,7 +7,7 @@ import ( var ( startupComplete = make(chan struct{}) // signal that the start procedure completed (is never closed, just signaled once) shuttingDown = make(chan struct{}) // signal that we are shutting down (will be closed, may not be closed directly, use initiateShutdown) - //nolint:deadcode,unused // false positive on linux, currently used by windows only + //nolint:unused // false positive on linux, currently used by windows only shutdownError error // protected by shutdownLock shutdownLock sync.Mutex ) diff --git a/cmds/portmaster-start/version.go b/cmds/portmaster-start/version.go index 9f3dc662..88af21e6 100644 --- a/cmds/portmaster-start/version.go +++ b/cmds/portmaster-start/version.go @@ -12,62 +12,64 @@ import ( "github.com/spf13/cobra" ) -var showShortVersion bool -var showAllVersions bool -var versionCmd = &cobra.Command{ - Use: "version", - Short: "Display various portmaster versions", - Args: cobra.NoArgs, - PersistentPreRunE: func(*cobra.Command, []string) error { - if showAllVersions { - // If we are going to show all component versions, - // we need the registry to be configured. - if err := configureRegistry(false); err != nil { - return err - } - } - - return nil - }, - RunE: func(*cobra.Command, []string) error { - if !showAllVersions { - if showShortVersion { - fmt.Println(info.Version()) - return nil - } - - fmt.Println(info.FullVersion()) - return nil - } - - fmt.Printf("portmaster-start %s\n\n", info.Version()) - fmt.Printf("Assets:\n") - - all := registry.Export() - keys := make([]string, 0, len(all)) - for identifier := range all { - keys = append(keys, identifier) - } - sort.Strings(keys) - - tw := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) - for _, identifier := range keys { - res := all[identifier] - - if showShortVersion { - // in "short" mode, skip all resources that are irrelevant on that platform - if !strings.HasPrefix(identifier, "all") && !strings.HasPrefix(identifier, runtime.GOOS) { - continue +var ( + showShortVersion bool + showAllVersions bool + versionCmd = &cobra.Command{ + Use: "version", + Short: "Display various portmaster versions", + Args: cobra.NoArgs, + PersistentPreRunE: func(*cobra.Command, []string) error { + if showAllVersions { + // If we are going to show all component versions, + // we need the registry to be configured. + if err := configureRegistry(false); err != nil { + return err } } - fmt.Fprintf(tw, " %s\t%s\n", identifier, res.SelectedVersion.VersionNumber) - } - tw.Flush() + return nil + }, + RunE: func(*cobra.Command, []string) error { + if !showAllVersions { + if showShortVersion { + fmt.Println(info.Version()) + return nil + } - return nil - }, -} + fmt.Println(info.FullVersion()) + return nil + } + + fmt.Printf("portmaster-start %s\n\n", info.Version()) + fmt.Printf("Assets:\n") + + all := registry.Export() + keys := make([]string, 0, len(all)) + for identifier := range all { + keys = append(keys, identifier) + } + sort.Strings(keys) + + tw := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) + for _, identifier := range keys { + res := all[identifier] + + if showShortVersion { + // in "short" mode, skip all resources that are irrelevant on that platform + if !strings.HasPrefix(identifier, "all") && !strings.HasPrefix(identifier, runtime.GOOS) { + continue + } + } + + fmt.Fprintf(tw, " %s\t%s\n", identifier, res.SelectedVersion.VersionNumber) + } + tw.Flush() + + return nil + }, + } +) func init() { flags := versionCmd.Flags()