Commit 565f5c8c authored by Michael Schurter's avatar Michael Schurter

Alter subprocess's environment instead of the hosts

Fixes #415
parent 3aa2ffab
......@@ -9,15 +9,24 @@ import (
)
func DoSysctrl(mib string) ([]string, error) {
err := os.Setenv("LC_ALL", "C")
if err != nil {
return []string{}, err
hostEnv := os.Environ()
foundLC := false
for i, line := range hostEnv {
if strings.HasPrefix(line, "LC_ALL") {
hostEnv[i] = "LC_ALL=C"
foundLC = true
}
}
if !foundLC {
hostEnv = append(hostEnv, "LC_ALL=C")
}
sysctl, err := exec.LookPath("/sbin/sysctl")
if err != nil {
return []string{}, err
}
out, err := exec.Command(sysctl, "-n", mib).Output()
cmd := exec.Command(sysctl, "-n", mib)
cmd.Env = hostEnv
out, err := cmd.Output()
if err != nil {
return []string{}, err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment