From 565f5c8c5e5f8cf2f8a92cf9375f2f1c0e3ea034 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Wed, 16 Aug 2017 14:54:50 -0700 Subject: [PATCH] Alter subprocess's environment instead of the hosts Fixes #415 --- internal/common/common_linux.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index c0aa9c7..5347b60 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -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 }