From 42f28ab8e374137fe3f5d25424489d879d4724f8 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Wed, 21 Jun 2017 19:06:17 -0700 Subject: Updating server dependancies (#6712) --- .../golang.org/x/sys/windows/svc/debug/service.go | 2 +- vendor/golang.org/x/sys/windows/svc/mgr/mgr.go | 47 +++++++++++++- .../golang.org/x/sys/windows/svc/mgr/mgr_test.go | 15 +++++ vendor/golang.org/x/sys/windows/svc/mgr/service.go | 2 - vendor/golang.org/x/sys/windows/svc/service.go | 71 +++++++++++++++------- vendor/golang.org/x/sys/windows/svc/sys_386.s | 7 ++- vendor/golang.org/x/sys/windows/svc/sys_amd64.s | 7 ++- 7 files changed, 118 insertions(+), 33 deletions(-) (limited to 'vendor/golang.org/x/sys/windows/svc') diff --git a/vendor/golang.org/x/sys/windows/svc/debug/service.go b/vendor/golang.org/x/sys/windows/svc/debug/service.go index d5ab94b2c..123df9893 100644 --- a/vendor/golang.org/x/sys/windows/svc/debug/service.go +++ b/vendor/golang.org/x/sys/windows/svc/debug/service.go @@ -31,7 +31,7 @@ func Run(name string, handler svc.Handler) error { for { select { case <-sig: - cmds <- svc.ChangeRequest{svc.Stop, status} + cmds <- svc.ChangeRequest{svc.Stop, 0, 0, status} case status = <-changes: } } diff --git a/vendor/golang.org/x/sys/windows/svc/mgr/mgr.go b/vendor/golang.org/x/sys/windows/svc/mgr/mgr.go index da8ceb6ed..76965b560 100644 --- a/vendor/golang.org/x/sys/windows/svc/mgr/mgr.go +++ b/vendor/golang.org/x/sys/windows/svc/mgr/mgr.go @@ -14,6 +14,7 @@ package mgr import ( "syscall" "unicode/utf16" + "unsafe" "golang.org/x/sys/windows" ) @@ -76,8 +77,10 @@ func toStringBlock(ss []string) *uint16 { // CreateService installs new service name on the system. // The service will be executed by running exepath binary. // Use config c to specify service parameters. -// If service StartType is set to StartAutomatic, -// args will be passed to svc.Handle.Execute. +// Any args will be passed as command-line arguments when +// the service is started; these arguments are distinct from +// the arguments passed to Service.Start or via the "Start +// parameters" field in the service's Properties dialog box. func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Service, error) { if c.StartType == 0 { c.StartType = StartManual @@ -117,3 +120,43 @@ func (m *Mgr) OpenService(name string) (*Service, error) { } return &Service{Name: name, Handle: h}, nil } + +// ListServices enumerates services in the specified +// service control manager database m. +// If the caller does not have the SERVICE_QUERY_STATUS +// access right to a service, the service is silently +// omitted from the list of services returned. +func (m *Mgr) ListServices() ([]string, error) { + var err error + var bytesNeeded, servicesReturned uint32 + var buf []byte + for { + var p *byte + if len(buf) > 0 { + p = &buf[0] + } + err = windows.EnumServicesStatusEx(m.Handle, windows.SC_ENUM_PROCESS_INFO, + windows.SERVICE_WIN32, windows.SERVICE_STATE_ALL, + p, uint32(len(buf)), &bytesNeeded, &servicesReturned, nil, nil) + if err == nil { + break + } + if err != syscall.ERROR_MORE_DATA { + return nil, err + } + if bytesNeeded <= uint32(len(buf)) { + return nil, err + } + buf = make([]byte, bytesNeeded) + } + if servicesReturned == 0 { + return nil, nil + } + services := (*[1 << 20]windows.ENUM_SERVICE_STATUS_PROCESS)(unsafe.Pointer(&buf[0]))[:servicesReturned] + var names []string + for _, s := range services { + name := syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(s.ServiceName))[:]) + names = append(names, name) + } + return names, nil +} diff --git a/vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go b/vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go index 78be970c0..e67407cf1 100644 --- a/vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go +++ b/vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go @@ -150,5 +150,20 @@ func TestMyService(t *testing.T) { testConfig(t, s, c) + svcnames, err := m.ListServices() + if err != nil { + t.Fatalf("ListServices failed: %v", err) + } + var myserviceIsInstalled bool + for _, sn := range svcnames { + if sn == name { + myserviceIsInstalled = true + break + } + } + if !myserviceIsInstalled { + t.Errorf("ListServices failed to find %q service", name) + } + remove(t, s) } diff --git a/vendor/golang.org/x/sys/windows/svc/mgr/service.go b/vendor/golang.org/x/sys/windows/svc/mgr/service.go index ac9fba5a1..fdc46af5f 100644 --- a/vendor/golang.org/x/sys/windows/svc/mgr/service.go +++ b/vendor/golang.org/x/sys/windows/svc/mgr/service.go @@ -15,8 +15,6 @@ import ( // TODO(brainman): Use EnumDependentServices to enumerate dependent services. -// TODO(brainman): Use EnumServicesStatus to enumerate services in the specified service control manager database. - // Service is used to access Windows service. type Service struct { Name string diff --git a/vendor/golang.org/x/sys/windows/svc/service.go b/vendor/golang.org/x/sys/windows/svc/service.go index 9864f7a72..1ea4a88f1 100644 --- a/vendor/golang.org/x/sys/windows/svc/service.go +++ b/vendor/golang.org/x/sys/windows/svc/service.go @@ -35,11 +35,20 @@ const ( type Cmd uint32 const ( - Stop = Cmd(windows.SERVICE_CONTROL_STOP) - Pause = Cmd(windows.SERVICE_CONTROL_PAUSE) - Continue = Cmd(windows.SERVICE_CONTROL_CONTINUE) - Interrogate = Cmd(windows.SERVICE_CONTROL_INTERROGATE) - Shutdown = Cmd(windows.SERVICE_CONTROL_SHUTDOWN) + Stop = Cmd(windows.SERVICE_CONTROL_STOP) + Pause = Cmd(windows.SERVICE_CONTROL_PAUSE) + Continue = Cmd(windows.SERVICE_CONTROL_CONTINUE) + Interrogate = Cmd(windows.SERVICE_CONTROL_INTERROGATE) + Shutdown = Cmd(windows.SERVICE_CONTROL_SHUTDOWN) + ParamChange = Cmd(windows.SERVICE_CONTROL_PARAMCHANGE) + NetBindAdd = Cmd(windows.SERVICE_CONTROL_NETBINDADD) + NetBindRemove = Cmd(windows.SERVICE_CONTROL_NETBINDREMOVE) + NetBindEnable = Cmd(windows.SERVICE_CONTROL_NETBINDENABLE) + NetBindDisable = Cmd(windows.SERVICE_CONTROL_NETBINDDISABLE) + DeviceEvent = Cmd(windows.SERVICE_CONTROL_DEVICEEVENT) + HardwareProfileChange = Cmd(windows.SERVICE_CONTROL_HARDWAREPROFILECHANGE) + PowerEvent = Cmd(windows.SERVICE_CONTROL_POWEREVENT) + SessionChange = Cmd(windows.SERVICE_CONTROL_SESSIONCHANGE) ) // Accepted is used to describe commands accepted by the service. @@ -63,6 +72,8 @@ type Status struct { // ChangeRequest is sent to the service Handler to request service status change. type ChangeRequest struct { Cmd Cmd + EventType uint32 + EventData uintptr CurrentStatus Status } @@ -85,16 +96,16 @@ type Handler interface { var ( // These are used by asm code. - goWaitsH uintptr - cWaitsH uintptr - ssHandle uintptr - sName *uint16 - sArgc uintptr - sArgv **uint16 - ctlHandlerProc uintptr - cSetEvent uintptr - cWaitForSingleObject uintptr - cRegisterServiceCtrlHandlerW uintptr + goWaitsH uintptr + cWaitsH uintptr + ssHandle uintptr + sName *uint16 + sArgc uintptr + sArgv **uint16 + ctlHandlerExProc uintptr + cSetEvent uintptr + cWaitForSingleObject uintptr + cRegisterServiceCtrlHandlerExW uintptr ) func init() { @@ -102,12 +113,16 @@ func init() { cSetEvent = k.MustFindProc("SetEvent").Addr() cWaitForSingleObject = k.MustFindProc("WaitForSingleObject").Addr() a := syscall.MustLoadDLL("advapi32.dll") - cRegisterServiceCtrlHandlerW = a.MustFindProc("RegisterServiceCtrlHandlerW").Addr() + cRegisterServiceCtrlHandlerExW = a.MustFindProc("RegisterServiceCtrlHandlerExW").Addr() } +// The HandlerEx prototype also has a context pointer but since we don't use +// it at start-up time we don't have to pass it over either. type ctlEvent struct { - cmd Cmd - errno uint32 + cmd Cmd + eventType uint32 + eventData uintptr + errno uint32 } // service provides access to windows service api. @@ -208,6 +223,8 @@ func (s *service) run() { var outch chan ChangeRequest inch := s.c var cmd Cmd + var evtype uint32 + var evdata uintptr loop: for { select { @@ -219,7 +236,9 @@ loop: inch = nil outch = cmdsToHandler cmd = r.cmd - case outch <- ChangeRequest{cmd, status}: + evtype = r.eventType + evdata = r.eventData + case outch <- ChangeRequest{cmd, evtype, evdata, status}: inch = s.c outch = nil case c := <-changesFromHandler: @@ -276,8 +295,8 @@ func Run(name string, handler Handler) error { return err } - ctlHandler := func(ctl uint32) uintptr { - e := ctlEvent{cmd: Cmd(ctl)} + ctlHandler := func(ctl uint32, evtype uint32, evdata uintptr, context uintptr) uintptr { + e := ctlEvent{cmd: Cmd(ctl), eventType: evtype, eventData: evdata} // We assume that this callback function is running on // the same thread as Run. Nowhere in MS documentation // I could find statement to guarantee that. So putting @@ -288,6 +307,7 @@ func Run(name string, handler Handler) error { e.errno = sysErrNewThreadInCallback } s.c <- e + // Always return NO_ERROR (0) for now. return 0 } @@ -301,7 +321,7 @@ func Run(name string, handler Handler) error { goWaitsH = uintptr(s.goWaits.h) cWaitsH = uintptr(s.cWaits.h) sName = t[0].ServiceName - ctlHandlerProc, err = newCallback(ctlHandler) + ctlHandlerExProc, err = newCallback(ctlHandler) if err != nil { return err } @@ -314,3 +334,10 @@ func Run(name string, handler Handler) error { } return nil } + +// StatusHandle returns service status handle. It is safe to call this function +// from inside the Handler.Execute because then it is guaranteed to be set. +// This code will have to change once multiple services are possible per process. +func StatusHandle() windows.Handle { + return windows.Handle(ssHandle) +} diff --git a/vendor/golang.org/x/sys/windows/svc/sys_386.s b/vendor/golang.org/x/sys/windows/svc/sys_386.s index 5e11bfadb..2c82a9d91 100644 --- a/vendor/golang.org/x/sys/windows/svc/sys_386.s +++ b/vendor/golang.org/x/sys/windows/svc/sys_386.s @@ -22,7 +22,8 @@ TEXT ·servicemain(SB),7,$0 MOVL AX, (SP) MOVL $·servicectlhandler(SB), AX MOVL AX, 4(SP) - MOVL ·cRegisterServiceCtrlHandlerW(SB), AX + MOVL $0, 8(SP) + MOVL ·cRegisterServiceCtrlHandlerExW(SB), AX MOVL SP, BP CALL AX MOVL BP, SP @@ -61,7 +62,7 @@ exit: // I do not know why, but this seems to be the only way to call // ctlHandlerProc on Windows 7. -// func servicectlhandler(ctl uint32) uintptr +// func servicectlhandler(ctl uint32, evtype uint32, evdata uintptr, context uintptr) uintptr { TEXT ·servicectlhandler(SB),7,$0 - MOVL ·ctlHandlerProc(SB), CX + MOVL ·ctlHandlerExProc(SB), CX JMP CX diff --git a/vendor/golang.org/x/sys/windows/svc/sys_amd64.s b/vendor/golang.org/x/sys/windows/svc/sys_amd64.s index 87dbec839..06b425900 100644 --- a/vendor/golang.org/x/sys/windows/svc/sys_amd64.s +++ b/vendor/golang.org/x/sys/windows/svc/sys_amd64.s @@ -13,7 +13,8 @@ TEXT ·servicemain(SB),7,$0 MOVQ ·sName(SB), CX MOVQ $·servicectlhandler(SB), DX - MOVQ ·cRegisterServiceCtrlHandlerW(SB), AX + // BUG(pastarmovj): Figure out a way to pass in context in R8. + MOVQ ·cRegisterServiceCtrlHandlerExW(SB), AX CALL AX CMPQ AX, $0 JE exit @@ -35,7 +36,7 @@ exit: // I do not know why, but this seems to be the only way to call // ctlHandlerProc on Windows 7. -// func servicectlhandler(ctl uint32) uintptr +// func ·servicectlhandler(ctl uint32, evtype uint32, evdata uintptr, context uintptr) uintptr { TEXT ·servicectlhandler(SB),7,$0 - MOVQ ·ctlHandlerProc(SB), AX + MOVQ ·ctlHandlerExProc(SB), AX JMP AX -- cgit v1.2.3-1-g7c22