diff --git a/CHANGELOG.md b/CHANGELOG.md index c365666b82..0dc7551ce6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ BUG FIXES: * agent: Clean up temporary files during disk write errors when persisting services and checks. [GH-3207] * agent: Fixed an issue where dns and client bind address templates were not being parsed via the go-sockaddr library. [GH-3322] * agent: Fixed status code on all KV store operations that fail due to an ACL issue. They now return a 403 status code, rather than a 404. [GH-2637] +* agent: Fixed quoting issues in script health check on windows. [GH-1875] ## 0.9.0 (July 20, 2017) diff --git a/agent/util.go b/agent/util.go index 538effba00..3739b00002 100644 --- a/agent/util.go +++ b/agent/util.go @@ -6,9 +6,7 @@ import ( "fmt" "math" "os" - "os/exec" "os/user" - "runtime" "strconv" "time" @@ -45,23 +43,6 @@ func aeScale(interval time.Duration, n int) time.Duration { return time.Duration(multiplier) * interval } -// ExecScript returns a command to execute a script -func ExecScript(script string) (*exec.Cmd, error) { - var shell, flag string - if runtime.GOOS == "windows" { - shell = "cmd" - flag = "/C" - } else { - shell = "/bin/sh" - flag = "-c" - } - if other := os.Getenv("SHELL"); other != "" { - shell = other - } - cmd := exec.Command(shell, flag, script) - return cmd, nil -} - // decodeMsgPack is used to decode a MsgPack encoded object func decodeMsgPack(buf []byte, out interface{}) error { return codec.NewDecoder(bytes.NewReader(buf), msgpackHandle).Decode(out) diff --git a/agent/util_other.go b/agent/util_other.go new file mode 100644 index 0000000000..47e3e1e67d --- /dev/null +++ b/agent/util_other.go @@ -0,0 +1,18 @@ +// +build !windows + +package agent + +import ( + "os" + "os/exec" +) + + +// ExecScript returns a command to execute a script +func ExecScript(script string) (*exec.Cmd, error) { + shell := "/bin/sh" + if other := os.Getenv("SHELL"); other != "" { + shell = other + } + return exec.Command(shell, "-c", script), nil +} diff --git a/agent/util_windows.go b/agent/util_windows.go new file mode 100644 index 0000000000..da280d37dc --- /dev/null +++ b/agent/util_windows.go @@ -0,0 +1,24 @@ +// +build windows + +package agent + +import ( + "os" + "os/exec" + "strings" + "syscall" +) + +// ExecScript returns a command to execute a script +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 +}