Skip to content

Commit

Permalink
adjust 'proctree' to use SIGINT instead of SIGKILL (#748)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Sep 24, 2024
1 parent 2163f02 commit 9cf5787
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion agent/proctree/impl_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package proctree
import (
"os/exec"
"sync"
"syscall"
)

func Init(_ string) error {
Expand Down Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions agent/proctree/impl_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package proctree

import (
"github.com/kolesnikovae/go-winjob"
"golang.org/x/sys/windows"
"os/exec"
"sync"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9cf5787

Please sign in to comment.