vendor: Update golang.org/x/sys/... (fixes #4615)
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4619
This commit is contained in:
2
vendor/golang.org/x/sys/windows/svc/debug/service.go
generated
vendored
2
vendor/golang.org/x/sys/windows/svc/debug/service.go
generated
vendored
@@ -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:
|
||||
}
|
||||
}
|
||||
|
||||
2
vendor/golang.org/x/sys/windows/svc/go12.go
generated
vendored
2
vendor/golang.org/x/sys/windows/svc/go12.go
generated
vendored
@@ -1,4 +1,4 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
|
||||
2
vendor/golang.org/x/sys/windows/svc/go13.go
generated
vendored
2
vendor/golang.org/x/sys/windows/svc/go13.go
generated
vendored
@@ -1,4 +1,4 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
|
||||
47
vendor/golang.org/x/sys/windows/svc/mgr/mgr.go
generated
vendored
47
vendor/golang.org/x/sys/windows/svc/mgr/mgr.go
generated
vendored
@@ -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
|
||||
}
|
||||
|
||||
4
vendor/golang.org/x/sys/windows/svc/mgr/service.go
generated
vendored
4
vendor/golang.org/x/sys/windows/svc/mgr/service.go
generated
vendored
@@ -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
|
||||
@@ -39,7 +37,7 @@ func (s *Service) Start(args ...string) error {
|
||||
var p **uint16
|
||||
if len(args) > 0 {
|
||||
vs := make([]*uint16, len(args))
|
||||
for i, _ := range vs {
|
||||
for i := range vs {
|
||||
vs[i] = syscall.StringToUTF16Ptr(args[i])
|
||||
}
|
||||
p = &vs[0]
|
||||
|
||||
97
vendor/golang.org/x/sys/windows/svc/service.go
generated
vendored
97
vendor/golang.org/x/sys/windows/svc/service.go
generated
vendored
@@ -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.
|
||||
@@ -47,9 +56,14 @@ const (
|
||||
type Accepted uint32
|
||||
|
||||
const (
|
||||
AcceptStop = Accepted(windows.SERVICE_ACCEPT_STOP)
|
||||
AcceptShutdown = Accepted(windows.SERVICE_ACCEPT_SHUTDOWN)
|
||||
AcceptPauseAndContinue = Accepted(windows.SERVICE_ACCEPT_PAUSE_CONTINUE)
|
||||
AcceptStop = Accepted(windows.SERVICE_ACCEPT_STOP)
|
||||
AcceptShutdown = Accepted(windows.SERVICE_ACCEPT_SHUTDOWN)
|
||||
AcceptPauseAndContinue = Accepted(windows.SERVICE_ACCEPT_PAUSE_CONTINUE)
|
||||
AcceptParamChange = Accepted(windows.SERVICE_ACCEPT_PARAMCHANGE)
|
||||
AcceptNetBindChange = Accepted(windows.SERVICE_ACCEPT_NETBINDCHANGE)
|
||||
AcceptHardwareProfileChange = Accepted(windows.SERVICE_ACCEPT_HARDWAREPROFILECHANGE)
|
||||
AcceptPowerEvent = Accepted(windows.SERVICE_ACCEPT_POWEREVENT)
|
||||
AcceptSessionChange = Accepted(windows.SERVICE_ACCEPT_SESSIONCHANGE)
|
||||
)
|
||||
|
||||
// Status combines State and Accepted commands to fully describe running service.
|
||||
@@ -63,6 +77,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 +101,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 +118,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.
|
||||
@@ -165,6 +185,21 @@ func (s *service) updateStatus(status *Status, ec *exitCode) error {
|
||||
if status.Accepts&AcceptPauseAndContinue != 0 {
|
||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_PAUSE_CONTINUE
|
||||
}
|
||||
if status.Accepts&AcceptParamChange != 0 {
|
||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_PARAMCHANGE
|
||||
}
|
||||
if status.Accepts&AcceptNetBindChange != 0 {
|
||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_NETBINDCHANGE
|
||||
}
|
||||
if status.Accepts&AcceptHardwareProfileChange != 0 {
|
||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_HARDWAREPROFILECHANGE
|
||||
}
|
||||
if status.Accepts&AcceptPowerEvent != 0 {
|
||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_POWEREVENT
|
||||
}
|
||||
if status.Accepts&AcceptSessionChange != 0 {
|
||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_SESSIONCHANGE
|
||||
}
|
||||
if ec.errno == 0 {
|
||||
t.Win32ExitCode = windows.NO_ERROR
|
||||
t.ServiceSpecificExitCode = windows.NO_ERROR
|
||||
@@ -208,6 +243,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 +256,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 +315,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 +327,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 +341,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 +354,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)
|
||||
}
|
||||
|
||||
7
vendor/golang.org/x/sys/windows/svc/sys_386.s
generated
vendored
7
vendor/golang.org/x/sys/windows/svc/sys_386.s
generated
vendored
@@ -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
|
||||
|
||||
7
vendor/golang.org/x/sys/windows/svc/sys_amd64.s
generated
vendored
7
vendor/golang.org/x/sys/windows/svc/sys_amd64.s
generated
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user