diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-06-22 19:54:26 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-06-22 19:56:14 +0200 |
commit | e99d28cf81a6d39a8ea102de48d1cd866ad351db (patch) | |
tree | ce194526397dcc82a482b195b578f0e9580cb9a2 | |
parent | version: bump (diff) | |
download | wireguard-windows-e99d28cf81a6d39a8ea102de48d1cd866ad351db.tar.xz wireguard-windows-e99d28cf81a6d39a8ea102de48d1cd866ad351db.zip |
manager: do not terminate current process when intended target is child
If we've already collected this, handle is -1, which is current process.
Catch this case.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | manager/uiprocess.go | 6 | ||||
-rw-r--r-- | services/errors.go | 3 |
2 files changed, 6 insertions, 3 deletions
diff --git a/manager/uiprocess.go b/manager/uiprocess.go index 80ac8b30..08c29f40 100644 --- a/manager/uiprocess.go +++ b/manager/uiprocess.go @@ -95,5 +95,9 @@ func (p *uiProcess) Wait() (uint32, error) { } func (p *uiProcess) Kill() error { - return windows.TerminateProcess(windows.Handle(atomic.LoadUintptr(&p.handle)), 1) + handle := windows.Handle(atomic.LoadUintptr(&p.handle)) + if handle == windows.InvalidHandle { + return nil + } + return windows.TerminateProcess(handle, 1) } diff --git a/services/errors.go b/services/errors.go index 569585a5..674c083b 100644 --- a/services/errors.go +++ b/services/errors.go @@ -7,7 +7,6 @@ package services import ( "fmt" - "syscall" "golang.org/x/sys/windows" ) @@ -73,7 +72,7 @@ func (e Error) Error() string { } func DetermineErrorCode(err error, serviceError Error) (bool, uint32) { - if syserr, ok := err.(syscall.Errno); ok { + if syserr, ok := err.(windows.Errno); ok { return false, uint32(syserr) } else if serviceError != ErrorSuccess { return true, uint32(serviceError) |