diff --git a/cmd.go b/cmd.go index e1e1fb7..68814a2 100644 --- a/cmd.go +++ b/cmd.go @@ -12,7 +12,7 @@ func runCommand(args []string) *exec.Cmd { cmd := exec.Command(args[0], args[1:]...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} + setProcAttr(cmd) fmt.Println("[*] running command:", cmd) err := cmd.Start() @@ -28,14 +28,8 @@ func stopCommand(cmd *exec.Cmd) { return } - err := syscall.Kill(-cmd.Process.Pid, syscall.Signal(0)) - if err != nil && err.Error() == "operation not permitted" { - // process no longer running, nothing to do here - return - } - fmt.Println("[*] stopping process", cmd.Process.Pid) - e := syscall.Kill(-cmd.Process.Pid, syscall.SIGTERM) + e := cmd.Process.Signal(syscall.SIGTERM) if e != nil { fmt.Println("error killing child process:", e) } diff --git a/cmd_nix.go b/cmd_nix.go new file mode 100644 index 0000000..fad11de --- /dev/null +++ b/cmd_nix.go @@ -0,0 +1,12 @@ +//go:build linux || darwin + +package vproxy + +import ( + "os/exec" + "syscall" +) + +func setProcAttr(cmd *exec.Cmd) { + cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} +} diff --git a/cmd_windows.go b/cmd_windows.go new file mode 100644 index 0000000..4e14061 --- /dev/null +++ b/cmd_windows.go @@ -0,0 +1,12 @@ +//go:build windows + +package vproxy + +import ( + "os/exec" + "syscall" +) + +func setProcAttr(cmd *exec.Cmd) { + cmd.SysProcAttr = &syscall.SysProcAttr{} +}