From ca3c7ff69e94fa7be0197a25a624eb939e8fe54d Mon Sep 17 00:00:00 2001 From: pytimer Date: Mon, 28 May 2018 13:41:40 +0800 Subject: [PATCH] [windows]services remove zsyscall_windows_ex.go file use golang/sys/windows QueryServiceStatusEx --- winservices/winservices.go | 4 +-- winservices/zsyscall_windows_ex.go | 57 -------------------------------------- 2 files changed, 2 insertions(+), 59 deletions(-) delete mode 100644 winservices/zsyscall_windows_ex.go diff --git a/winservices/winservices.go b/winservices/winservices.go index 47e6783..4112b2c 100644 --- a/winservices/winservices.go +++ b/winservices/winservices.go @@ -85,13 +85,13 @@ func (s *Service) QueryStatusWithContext(ctx context.Context) (ServiceStatus, er var bytesNeeded uint32 var buf []byte - if err := QueryServiceStatusEx(s.srv.Handle, SC_STATUS_PROCESS_INFO, nil, 0, &bytesNeeded); err != windows.ERROR_INSUFFICIENT_BUFFER { + if err := windows.QueryServiceStatusEx(s.srv.Handle, windows.SC_STATUS_PROCESS_INFO, nil, 0, &bytesNeeded); err != windows.ERROR_INSUFFICIENT_BUFFER { return ServiceStatus{}, err } buf = make([]byte, bytesNeeded) p = (*windows.SERVICE_STATUS_PROCESS)(unsafe.Pointer(&buf[0])) - if err := QueryServiceStatusEx(s.srv.Handle, SC_STATUS_PROCESS_INFO, &buf[0], uint32(len(buf)), &bytesNeeded); err != nil { + if err := windows.QueryServiceStatusEx(s.srv.Handle, windows.SC_STATUS_PROCESS_INFO, &buf[0], uint32(len(buf)), &bytesNeeded); err != nil { return ServiceStatus{}, err } diff --git a/winservices/zsyscall_windows_ex.go b/winservices/zsyscall_windows_ex.go deleted file mode 100644 index 8db9c51..0000000 --- a/winservices/zsyscall_windows_ex.go +++ /dev/null @@ -1,57 +0,0 @@ -// +build windows - -package winservices - -import ( - "syscall" - "unsafe" - - "golang.org/x/sys/windows" -) - -var ( - modadvapi32 = windows.NewLazySystemDLL("advapi32.dll") - procQueryServiceStatusEx = modadvapi32.NewProc("QueryServiceStatusEx") -) - -// Do the interface allocations only once for common -// Errno values. -const ( - errnoERROR_IO_PENDING = 997 -) - -var ( - errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) -) - -// errnoErr returns common boxed Errno values, to prevent -// allocations at runtime. -func errnoErr(e syscall.Errno) error { - switch e { - case 0: - return nil - case errnoERROR_IO_PENDING: - return errERROR_IO_PENDING - } - // TODO: add more here, after collecting data on the common - // error values see on Windows. (perhaps when running - // all.bat?) - return e -} - -// SC_STATUS_PROCESS_INFO reference to https://msdn.microsoft.com/en-us/library/windows/desktop/ms684941(v=vs.85).aspx, -// Use SC_STATUS_PROCESS_INFO to retrieve the service status information. -const SC_STATUS_PROCESS_INFO int = 0 - -// QueryServiceStatusEx golang/sys/windows standard library can not implement QueryServiceStatusEx. -func QueryServiceStatusEx(service windows.Handle, infoLevel int, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procQueryServiceStatusEx.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0) - if r1 == 0 { - if e1 != 0 { - err = errnoErr(e1) - } else { - err = syscall.EINVAL - } - } - return -}