diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2018-10-03 07:03:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-03 07:03:16 -0700 |
commit | 230edff5216d0a7cedeff06c891450f8691b5aa2 (patch) | |
tree | 56147c11769b5586a6a2afbf6357caf59d1b8318 /libpod/runtime.go | |
parent | a3c4ce6717cab56d968fbe1fff0ced19f45c23cb (diff) | |
parent | 2f73a9b0f6225819fb8bf53d103438ddf4421441 (diff) | |
download | podman-230edff5216d0a7cedeff06c891450f8691b5aa2.tar.gz podman-230edff5216d0a7cedeff06c891450f8691b5aa2.tar.bz2 podman-230edff5216d0a7cedeff06c891450f8691b5aa2.zip |
Merge pull request #1580 from giuseppe/rootless-always-set-XDG_RUNTIME_DIR
rootless: always set XDG_RUNTIME_DIR
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r-- | libpod/runtime.go | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go index 988c418f3..985af2849 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -261,6 +261,25 @@ func getDefaultTmpDir() (string, error) { return filepath.Join(rootlessRuntimeDir, "libpod", "tmp"), nil } +// SetXdgRuntimeDir ensures the XDG_RUNTIME_DIR env variable is set +// containers/image uses XDG_RUNTIME_DIR to locate the auth file. +func SetXdgRuntimeDir(val string) error { + if !rootless.IsRootless() { + return nil + } + if val == "" { + var err error + val, err = GetRootlessRuntimeDir() + if err != nil { + return err + } + } + if err := os.Setenv("XDG_RUNTIME_DIR", val); err != nil { + return errors.Wrapf(err, "cannot set XDG_RUNTIME_DIR") + } + return nil +} + // NewRuntime creates a new container runtime // Options can be passed to override the default configuration for the runtime func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) { @@ -297,7 +316,7 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) { // containers/image uses XDG_RUNTIME_DIR to locate the auth file. // So make sure the env variable is set. - err = os.Setenv("XDG_RUNTIME_DIR", runtimeDir) + err = SetXdgRuntimeDir(runtimeDir) if err != nil { return nil, errors.Wrapf(err, "cannot set XDG_RUNTIME_DIR") } |