Skip to content

Commit

Permalink
Fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
vcastellm committed Feb 4, 2024
1 parent 7ee3ab6 commit 1377bcd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 1 addition & 3 deletions plugin/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"runtime"
"strconv"
"strings"
"syscall"
"time"

"github.com/armon/circbuf"
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion plugin/shell/shell_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package shell
Expand Down Expand Up @@ -29,11 +30,15 @@ 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),
}
}
return nil
}

func processKill(cmd *exec.Cmd) error {
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) // note the minus sign
}
5 changes: 5 additions & 0 deletions plugin/shell/shell_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

package shell
Expand All @@ -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()
}

0 comments on commit 1377bcd

Please sign in to comment.