2023-09-25 16:47:17 -05:00
|
|
|
//go:build !windows
|
|
|
|
|
|
|
|
|
|
package agentscripts
|
|
|
|
|
|
|
|
|
|
import (
|
2025-01-29 13:37:43 +00:00
|
|
|
"context"
|
2023-09-25 16:47:17 -05:00
|
|
|
"os/exec"
|
|
|
|
|
"syscall"
|
2025-01-29 13:37:43 +00:00
|
|
|
|
2026-01-08 10:29:41 +04:00
|
|
|
"cdr.dev/slog/v3"
|
2023-09-25 16:47:17 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func cmdSysProcAttr() *syscall.SysProcAttr {
|
|
|
|
|
return &syscall.SysProcAttr{
|
|
|
|
|
Setsid: true,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-29 13:37:43 +00:00
|
|
|
func cmdCancel(ctx context.Context, logger slog.Logger, cmd *exec.Cmd) func() error {
|
2023-09-25 16:47:17 -05:00
|
|
|
return func() error {
|
2025-01-29 13:37:43 +00:00
|
|
|
logger.Debug(ctx, "cmdCancel: sending SIGHUP to process and children", slog.F("pid", cmd.Process.Pid))
|
2023-09-25 16:47:17 -05:00
|
|
|
return syscall.Kill(-cmd.Process.Pid, syscall.SIGHUP)
|
|
|
|
|
}
|
|
|
|
|
}
|