Skip to content

Commit

Permalink
fix: argocd build fails on windows (argoproj#8319)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Matyushentsev <[email protected]>
  • Loading branch information
Alexander Matyushentsev authored Jan 30, 2022
1 parent 85c114d commit 580a696
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
5 changes: 2 additions & 3 deletions cmpserver/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os/exec"
"path/filepath"
"strings"
"syscall"
"time"

"github.com/argoproj/pkg/rand"
Expand Down Expand Up @@ -68,7 +67,7 @@ func runCommand(ctx context.Context, command Command, path string, env []string)
cmd.Stderr = &stderr

// Make sure the command is killed immediately on timeout. https://stackoverflow.com/a/38133948/684776
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
cmd.SysProcAttr = newSysProcAttr(true)

start := time.Now()
err = cmd.Start()
Expand All @@ -80,7 +79,7 @@ func runCommand(ctx context.Context, command Command, path string, env []string)
<-ctx.Done()
// Kill by group ID to make sure child processes are killed. The - tells `kill` that it's a group ID.
// Since we didn't set Pgid in SysProcAttr, the group ID is the same as the process ID. https://pkg.go.dev/syscall#SysProcAttr
_ = syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
_ = sysCallKill(-cmd.Process.Pid)
}()

err = cmd.Wait()
Expand Down
16 changes: 16 additions & 0 deletions cmpserver/plugin/plugin_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build !windows
// +build !windows

package plugin

import (
"syscall"
)

func newSysProcAttr(setpgid bool) *syscall.SysProcAttr {
return &syscall.SysProcAttr{Setpgid: setpgid}
}

func sysCallKill(pid int) error {
return syscall.Kill(pid, syscall.SIGKILL)
}
16 changes: 16 additions & 0 deletions cmpserver/plugin/plugin_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build windows
// +build windows

package plugin

import (
"syscall"
)

func newSysProcAttr(setpgid bool) *syscall.SysProcAttr {
return &syscall.SysProcAttr{}
}

func sysCallKill(pid int) error {
return nil
}

0 comments on commit 580a696

Please sign in to comment.