From 580a6960fcb0d0a8d85e5676b44ece5b5e9a866f Mon Sep 17 00:00:00 2001 From: Alexander Matyushentsev Date: Sun, 30 Jan 2022 13:01:13 -0800 Subject: [PATCH] fix: argocd build fails on windows (#8319) Signed-off-by: Alexander Matyushentsev --- cmpserver/plugin/plugin.go | 5 ++--- cmpserver/plugin/plugin_unix.go | 16 ++++++++++++++++ cmpserver/plugin/plugin_windows.go | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 cmpserver/plugin/plugin_unix.go create mode 100644 cmpserver/plugin/plugin_windows.go diff --git a/cmpserver/plugin/plugin.go b/cmpserver/plugin/plugin.go index 99f1727927247..2f150bd532939 100644 --- a/cmpserver/plugin/plugin.go +++ b/cmpserver/plugin/plugin.go @@ -9,7 +9,6 @@ import ( "os/exec" "path/filepath" "strings" - "syscall" "time" "github.com/argoproj/pkg/rand" @@ -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() @@ -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() diff --git a/cmpserver/plugin/plugin_unix.go b/cmpserver/plugin/plugin_unix.go new file mode 100644 index 0000000000000..a9dc157bc7ef8 --- /dev/null +++ b/cmpserver/plugin/plugin_unix.go @@ -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) +} diff --git a/cmpserver/plugin/plugin_windows.go b/cmpserver/plugin/plugin_windows.go new file mode 100644 index 0000000000000..2a188e61f6f9e --- /dev/null +++ b/cmpserver/plugin/plugin_windows.go @@ -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 +}