summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2020-07-31 13:52:14 -0400
committerMatthew Heon <matthew.heon@pm.me>2020-08-18 15:17:46 -0400
commita7e864e6e7de894d4edde4fff00e53dc6a0b5074 (patch)
tree9a6381d9ce5ce0045ffa07dcfea2d10c725ab50d
parentff1f81b14a2944a1651e1b404681972ff3483d36 (diff)
downloadpodman-a7e864e6e7de894d4edde4fff00e53dc6a0b5074.tar.gz
podman-a7e864e6e7de894d4edde4fff00e53dc6a0b5074.tar.bz2
podman-a7e864e6e7de894d4edde4fff00e53dc6a0b5074.zip
Ensure DefaultEnvVariables is used in Specgen
When we rewrote Podman's pkg/spec, one of the things that was lost was our use of a set of default environment variables, that ensure all containers have at least $PATH and $TERM set. While we're in the process of re-adding it, change it from a variable to a function, so we can ensure the Join function does not overwrite it and corrupt the defaults. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
-rw-r--r--pkg/env/env.go14
-rw-r--r--pkg/spec/spec.go4
2 files changed, 10 insertions, 8 deletions
diff --git a/pkg/env/env.go b/pkg/env/env.go
index a16007a50..0d55e5560 100644
--- a/pkg/env/env.go
+++ b/pkg/env/env.go
@@ -12,14 +12,16 @@ import (
"github.com/pkg/errors"
)
-// DefaultEnvVariables sets $PATH and $TERM.
-var DefaultEnvVariables = map[string]string{
- "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
- "TERM": "xterm",
-}
-
const whiteSpaces = " \t"
+// DefaultEnvVariables returns a default environment, with $PATH and $TERM set.
+func DefaultEnvVariables() map[string]string {
+ return map[string]string{
+ "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
+ "TERM": "xterm",
+ }
+}
+
// Slice transforms the specified map of environment variables into a
// slice. If a value is non-empty, the key and value are joined with '='.
func Slice(m map[string]string) []string {
diff --git a/pkg/spec/spec.go b/pkg/spec/spec.go
index c7a838d4c..893ae3cab 100644
--- a/pkg/spec/spec.go
+++ b/pkg/spec/spec.go
@@ -321,13 +321,13 @@ func (config *CreateConfig) createConfigToOCISpec(runtime *libpod.Runtime, userM
// config.
var defaultEnv map[string]string
if runtimeConfig == nil {
- defaultEnv = env.DefaultEnvVariables
+ defaultEnv = env.DefaultEnvVariables()
} else {
defaultEnv, err = env.ParseSlice(runtimeConfig.Containers.Env)
if err != nil {
return nil, errors.Wrap(err, "Env fields in containers.conf failed ot parse")
}
- defaultEnv = env.Join(env.DefaultEnvVariables, defaultEnv)
+ defaultEnv = env.Join(env.DefaultEnvVariables(), defaultEnv)
}
if err := addRlimits(config, &g); err != nil {