From 9cf5787c47165b1426f2645c397c8f531d019e23 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 24 Sep 2024 14:06:37 -0400 Subject: [PATCH] adjust 'proctree' to use SIGINT instead of SIGKILL (#748) --- agent/proctree/impl_posix.go | 3 ++- agent/proctree/impl_windows.go | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/agent/proctree/impl_posix.go b/agent/proctree/impl_posix.go index aa8596c5..a82c37f9 100644 --- a/agent/proctree/impl_posix.go +++ b/agent/proctree/impl_posix.go @@ -5,6 +5,7 @@ package proctree import ( "os/exec" "sync" + "syscall" ) func Init(_ string) error { @@ -52,7 +53,7 @@ func WaitChild(c *Child) error { } func StopChild(c *Child) error { - if err := c.cmd.Process.Kill(); err != nil { + if err := syscall.Kill(c.cmd.Process.Pid, syscall.SIGINT); err != nil { return err } return nil diff --git a/agent/proctree/impl_windows.go b/agent/proctree/impl_windows.go index 6a446fe8..d6fc0398 100755 --- a/agent/proctree/impl_windows.go +++ b/agent/proctree/impl_windows.go @@ -3,7 +3,6 @@ package proctree import ( - "github.com/kolesnikovae/go-winjob" "golang.org/x/sys/windows" "os/exec" "sync" @@ -72,7 +71,23 @@ func WaitChild(c *Child) error { } func StopChild(c *Child) error { - if err := c.cmd.Process.Kill(); err != nil { + if err := sendSigInt(c); err != nil { + return err + } + return nil +} + +func sendSigInt(c *Child) error { + dll, err := syscall.LoadDLL("kernel32.dll") + if er != nil { + return err + } + proc, err := dll.FindProc("GenerateConsoleCtrlEvent") + if err != nil { + return err + } + r, _, err := proc.Call(syscall.CTRL_BREAK_EVENT, uintptr(c.cmd.Process.Pid)) + if err != nil { return err } return nil