Skip to content

Commit

Permalink
fix: windows build compat
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Jul 19, 2022
1 parent 5cad911 commit 73442db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
10 changes: 2 additions & 8 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
Expand Down
12 changes: 12 additions & 0 deletions cmd_nix.go
Original file line number Diff line number Diff line change
@@ -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}
}
12 changes: 12 additions & 0 deletions cmd_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build windows

package vproxy

import (
"os/exec"
"syscall"
)

func setProcAttr(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{}
}

0 comments on commit 73442db

Please sign in to comment.