diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2018-10-22 09:43:03 -0400 |
---|---|---|
committer | Daniel J Walsh <dwalsh@redhat.com> | 2018-10-22 09:43:59 -0400 |
commit | 2444ac9926c651010a60a11eb372cca0ac7cc0e8 (patch) | |
tree | 51ce4dffa6d85261451a23a9185a900a4487a2f5 /libpod/runtime.go | |
parent | 0fefe3b191444cba8694119b5c30f484d146e162 (diff) | |
download | podman-2444ac9926c651010a60a11eb372cca0ac7cc0e8.tar.gz podman-2444ac9926c651010a60a11eb372cca0ac7cc0e8.tar.bz2 podman-2444ac9926c651010a60a11eb372cca0ac7cc0e8.zip |
Move rootless directory handling to the libpod/pkg/util directory
This should allow us to share this code with buildah.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r-- | libpod/runtime.go | 43 |
1 files changed, 4 insertions, 39 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go index 985af2849..f012d66c2 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -1,13 +1,11 @@ package libpod import ( - "fmt" "io/ioutil" "os" "os/exec" "path/filepath" "sync" - "syscall" "github.com/BurntSushi/toml" is "github.com/containers/image/storage" @@ -17,6 +15,7 @@ import ( "github.com/containers/libpod/pkg/hooks" sysreg "github.com/containers/libpod/pkg/registries" "github.com/containers/libpod/pkg/rootless" + "github.com/containers/libpod/pkg/util" "github.com/containers/storage" "github.com/cri-o/ocicni/pkg/ocicni" "github.com/docker/docker/pkg/namesgenerator" @@ -215,46 +214,12 @@ var ( } ) -// GetRootlessRuntimeDir returns the runtime directory when running as non root -func GetRootlessRuntimeDir() (string, error) { - runtimeDir := os.Getenv("XDG_RUNTIME_DIR") - uid := fmt.Sprintf("%d", rootless.GetRootlessUID()) - if runtimeDir == "" { - tmpDir := filepath.Join("/run", "user", uid) - os.MkdirAll(tmpDir, 0700) - st, err := os.Stat(tmpDir) - if err == nil && int(st.Sys().(*syscall.Stat_t).Uid) == os.Getuid() && st.Mode().Perm() == 0700 { - runtimeDir = tmpDir - } - } - if runtimeDir == "" { - tmpDir := filepath.Join(os.TempDir(), "user", uid) - os.MkdirAll(tmpDir, 0700) - st, err := os.Stat(tmpDir) - if err == nil && int(st.Sys().(*syscall.Stat_t).Uid) == os.Getuid() && st.Mode().Perm() == 0700 { - runtimeDir = tmpDir - } - } - if runtimeDir == "" { - home := os.Getenv("HOME") - if home == "" { - return "", fmt.Errorf("neither XDG_RUNTIME_DIR nor HOME was set non-empty") - } - resolvedHome, err := filepath.EvalSymlinks(home) - if err != nil { - return "", errors.Wrapf(err, "cannot resolve %s", home) - } - runtimeDir = filepath.Join(resolvedHome, "rundir") - } - return runtimeDir, nil -} - func getDefaultTmpDir() (string, error) { if !rootless.IsRootless() { return "/var/run/libpod", nil } - rootlessRuntimeDir, err := GetRootlessRuntimeDir() + rootlessRuntimeDir, err := util.GetRootlessRuntimeDir() if err != nil { return "", err } @@ -269,7 +234,7 @@ func SetXdgRuntimeDir(val string) error { } if val == "" { var err error - val, err = GetRootlessRuntimeDir() + val, err = util.GetRootlessRuntimeDir() if err != nil { return err } @@ -309,7 +274,7 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) { foundConfig = false } - runtimeDir, err := GetRootlessRuntimeDir() + runtimeDir, err := util.GetRootlessRuntimeDir() if err != nil { return nil, err } |