mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-06 09:07:16 -04:00
windows/svc/mgr: Service.Control: populate Status when returning certain errors
Fixes golang/go#59015 Change-Id: I45f22049f3a05f807f78d20c9ed67c6c79e3d3c1 GitHub-Last-Rev: 929aeb4acb899e813a44dee1e9a441876939493c GitHub-Pull-Request: golang/sys#156 Reviewed-on: https://go-review.googlesource.com/c/sys/+/484895 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Run-TryBot: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
committed by
Alex Brainman
parent
2a33a30b79
commit
9524d496ef
@@ -45,17 +45,25 @@ func (s *Service) Start(args ...string) error {
|
||||
return windows.StartService(s.Handle, uint32(len(args)), p)
|
||||
}
|
||||
|
||||
// Control sends state change request c to the service s.
|
||||
// Control sends state change request c to the service s. It returns the most
|
||||
// recent status the service reported to the service control manager, and an
|
||||
// error if the state change request was not accepted.
|
||||
// Note that the returned service status is only set if the status change
|
||||
// request succeeded, or if it failed with error ERROR_INVALID_SERVICE_CONTROL,
|
||||
// ERROR_SERVICE_CANNOT_ACCEPT_CTRL, or ERROR_SERVICE_NOT_ACTIVE.
|
||||
func (s *Service) Control(c svc.Cmd) (svc.Status, error) {
|
||||
var t windows.SERVICE_STATUS
|
||||
err := windows.ControlService(s.Handle, uint32(c), &t)
|
||||
if err != nil {
|
||||
if err != nil &&
|
||||
err != windows.ERROR_INVALID_SERVICE_CONTROL &&
|
||||
err != windows.ERROR_SERVICE_CANNOT_ACCEPT_CTRL &&
|
||||
err != windows.ERROR_SERVICE_NOT_ACTIVE {
|
||||
return svc.Status{}, err
|
||||
}
|
||||
return svc.Status{
|
||||
State: svc.State(t.CurrentState),
|
||||
Accepts: svc.Accepted(t.ControlsAccepted),
|
||||
}, nil
|
||||
}, err
|
||||
}
|
||||
|
||||
// Query returns current status of service s.
|
||||
|
||||
Reference in New Issue
Block a user