mirror of https://github.com/containers/podman.git
Merge pull request #4068 from giuseppe/always-set-home
container: make sure $HOME is always set
This commit is contained in:
commit
819b63c8de
|
@ -279,6 +279,17 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
|
|||
}
|
||||
}
|
||||
|
||||
hasHomeSet := false
|
||||
for _, s := range c.config.Spec.Process.Env {
|
||||
if strings.HasPrefix(s, "HOME=") {
|
||||
hasHomeSet = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasHomeSet {
|
||||
c.config.Spec.Process.Env = append(c.config.Spec.Process.Env, fmt.Sprintf("HOME=%s", execUser.Home))
|
||||
}
|
||||
|
||||
if c.config.User != "" {
|
||||
// User and Group must go together
|
||||
g.SetProcessUID(uint32(execUser.Uid))
|
||||
|
|
|
@ -194,10 +194,22 @@ var _ = Describe("Podman run", func() {
|
|||
})
|
||||
|
||||
It("podman run environment test", func() {
|
||||
session := podmanTest.Podman([]string{"run", "--rm", "--env", "FOO=BAR,BAZ", ALPINE, "printenv", "FOO"})
|
||||
session := podmanTest.Podman([]string{"run", "--rm", ALPINE, "printenv", "HOME"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
match, _ := session.GrepString("BAR,BAZ")
|
||||
match, _ := session.GrepString("/root")
|
||||
Expect(match).Should(BeTrue())
|
||||
|
||||
session = podmanTest.Podman([]string{"run", "--rm", "--env", "HOME=/foo", ALPINE, "printenv", "HOME"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
match, _ = session.GrepString("/foo")
|
||||
Expect(match).Should(BeTrue())
|
||||
|
||||
session = podmanTest.Podman([]string{"run", "--rm", "--env", "FOO=BAR,BAZ", ALPINE, "printenv", "FOO"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
match, _ = session.GrepString("BAR,BAZ")
|
||||
Expect(match).Should(BeTrue())
|
||||
|
||||
session = podmanTest.Podman([]string{"run", "--rm", "--env", "PATH=/bin", ALPINE, "printenv", "PATH"})
|
||||
|
|
Loading…
Reference in New Issue