diff options
author | TomSweeneyRedHat <tsweeney@redhat.com> | 2019-07-01 14:35:13 -0400 |
---|---|---|
committer | TomSweeneyRedHat <tsweeney@redhat.com> | 2019-07-29 11:29:41 -0400 |
commit | 5779e898090b7182ad9307e3ddf1087ac913c770 (patch) | |
tree | 6d299bd2db2c339297edddc479a1be19a59de8a6 /pkg/util/utils_supported.go | |
parent | 6665269ab8bd413799df6568a83a3ac679c93ad1 (diff) | |
download | podman-5779e898090b7182ad9307e3ddf1087ac913c770.tar.gz podman-5779e898090b7182ad9307e3ddf1087ac913c770.tar.bz2 podman-5779e898090b7182ad9307e3ddf1087ac913c770.zip |
Touch up XDG, add rootless links
Touch up a number of formating issues for XDG_RUNTIME_DIRS in a number
of man pages. Make use of the XDG_CONFIG_HOME environment variable
in a rootless environment if available, or set it if not.
Also added a number of links to the Rootless Podman config page and
added the location of the auth.json files to that doc.
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
Diffstat (limited to 'pkg/util/utils_supported.go')
-rw-r--r-- | pkg/util/utils_supported.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/pkg/util/utils_supported.go b/pkg/util/utils_supported.go index af55689a6..3eac58dc6 100644 --- a/pkg/util/utils_supported.go +++ b/pkg/util/utils_supported.go @@ -65,6 +65,38 @@ func GetRootlessRuntimeDir() (string, error) { return rootlessRuntimeDir, nil } +// GetRootlessConfigHomeDir returns the config home directory when running as non root +func GetRootlessConfigHomeDir() (string, error) { + var rootlessConfigHomeDirError error + + rootlessConfigHomeDirOnce.Do(func() { + cfgHomeDir := os.Getenv("XDG_CONFIG_HOME") + if cfgHomeDir == "" { + home := os.Getenv("HOME") + resolvedHome, err := filepath.EvalSymlinks(home) + if err != nil { + rootlessConfigHomeDirError = errors.Wrapf(err, "cannot resolve %s", home) + return + } + tmpDir := filepath.Join(resolvedHome, ".config") + if err := os.MkdirAll(tmpDir, 0755); err != nil { + logrus.Errorf("unable to make temp dir %s", tmpDir) + } + st, err := os.Stat(tmpDir) + if err == nil && int(st.Sys().(*syscall.Stat_t).Uid) == os.Geteuid() && st.Mode().Perm() == 0755 { + cfgHomeDir = tmpDir + } + } + rootlessConfigHomeDir = cfgHomeDir + }) + + if rootlessConfigHomeDirError != nil { + return "", rootlessConfigHomeDirError + } + + return rootlessConfigHomeDir, nil +} + // GetRootlessPauseProcessPidPath returns the path to the file that holds the pid for // the pause process func GetRootlessPauseProcessPidPath() (string, error) { |