Fix pmctl linter errors

This commit is contained in:
Daniel 2020-04-10 13:19:07 +02:00
parent 881c269c1b
commit c20c73a2d8
3 changed files with 17 additions and 20 deletions

View file

@ -83,7 +83,7 @@ func attachToParentConsole() (attached bool, err error) {
if err != nil { if err != nil {
return false, err return false, err
} }
r1, _, err := procAttachConsole.Call(windowsAttachParentProcess) r1, _, _ := procAttachConsole.Call(windowsAttachParentProcess)
if r1 == 0 { if r1 == 0 {
// possible errors: // possible errors:
// ERROR_ACCESS_DENIED: already attached to console // ERROR_ACCESS_DENIED: already attached to console

View file

@ -1,6 +1,6 @@
package main 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 // https://github.com/golang/sys/blob/master/windows/svc/example
// by The Go Authors. // by The Go Authors.
// Original LICENSE (sha256sum: 2d36597f7117c38b006835ae7f537487207d8ec407aa9d9980794b2030cbc067) can be found in vendor/pkg cache directory. // Original LICENSE (sha256sum: 2d36597f7117c38b006835ae7f537487207d8ec407aa9d9980794b2030cbc067) can be found in vendor/pkg cache directory.
@ -19,6 +19,10 @@ import (
"golang.org/x/sys/windows/svc/mgr" "golang.org/x/sys/windows/svc/mgr"
) )
const (
exeSuffix = ".exe"
)
func init() { func init() {
rootCmd.AddCommand(installCmd) rootCmd.AddCommand(installCmd)
installCmd.AddCommand(installService) installCmd.AddCommand(installService)
@ -70,8 +74,8 @@ func getExePath() (string, error) {
} }
// check if we have a .exe extension, add and check if not // check if we have a .exe extension, add and check if not
if filepath.Ext(p) == "" { if filepath.Ext(p) == "" {
p += ".exe" p += exeSuffix
fi, err := os.Stat(p) fi, err = os.Stat(p)
if err == nil { if err == nil {
if !fi.Mode().IsDir() { if !fi.Mode().IsDir() {
return p, nil return p, nil
@ -113,15 +117,7 @@ func getServiceConfig(exePath string) mgr.Config {
func getRecoveryActions() (recoveryActions []mgr.RecoveryAction, resetPeriod uint32) { func getRecoveryActions() (recoveryActions []mgr.RecoveryAction, resetPeriod uint32) {
return []mgr.RecoveryAction{ 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 Type: mgr.ServiceRestart, // one of NoAction, ComputerReboot, ServiceRestart or RunCommand
Delay: 1 * time.Minute, // the time to wait before performing the specified action 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 { if err != nil {
return fmt.Errorf("failed to connect to service manager: %s", err) return fmt.Errorf("failed to connect to service manager: %s", err)
} }
defer m.Disconnect() defer m.Disconnect() //nolint:errcheck // TODO
// open service // open service
created := false created := false
@ -156,7 +152,7 @@ func installWindowsService(cmd *cobra.Command, args []string) error {
created = true created = true
} else { } else {
// update service // update service
s.UpdateConfig(getServiceConfig(exePath)) err = s.UpdateConfig(getServiceConfig(exePath))
if err != nil { if err != nil {
return fmt.Errorf("failed to update service: %s", err) return fmt.Errorf("failed to update service: %s", err)
} }
@ -184,7 +180,7 @@ func uninstallWindowsService(cmd *cobra.Command, args []string) error {
if err != nil { if err != nil {
return err return err
} }
defer m.Disconnect() defer m.Disconnect() //nolint:errcheck // TODO
// open service // open service
s, err := m.OpenService(serviceName) s, err := m.OpenService(serviceName)

View file

@ -1,6 +1,6 @@
package main 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 // https://github.com/golang/sys/blob/master/windows/svc/example
// by The Go Authors. // by The Go Authors.
// Original LICENSE (sha256sum: 2d36597f7117c38b006835ae7f537487207d8ec407aa9d9980794b2030cbc067) can be found in vendor/pkg cache directory. // Original LICENSE (sha256sum: 2d36597f7117c38b006835ae7f537487207d8ec407aa9d9980794b2030cbc067) can be found in vendor/pkg cache directory.
@ -84,7 +84,8 @@ service:
changes <- svc.Status{State: svc.Stopped} changes <- svc.Status{State: svc.Stopped}
// wait a little for the status to reach Windows // wait a little for the status to reach Windows
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
return
return ssec, errno
} }
func runService(cmd *cobra.Command, opts *Options) error { func runService(cmd *cobra.Command, opts *Options) error {
@ -121,7 +122,7 @@ func runService(cmd *cobra.Command, opts *Options) error {
go func() { go func() {
// run slightly delayed // run slightly delayed
time.Sleep(250 * time.Millisecond) time.Sleep(250 * time.Millisecond)
handleRun(cmd, opts) _ = handleRun(cmd, opts) // error handled by shutdown routine
finishWg.Done() finishWg.Done()
runWg.Done() runWg.Done()
}() }()
@ -131,7 +132,7 @@ func runService(cmd *cobra.Command, opts *Options) error {
err = getShutdownError() err = getShutdownError()
if err != nil { if err != nil {
log.Printf("%s service experienced an error: %s\n", serviceName, err) 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 return err