Skip to content

Commit 73442db

Browse files
committed
fix: windows build compat
1 parent 5cad911 commit 73442db

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

cmd.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func runCommand(args []string) *exec.Cmd {
1212
cmd := exec.Command(args[0], args[1:]...)
1313
cmd.Stdout = os.Stdout
1414
cmd.Stderr = os.Stderr
15-
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
15+
setProcAttr(cmd)
1616

1717
fmt.Println("[*] running command:", cmd)
1818
err := cmd.Start()
@@ -28,14 +28,8 @@ func stopCommand(cmd *exec.Cmd) {
2828
return
2929
}
3030

31-
err := syscall.Kill(-cmd.Process.Pid, syscall.Signal(0))
32-
if err != nil && err.Error() == "operation not permitted" {
33-
// process no longer running, nothing to do here
34-
return
35-
}
36-
3731
fmt.Println("[*] stopping process", cmd.Process.Pid)
38-
e := syscall.Kill(-cmd.Process.Pid, syscall.SIGTERM)
32+
e := cmd.Process.Signal(syscall.SIGTERM)
3933
if e != nil {
4034
fmt.Println("error killing child process:", e)
4135
}

cmd_nix.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build linux || darwin
2+
3+
package vproxy
4+
5+
import (
6+
"os/exec"
7+
"syscall"
8+
)
9+
10+
func setProcAttr(cmd *exec.Cmd) {
11+
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
12+
}

cmd_windows.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build windows
2+
3+
package vproxy
4+
5+
import (
6+
"os/exec"
7+
"syscall"
8+
)
9+
10+
func setProcAttr(cmd *exec.Cmd) {
11+
cmd.SysProcAttr = &syscall.SysProcAttr{}
12+
}

0 commit comments

Comments
 (0)