mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-12 09:05:39 +00:00
* bugfix: Kill the process group, not just the parent process (#328), thanks @ioqy, @vvrein * bugfix: Kill the process group, not just the parent process (#328), thanks @ioqy, @vvrein * bugfix: Kill the process group, not just the parent process (#328), thanks @ioqy, @vvrein
This commit is contained in:
25
internal/executor/executor_unix.go
Normal file
25
internal/executor/executor_unix.go
Normal file
@@ -0,0 +1,25 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package executor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func (e *Executor) Kill(execReq *InternalLogEntry) error {
|
||||
// A negative PID means to kill the whole process group. This is *nix specific behavior.
|
||||
return syscall.Kill(-execReq.Process.Pid, syscall.SIGKILL)
|
||||
}
|
||||
|
||||
func wrapCommandInShell(ctx context.Context, finalParsedCommand string) *exec.Cmd {
|
||||
cmd := exec.CommandContext(ctx, "sh", "-c", finalParsedCommand)
|
||||
|
||||
// This is to ensure that the process group is killed when the parent process is killed.
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
|
||||
return cmd
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user