eea2bd2753
* Kill check processes after the timeout is reached Kill the subprocess spawned by a script check once the timeout is reached. Previously Consul just marked the check critical and left the subprocess around. Fixes #3565. * Set err to non-nil when timeout occurs * Fix check timeout test * Kill entire process subtree on check timeout * Add a docs note about windows subprocess termination
31 lines
580 B
Go
31 lines
580 B
Go
// +build windows
|
|
|
|
package agent
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"syscall"
|
|
)
|
|
|
|
// ExecScript returns a command to execute a script through a shell.
|
|
func ExecScript(script string) (*exec.Cmd, error) {
|
|
shell := "cmd"
|
|
if other := os.Getenv("SHELL"); other != "" {
|
|
shell = other
|
|
}
|
|
script = "\"" + script + "\""
|
|
cmd := exec.Command(shell, "/C", script)
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
CmdLine: strings.Join(cmd.Args, " "),
|
|
}
|
|
return cmd, nil
|
|
}
|
|
|
|
func SetSysProcAttr(cmd *exec.Cmd) {}
|
|
|
|
func KillCommandSubtree(cmd *exec.Cmd) error {
|
|
return cmd.Process.Kill()
|
|
}
|