mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
exec: set HOME also with exec sessions
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -200,13 +200,16 @@ func prepareProcessExec(c *Container, cmd, env []string, tty bool, cwd, user, se
|
|||||||
pspec.Cwd = cwd
|
pspec.Cwd = cwd
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
overrides := c.getUserOverrides()
|
||||||
|
execUser, err := lookup.GetUserGroupInfo(c.state.Mountpoint, user, overrides)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// If user was set, look it up in the container to get a UID to use on
|
// If user was set, look it up in the container to get a UID to use on
|
||||||
// the host
|
// the host
|
||||||
if user != "" {
|
if user != "" {
|
||||||
execUser, err := lookup.GetUserGroupInfo(c.state.Mountpoint, user, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
sgids := make([]uint32, 0, len(execUser.Sgids))
|
sgids := make([]uint32, 0, len(execUser.Sgids))
|
||||||
for _, sgid := range execUser.Sgids {
|
for _, sgid := range execUser.Sgids {
|
||||||
sgids = append(sgids, uint32(sgid))
|
sgids = append(sgids, uint32(sgid))
|
||||||
@ -220,6 +223,17 @@ func prepareProcessExec(c *Container, cmd, env []string, tty bool, cwd, user, se
|
|||||||
pspec.User = processUser
|
pspec.User = processUser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasHomeSet := false
|
||||||
|
for _, s := range pspec.Env {
|
||||||
|
if strings.HasPrefix(s, "HOME=") {
|
||||||
|
hasHomeSet = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !hasHomeSet {
|
||||||
|
pspec.Env = append(pspec.Env, fmt.Sprintf("HOME=%s", execUser.Home))
|
||||||
|
}
|
||||||
|
|
||||||
processJSON, err := json.Marshal(pspec)
|
processJSON, err := json.Marshal(pspec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Reference in New Issue
Block a user