summaryrefslogtreecommitdiff
path: root/libpod/runtime.go
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2019-03-29 11:23:42 +0100
committerGiuseppe Scrivano <gscrivan@redhat.com>2019-03-29 12:01:12 +0100
commit2fa9861d788d821b6089becf3f3833b79d08d443 (patch)
tree0215a5f0e3d098d5c6952154304851a5e9f12c76 /libpod/runtime.go
parentd8caa2f2fa006b61737d68600808c7ff10b21ece (diff)
downloadpodman-2fa9861d788d821b6089becf3f3833b79d08d443.tar.gz
podman-2fa9861d788d821b6089becf3f3833b79d08d443.tar.bz2
podman-2fa9861d788d821b6089becf3f3833b79d08d443.zip
rootless: set sticky bit on rundir
it prevents the directory to be auto pruned, according to the XDG specifications. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r--libpod/runtime.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go
index f7b166513..6e54de558 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -309,7 +309,17 @@ func getDefaultTmpDir() (string, error) {
if err != nil {
return "", err
}
- return filepath.Join(rootlessRuntimeDir, "libpod", "tmp"), nil
+ libpodRuntimeDir := filepath.Join(rootlessRuntimeDir, "libpod")
+
+ if err := os.Mkdir(libpodRuntimeDir, 0700|os.ModeSticky); err != nil {
+ if !os.IsExist(err) {
+ return "", errors.Wrapf(err, "cannot mkdir %s", libpodRuntimeDir)
+ } else if err := os.Chmod(libpodRuntimeDir, 0700|os.ModeSticky); err != nil {
+ // The directory already exist, just set the sticky bit
+ return "", errors.Wrapf(err, "could not set sticky bit on %s", libpodRuntimeDir)
+ }
+ }
+ return filepath.Join(libpodRuntimeDir, "tmp"), nil
}
// SetXdgRuntimeDir ensures the XDG_RUNTIME_DIR env variable is set