46 lines
697 B
Go
46 lines
697 B
Go
//go:build !windows
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"os/exec"
|
|
"sync"
|
|
"syscall"
|
|
)
|
|
|
|
func configureSidecarCmd(cmd *exec.Cmd) {
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
|
}
|
|
|
|
func configureDetachedVMProcess(cmd *exec.Cmd) {
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
|
}
|
|
|
|
type sidecarJob struct {
|
|
pgid int
|
|
closeOnce sync.Once
|
|
}
|
|
|
|
func newSidecarJob(_ uintptr) (*sidecarJob, error) {
|
|
return &sidecarJob{}, nil
|
|
}
|
|
|
|
func (j *sidecarJob) Assign(pid int) error {
|
|
if j != nil {
|
|
j.pgid = pid
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (j *sidecarJob) Close() {
|
|
if j == nil {
|
|
return
|
|
}
|
|
j.closeOnce.Do(func() {
|
|
if j.pgid > 0 {
|
|
_ = syscall.Kill(-j.pgid, syscall.SIGKILL)
|
|
j.pgid = 0
|
|
}
|
|
})
|
|
}
|