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>
This commit is contained in:
Giuseppe Scrivano 2019-03-29 11:23:42 +01:00
parent d8caa2f2fa
commit 2fa9861d78
No known key found for this signature in database
GPG Key ID: E4730F97F60286ED
1 changed files with 11 additions and 1 deletions

View File

@ -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