fix(checks): os_service lifecycle bugfix

pull/13388/head
Alessandro De Blasis 2 years ago
parent fc0dd92dcf
commit f440966a38

@ -16,20 +16,19 @@ var (
win windowsSystem = windowsOS{} win windowsSystem = windowsOS{}
) )
type OSServiceClient struct { type OSServiceClient struct{}
scHandle windows.Handle
}
func NewOSServiceClient() (*OSServiceClient, error) { func NewOSServiceClient() (*OSServiceClient, error) {
scHandle, err := win.OpenSCManager(nil, nil, windows.SC_MANAGER_CONNECT) return &OSServiceClient{}, nil
if err != nil {
return nil, fmt.Errorf("error connecting to service manager: %w", err)
}
return &OSServiceClient{scHandle: scHandle}, nil
} }
func (client *OSServiceClient) Check(serviceName string) (err error) { func (client *OSServiceClient) Check(serviceName string) (err error) {
m := win.getWindowsSvcMgr(client.scHandle) h, err := windows.OpenSCManager(nil, nil, windows.SC_MANAGER_CONNECT)
if err != nil {
return fmt.Errorf("failed to connect to Windows service manager: %w", err)
}
m := win.getWindowsSvcMgr(h)
defer m.Disconnect() defer m.Disconnect()
svcNamePtr, err := syscall.UTF16PtrFromString(serviceName) svcNamePtr, err := syscall.UTF16PtrFromString(serviceName)

Loading…
Cancel
Save