summaryrefslogtreecommitdiff
path: root/pkg/util/utils_supported.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-08-06 17:42:54 +0200
committerGitHub <noreply@github.com>2019-08-06 17:42:54 +0200
commit37b40e9acdae6bfa79d53928361540754417cdc6 (patch)
tree77a8f189ed503f5c75efa27a4702ea8b4e004bb0 /pkg/util/utils_supported.go
parent3bffe77f824772b841080ea463324f5ae5c833d4 (diff)
parent5779e898090b7182ad9307e3ddf1087ac913c770 (diff)
downloadpodman-37b40e9acdae6bfa79d53928361540754417cdc6.tar.gz
podman-37b40e9acdae6bfa79d53928361540754417cdc6.tar.bz2
podman-37b40e9acdae6bfa79d53928361540754417cdc6.zip
Merge pull request #3466 from TomSweeneyRedHat/dev/tsweeney/myhome
Touch up XDG, add rootless links
Diffstat (limited to 'pkg/util/utils_supported.go')
-rw-r--r--pkg/util/utils_supported.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/pkg/util/utils_supported.go b/pkg/util/utils_supported.go
index 6449c6f85..c7c8787a0 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) {