diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2020-10-31 07:53:58 -0400 |
---|---|---|
committer | Daniel J Walsh <dwalsh@redhat.com> | 2020-11-04 14:47:54 -0500 |
commit | 5a032acff6e6906cfb5533ec135f177b696d7154 (patch) | |
tree | aa8348ddefd55ee74d64aeac6b6b1affcaf08211 | |
parent | ab273a9cbd08e25e3794c606a863644eb3a06e30 (diff) | |
download | podman-5a032acff6e6906cfb5533ec135f177b696d7154.tar.gz podman-5a032acff6e6906cfb5533ec135f177b696d7154.tar.bz2 podman-5a032acff6e6906cfb5533ec135f177b696d7154.zip |
Only use container/storage/pkg/homedir.Get()
We are resolving the homedir of the user in many different
places. This Patch consolodates them to use container/storage
version.
This PR also fixes a failure mode when the homedir does not
exists, and the user sets a root path. In this situation
podman should continue to work. Podman does not require a users
homedir to exist in order to run.
Finally the rootlessConfigHomeDirOnce and rootlessRuntimeDirOnce
were broken, because if an error ever happened, they would not be recorded
the second time, and "" would be returned as the path.
Fixes: https://github.com/containers/podman/issues/8131
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
-rw-r--r-- | libpod/oci_conmon_exec_linux.go | 5 | ||||
-rw-r--r-- | libpod/oci_conmon_linux.go | 17 |
2 files changed, 8 insertions, 14 deletions
diff --git a/libpod/oci_conmon_exec_linux.go b/libpod/oci_conmon_exec_linux.go index 8651c1dc5..7068bf87a 100644 --- a/libpod/oci_conmon_exec_linux.go +++ b/libpod/oci_conmon_exec_linux.go @@ -444,10 +444,7 @@ func (r *ConmonOCIRuntime) startExec(c *Container, sessionID string, options *Ex // } // } - conmonEnv, extraFiles, err := r.configureConmonEnv(c, runtimeDir) - if err != nil { - return nil, nil, err - } + conmonEnv, extraFiles := r.configureConmonEnv(c, runtimeDir) var filesToClose []*os.File if options.PreserveFDs > 0 { diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go index 89d64537d..bd58610a2 100644 --- a/libpod/oci_conmon_linux.go +++ b/libpod/oci_conmon_linux.go @@ -32,6 +32,7 @@ import ( "github.com/containers/podman/v2/pkg/rootless" "github.com/containers/podman/v2/pkg/util" "github.com/containers/podman/v2/utils" + "github.com/containers/storage/pkg/homedir" pmount "github.com/containers/storage/pkg/mount" "github.com/coreos/go-systemd/v22/activation" "github.com/coreos/go-systemd/v22/daemon" @@ -1065,10 +1066,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co } // 0, 1 and 2 are stdin, stdout and stderr - conmonEnv, envFiles, err := r.configureConmonEnv(ctr, runtimeDir) - if err != nil { - return err - } + conmonEnv, envFiles := r.configureConmonEnv(ctr, runtimeDir) var filesToClose []*os.File if ctr.config.PreserveFDs > 0 { @@ -1268,16 +1266,15 @@ func prepareProcessExec(c *Container, cmd, env []string, tty bool, cwd, user, se // configureConmonEnv gets the environment values to add to conmon's exec struct // TODO this may want to be less hardcoded/more configurable in the future -func (r *ConmonOCIRuntime) configureConmonEnv(ctr *Container, runtimeDir string) ([]string, []*os.File, error) { +func (r *ConmonOCIRuntime) configureConmonEnv(ctr *Container, runtimeDir string) ([]string, []*os.File) { env := make([]string, 0, 6) env = append(env, fmt.Sprintf("XDG_RUNTIME_DIR=%s", runtimeDir)) env = append(env, fmt.Sprintf("_CONTAINERS_USERNS_CONFIGURED=%s", os.Getenv("_CONTAINERS_USERNS_CONFIGURED"))) env = append(env, fmt.Sprintf("_CONTAINERS_ROOTLESS_UID=%s", os.Getenv("_CONTAINERS_ROOTLESS_UID"))) - home, err := util.HomeDir() - if err != nil { - return nil, nil, err + home := homedir.Get() + if home != "" { + env = append(env, fmt.Sprintf("HOME=%s", home)) } - env = append(env, fmt.Sprintf("HOME=%s", home)) extraFiles := make([]*os.File, 0) if ctr.config.SdNotifyMode == define.SdNotifyModeContainer { @@ -1294,7 +1291,7 @@ func (r *ConmonOCIRuntime) configureConmonEnv(ctr *Container, runtimeDir string) } else { logrus.Debug("disabling SD notify") } - return env, extraFiles, nil + return env, extraFiles } // sharedConmonArgs takes common arguments for exec and create/restore and formats them for the conmon CLI |