cmdsetenv_others.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //go:build !windows
  15. // +build !windows
  16. package procutils
  17. import (
  18. "fmt"
  19. "os"
  20. "os/exec"
  21. "strings"
  22. "yunion.io/x/executor/client"
  23. )
  24. var (
  25. presetEnv = []string{
  26. "LANG=en_US.UTF8",
  27. }
  28. )
  29. func cmdSetEnv(cmd *exec.Cmd) {
  30. cmd.Env = append(
  31. os.Environ(),
  32. presetEnv...,
  33. )
  34. }
  35. var paths = []string{
  36. "/usr/bin",
  37. "/usr/sbin",
  38. "/usr/local/sbin",
  39. "/usr/local/bin",
  40. "/sbin",
  41. "/bin",
  42. "/opt/yunion/bin",
  43. }
  44. func remoteCmdSetEnv(cmd *client.Cmd) {
  45. envs := []string{
  46. fmt.Sprintf("PATH=%s", strings.Join(paths, ":")),
  47. }
  48. cmd.Env = append(envs, presetEnv...)
  49. }