diff --git a/pmctl/console_windows.go b/pmctl/console_windows.go index 5a1c09b3..1148d90e 100644 --- a/pmctl/console_windows.go +++ b/pmctl/console_windows.go @@ -83,7 +83,7 @@ func attachToParentConsole() (attached bool, err error) { if err != nil { return false, err } - r1, _, err := procAttachConsole.Call(windowsAttachParentProcess) + r1, _, _ := procAttachConsole.Call(windowsAttachParentProcess) if r1 == 0 { // possible errors: // ERROR_ACCESS_DENIED: already attached to console diff --git a/pmctl/install_windows.go b/pmctl/install_windows.go index b06db6f4..3446c493 100644 --- a/pmctl/install_windows.go +++ b/pmctl/install_windows.go @@ -1,6 +1,6 @@ package main -// Based on the offical Go examples from +// Based on the official Go examples from // https://github.com/golang/sys/blob/master/windows/svc/example // by The Go Authors. // Original LICENSE (sha256sum: 2d36597f7117c38b006835ae7f537487207d8ec407aa9d9980794b2030cbc067) can be found in vendor/pkg cache directory. @@ -19,6 +19,10 @@ import ( "golang.org/x/sys/windows/svc/mgr" ) +const ( + exeSuffix = ".exe" +) + func init() { rootCmd.AddCommand(installCmd) installCmd.AddCommand(installService) @@ -70,8 +74,8 @@ func getExePath() (string, error) { } // check if we have a .exe extension, add and check if not if filepath.Ext(p) == "" { - p += ".exe" - fi, err := os.Stat(p) + p += exeSuffix + fi, err = os.Stat(p) if err == nil { if !fi.Mode().IsDir() { return p, nil @@ -113,15 +117,7 @@ func getServiceConfig(exePath string) mgr.Config { func getRecoveryActions() (recoveryActions []mgr.RecoveryAction, resetPeriod uint32) { return []mgr.RecoveryAction{ - //mgr.RecoveryAction{ - // Type: mgr.ServiceRestart, // one of NoAction, ComputerReboot, ServiceRestart or RunCommand - // Delay: 1 * time.Minute, // the time to wait before performing the specified action - //}, - // mgr.RecoveryAction{ - // Type: mgr.ServiceRestart, // one of NoAction, ComputerReboot, ServiceRestart or RunCommand - // Delay: 1 * time.Minute, // the time to wait before performing the specified action - // }, - mgr.RecoveryAction{ + { Type: mgr.ServiceRestart, // one of NoAction, ComputerReboot, ServiceRestart or RunCommand Delay: 1 * time.Minute, // the time to wait before performing the specified action }, @@ -140,7 +136,7 @@ func installWindowsService(cmd *cobra.Command, args []string) error { if err != nil { return fmt.Errorf("failed to connect to service manager: %s", err) } - defer m.Disconnect() + defer m.Disconnect() //nolint:errcheck // TODO // open service created := false @@ -156,7 +152,7 @@ func installWindowsService(cmd *cobra.Command, args []string) error { created = true } else { // update service - s.UpdateConfig(getServiceConfig(exePath)) + err = s.UpdateConfig(getServiceConfig(exePath)) if err != nil { return fmt.Errorf("failed to update service: %s", err) } @@ -184,7 +180,7 @@ func uninstallWindowsService(cmd *cobra.Command, args []string) error { if err != nil { return err } - defer m.Disconnect() + defer m.Disconnect() //nolint:errcheck // TODO // open service s, err := m.OpenService(serviceName) diff --git a/pmctl/service_windows.go b/pmctl/service_windows.go index 4fb68bc6..8b02815d 100644 --- a/pmctl/service_windows.go +++ b/pmctl/service_windows.go @@ -1,6 +1,6 @@ package main -// Based on the offical Go examples from +// Based on the official Go examples from // https://github.com/golang/sys/blob/master/windows/svc/example // by The Go Authors. // Original LICENSE (sha256sum: 2d36597f7117c38b006835ae7f537487207d8ec407aa9d9980794b2030cbc067) can be found in vendor/pkg cache directory. @@ -84,7 +84,8 @@ service: changes <- svc.Status{State: svc.Stopped} // wait a little for the status to reach Windows time.Sleep(100 * time.Millisecond) - return + + return ssec, errno } func runService(cmd *cobra.Command, opts *Options) error { @@ -121,7 +122,7 @@ func runService(cmd *cobra.Command, opts *Options) error { go func() { // run slightly delayed time.Sleep(250 * time.Millisecond) - handleRun(cmd, opts) + _ = handleRun(cmd, opts) // error handled by shutdown routine finishWg.Done() runWg.Done() }() @@ -131,7 +132,7 @@ func runService(cmd *cobra.Command, opts *Options) error { err = getShutdownError() if err != nil { log.Printf("%s service experienced an error: %s\n", serviceName, err) - elog.Error(1, fmt.Sprintf("%s experienced an error: %s", serviceName, err)) + _ = elog.Error(1, fmt.Sprintf("%s experienced an error: %s", serviceName, err)) } return err