dd0e8eec14
* copyright headers for agent folder * Ignore test data files * fix proto files and remove headers in agent/uiserver folder * ignore deep-copy files
32 lines
685 B
Go
32 lines
685 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
//go:build !windows
|
|
// +build !windows
|
|
|
|
package exec
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"syscall"
|
|
)
|
|
|
|
// Script returns a command to execute a script through a shell.
|
|
func Script(script string) (*exec.Cmd, error) {
|
|
shell := "/bin/sh"
|
|
if other := os.Getenv("SHELL"); other != "" {
|
|
shell = other
|
|
}
|
|
return exec.Command(shell, "-c", script), nil
|
|
}
|
|
|
|
func SetSysProcAttr(cmd *exec.Cmd) {
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
|
}
|
|
|
|
// KillCommandSubtree kills the command process and any child processes
|
|
func KillCommandSubtree(cmd *exec.Cmd) error {
|
|
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
|
}
|