From 1377bcdf35a33941191e35fe613ac720f40c3919 Mon Sep 17 00:00:00 2001 From: Victor Castell <0x@vcastellm.xyz> Date: Sun, 4 Feb 2024 10:41:45 +0100 Subject: [PATCH] Fix windows build --- plugin/shell/shell.go | 4 +--- plugin/shell/shell_unix.go | 7 ++++++- plugin/shell/shell_windows.go | 5 +++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/plugin/shell/shell.go b/plugin/shell/shell.go index 5994959e9..1161be4bc 100644 --- a/plugin/shell/shell.go +++ b/plugin/shell/shell.go @@ -10,7 +10,6 @@ import ( "runtime" "strconv" "strings" - "syscall" "time" "github.com/armon/circbuf" @@ -103,7 +102,6 @@ func (s *Shell) ExecuteImpl(args *dktypes.ExecuteRequest, cb dkplugin.StatusHelp if err != nil { return nil, errors.New("shell: Error parsing job timeout") } - cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} } log.Printf("shell: going to run %s", command) @@ -119,7 +117,7 @@ func (s *Shell) ExecuteImpl(args *dktypes.ExecuteRequest, cb dkplugin.StatusHelp if jt != 0 { slowTimer := time.AfterFunc(jt, func() { // Kill child process to avoid cmd.Wait() - err := syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) // note the minus sign + err := processKill(cmd) if err != nil { jobTimeoutMessage = fmt.Sprintf("shell: Job '%s' execution time exceeding defined timeout %v. SIGKILL returned error. Job may not have been killed", command, jt) } else { diff --git a/plugin/shell/shell_unix.go b/plugin/shell/shell_unix.go index db11cc182..e51aa153b 100644 --- a/plugin/shell/shell_unix.go +++ b/plugin/shell/shell_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package shell @@ -29,7 +30,7 @@ func setCmdAttr(cmd *exec.Cmd, config map[string]string) error { } else { gid, _ = strconv.Atoi(u.Gid) } - cmd.SysProcAttr = &syscall.SysProcAttr{} + cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} cmd.SysProcAttr.Credential = &syscall.Credential{ Uid: uint32(uid), Gid: uint32(gid), @@ -37,3 +38,7 @@ func setCmdAttr(cmd *exec.Cmd, config map[string]string) error { } return nil } + +func processKill(cmd *exec.Cmd) error { + return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) // note the minus sign +} diff --git a/plugin/shell/shell_windows.go b/plugin/shell/shell_windows.go index 104dfbd16..cdc7c2f4e 100644 --- a/plugin/shell/shell_windows.go +++ b/plugin/shell/shell_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package shell @@ -9,3 +10,7 @@ import ( func setCmdAttr(cmd *exec.Cmd, config map[string]string) error { return nil } + +func processKill(cmd *exec.Cmd) error { + return cmd.Process.Kill() +}