Deps update, gopkg.lock fix, flagger initialization fix.
This commit is contained in:
40
vendor/golang.org/x/sys/windows/svc/mgr/config.go
generated
vendored
40
vendor/golang.org/x/sys/windows/svc/mgr/config.go
generated
vendored
@@ -88,23 +88,11 @@ func (s *Service) Config() (Config, error) {
|
||||
}
|
||||
}
|
||||
|
||||
var p2 *windows.SERVICE_DESCRIPTION
|
||||
n = uint32(1024)
|
||||
for {
|
||||
b := make([]byte, n)
|
||||
p2 = (*windows.SERVICE_DESCRIPTION)(unsafe.Pointer(&b[0]))
|
||||
err := windows.QueryServiceConfig2(s.Handle,
|
||||
windows.SERVICE_CONFIG_DESCRIPTION, &b[0], n, &n)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
if err.(syscall.Errno) != syscall.ERROR_INSUFFICIENT_BUFFER {
|
||||
return Config{}, err
|
||||
}
|
||||
if n <= uint32(len(b)) {
|
||||
return Config{}, err
|
||||
}
|
||||
b, err := s.queryServiceConfig2(windows.SERVICE_CONFIG_DESCRIPTION)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
p2 := (*windows.SERVICE_DESCRIPTION)(unsafe.Pointer(&b[0]))
|
||||
|
||||
return Config{
|
||||
ServiceType: p.ServiceType,
|
||||
@@ -121,7 +109,7 @@ func (s *Service) Config() (Config, error) {
|
||||
}
|
||||
|
||||
func updateDescription(handle windows.Handle, desc string) error {
|
||||
d := windows.SERVICE_DESCRIPTION{toPtr(desc)}
|
||||
d := windows.SERVICE_DESCRIPTION{Description: toPtr(desc)}
|
||||
return windows.ChangeServiceConfig2(handle,
|
||||
windows.SERVICE_CONFIG_DESCRIPTION, (*byte)(unsafe.Pointer(&d)))
|
||||
}
|
||||
@@ -137,3 +125,21 @@ func (s *Service) UpdateConfig(c Config) error {
|
||||
}
|
||||
return updateDescription(s.Handle, c.Description)
|
||||
}
|
||||
|
||||
// queryServiceConfig2 calls Windows QueryServiceConfig2 with infoLevel parameter and returns retrieved service configuration information.
|
||||
func (s *Service) queryServiceConfig2(infoLevel uint32) ([]byte, error) {
|
||||
n := uint32(1024)
|
||||
for {
|
||||
b := make([]byte, n)
|
||||
err := windows.QueryServiceConfig2(s.Handle, infoLevel, &b[0], n, &n)
|
||||
if err == nil {
|
||||
return b, nil
|
||||
}
|
||||
if err.(syscall.Errno) != syscall.ERROR_INSUFFICIENT_BUFFER {
|
||||
return nil, err
|
||||
}
|
||||
if n <= uint32(len(b)) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
113
vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go
generated
vendored
113
vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go
generated
vendored
@@ -95,6 +95,113 @@ func testConfig(t *testing.T, s *mgr.Service, should mgr.Config) mgr.Config {
|
||||
return is
|
||||
}
|
||||
|
||||
func testRecoveryActions(t *testing.T, s *mgr.Service, should []mgr.RecoveryAction) {
|
||||
is, err := s.RecoveryActions()
|
||||
if err != nil {
|
||||
t.Fatalf("RecoveryActions failed: %s", err)
|
||||
}
|
||||
if len(should) != len(is) {
|
||||
t.Errorf("recovery action mismatch: contains %v actions, but should have %v", len(is), len(should))
|
||||
}
|
||||
for i, _ := range is {
|
||||
if should[i].Type != is[i].Type {
|
||||
t.Errorf("recovery action mismatch: Type is %v, but should have %v", is[i].Type, should[i].Type)
|
||||
}
|
||||
if should[i].Delay != is[i].Delay {
|
||||
t.Errorf("recovery action mismatch: Delay is %v, but should have %v", is[i].Delay, should[i].Delay)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testResetPeriod(t *testing.T, s *mgr.Service, should uint32) {
|
||||
is, err := s.ResetPeriod()
|
||||
if err != nil {
|
||||
t.Fatalf("ResetPeriod failed: %s", err)
|
||||
}
|
||||
if should != is {
|
||||
t.Errorf("reset period mismatch: reset period is %v, but should have %v", is, should)
|
||||
}
|
||||
}
|
||||
|
||||
func testSetRecoveryActions(t *testing.T, s *mgr.Service) {
|
||||
r := []mgr.RecoveryAction{
|
||||
mgr.RecoveryAction{
|
||||
Type: mgr.NoAction,
|
||||
Delay: 60000 * time.Millisecond,
|
||||
},
|
||||
mgr.RecoveryAction{
|
||||
Type: mgr.ServiceRestart,
|
||||
Delay: 4 * time.Minute,
|
||||
},
|
||||
mgr.RecoveryAction{
|
||||
Type: mgr.ServiceRestart,
|
||||
Delay: time.Minute,
|
||||
},
|
||||
mgr.RecoveryAction{
|
||||
Type: mgr.RunCommand,
|
||||
Delay: 4000 * time.Millisecond,
|
||||
},
|
||||
}
|
||||
|
||||
// 4 recovery actions with reset period
|
||||
err := s.SetRecoveryActions(r, uint32(10000))
|
||||
if err != nil {
|
||||
t.Fatalf("SetRecoveryActions failed: %v", err)
|
||||
}
|
||||
testRecoveryActions(t, s, r)
|
||||
testResetPeriod(t, s, uint32(10000))
|
||||
|
||||
// Infinite reset period
|
||||
err = s.SetRecoveryActions(r, syscall.INFINITE)
|
||||
if err != nil {
|
||||
t.Fatalf("SetRecoveryActions failed: %v", err)
|
||||
}
|
||||
testRecoveryActions(t, s, r)
|
||||
testResetPeriod(t, s, syscall.INFINITE)
|
||||
|
||||
// nil recovery actions
|
||||
err = s.SetRecoveryActions(nil, 0)
|
||||
if err.Error() != "recoveryActions cannot be nil" {
|
||||
t.Fatalf("SetRecoveryActions failed with unexpected error message of %q", err)
|
||||
}
|
||||
|
||||
// Delete all recovery actions and reset period
|
||||
err = s.ResetRecoveryActions()
|
||||
if err != nil {
|
||||
t.Fatalf("ResetRecoveryActions failed: %v", err)
|
||||
}
|
||||
testRecoveryActions(t, s, nil)
|
||||
testResetPeriod(t, s, 0)
|
||||
}
|
||||
|
||||
func testRebootMessage(t *testing.T, s *mgr.Service, should string) {
|
||||
err := s.SetRebootMessage(should)
|
||||
if err != nil {
|
||||
t.Fatalf("SetRebootMessage failed: %v", err)
|
||||
}
|
||||
is, err := s.RebootMessage()
|
||||
if err != nil {
|
||||
t.Fatalf("RebootMessage failed: %v", err)
|
||||
}
|
||||
if should != is {
|
||||
t.Errorf("reboot message mismatch: message is %q, but should have %q", is, should)
|
||||
}
|
||||
}
|
||||
|
||||
func testRecoveryCommand(t *testing.T, s *mgr.Service, should string) {
|
||||
err := s.SetRecoveryCommand(should)
|
||||
if err != nil {
|
||||
t.Fatalf("SetRecoveryCommand failed: %v", err)
|
||||
}
|
||||
is, err := s.RecoveryCommand()
|
||||
if err != nil {
|
||||
t.Fatalf("RecoveryCommand failed: %v", err)
|
||||
}
|
||||
if should != is {
|
||||
t.Errorf("recovery command mismatch: command is %q, but should have %q", is, should)
|
||||
}
|
||||
}
|
||||
|
||||
func remove(t *testing.T, s *mgr.Service) {
|
||||
err := s.Delete()
|
||||
if err != nil {
|
||||
@@ -165,5 +272,11 @@ func TestMyService(t *testing.T) {
|
||||
t.Errorf("ListServices failed to find %q service", name)
|
||||
}
|
||||
|
||||
testSetRecoveryActions(t, s)
|
||||
testRebootMessage(t, s, "myservice failed")
|
||||
testRebootMessage(t, s, "") // delete reboot message
|
||||
testRecoveryCommand(t, s, "sc query myservice")
|
||||
testRecoveryCommand(t, s, "") // delete recovery command
|
||||
|
||||
remove(t, s)
|
||||
}
|
||||
|
Reference in New Issue
Block a user