summaryrefslogtreecommitdiff
path: root/libpod/runtime.go
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2018-10-03 10:41:47 +0200
committerGiuseppe Scrivano <gscrivan@redhat.com>2018-10-03 10:41:47 +0200
commit2f73a9b0f6225819fb8bf53d103438ddf4421441 (patch)
tree60fe25f1728dd90cd6fceec3a9a7a16bb3106865 /libpod/runtime.go
parentd5687946f6a0aa14a5326f26ca0ceca68588056f (diff)
downloadpodman-2f73a9b0f6225819fb8bf53d103438ddf4421441.tar.gz
podman-2f73a9b0f6225819fb8bf53d103438ddf4421441.tar.bz2
podman-2f73a9b0f6225819fb8bf53d103438ddf4421441.zip
rootless: always set XDG_RUNTIME_DIR
it is used internally by containers/image to locate the auth file. Closes: https://github.com/containers/libpod/issues/1457 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r--libpod/runtime.go21
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")
}