From e99d28cf81a6d39a8ea102de48d1cd866ad351db Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 22 Jun 2021 19:54:26 +0200 Subject: 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 --- manager/uiprocess.go | 6 +++++- 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) -- cgit v1.2.3-59-g8ed1b