4
0

executor_unix.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //go:build !windows
  2. // +build !windows
  3. package executor
  4. import (
  5. "context"
  6. "os/exec"
  7. "syscall"
  8. )
  9. func (e *Executor) Kill(execReq *InternalLogEntry) error {
  10. if execReq == nil {
  11. return nil
  12. }
  13. runExecToolHelperKillCommand(execReq.Attributes)
  14. if execReq.Process != nil {
  15. return syscall.Kill(-execReq.Process.Pid, syscall.SIGKILL)
  16. }
  17. return nil
  18. }
  19. func wrapCommandInShell(ctx context.Context, finalParsedCommand string) *exec.Cmd {
  20. cmd := exec.CommandContext(ctx, "sh", "-c", finalParsedCommand)
  21. // This is to ensure that the process group is killed when the parent process is killed.
  22. cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
  23. return cmd
  24. }
  25. func wrapCommandDirect(ctx context.Context, execArgs []string) *exec.Cmd {
  26. if len(execArgs) == 0 {
  27. return nil
  28. }
  29. cmd := exec.CommandContext(ctx, execArgs[0], execArgs[1:]...)
  30. // This is to ensure that the process group is killed when the parent process is killed.
  31. cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
  32. return cmd
  33. }
  34. func wrapCommandExecTool(ctx context.Context, name string) *exec.Cmd {
  35. cmd := exec.CommandContext(ctx, "olivetin-"+name, "exec")
  36. cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
  37. return cmd
  38. }