Make container env variable conditional

Add only when it's not already present.

Add a more specific version in podman spec generation
so we get 'container=podman' not 'container=libpod'

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #540
Approved by: baude
This commit is contained in:
Matthew Heon 2018-03-23 11:22:48 -04:00 committed by Atomic Bot
parent f7c8dd5836
commit 3f5da4d0dd
2 changed files with 13 additions and 1 deletions

View File

@ -195,6 +195,7 @@ func createConfigToOCISpec(config *createConfig) (*spec.Spec, error) {
for sysctlKey, sysctlVal := range config.Sysctl {
g.AddLinuxSysctl(sysctlKey, sysctlVal)
}
g.AddProcessEnv("container", "podman")
// RESOURCES - MEMORY
if config.Resources.Memory != 0 {

View File

@ -909,7 +909,18 @@ func (c *Container) generateSpec() (*spec.Spec, error) {
g.SetHostname(c.Hostname())
g.AddProcessEnv("HOSTNAME", g.Spec().Hostname)
g.AddProcessEnv("container", "libpod")
// Only add container environment variable if not already present
foundContainerEnv := false
for _, env := range g.Spec().Process.Env {
if strings.HasPrefix(env, "container=") {
foundContainerEnv = true
break
}
}
if !foundContainerEnv {
g.AddProcessEnv("container", "libpod")
}
return g.Spec(), nil
}