diff options
author | Michal Sekletar <msekleta@redhat.com> | 2013-03-14 18:12:27 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-03-15 22:56:40 -0400 |
commit | c17ec25e4d9bd6c8e8617416f813e25b2ebbafc5 (patch) | |
tree | 6a414a30460e6a362180a059bc93e88cea946916 /src/shared/util.c | |
parent | 3b953d68c628c6ae70adba871719ac0f16083b51 (diff) |
core: reuse the same /tmp, /var/tmp and inaccessible dir
All Execs within the service, will get mounted the same
/tmp and /var/tmp directories, if service is configured with
PrivateTmp=yes. Temporary directories are cleaned up by service
itself in addition to systemd-tmpfiles. Directory which is mounted
as inaccessible is created at runtime in /run/systemd.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r-- | src/shared/util.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index dc2651f3f2..34c5330838 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -5682,3 +5682,47 @@ int search_and_fopen_nulstr(const char *path, const char *mode, const char *sear return search_and_fopen_internal(path, mode, s, _f); } + +int create_tmp_dir(char template[], mode_t mask, bool need_sticky, char** dir_name) { + int r = 0; + char *d = NULL; + bool remove = false; + mode_t _cleanup_umask_ u; + + assert(dir_name); + + u = umask(mask); + d = mkdtemp(template); + if (!d) { + r = -errno; + log_debug("Can't create directory"); + goto fail; + } + + remove = true; + + log_debug("Created temporary directory : %s", template); + + d = strdup(template); + if (!d) { + r = log_oom(); + goto fail; + } + + if (need_sticky) { + r = chmod(template, 0777 | S_ISVTX); + if (r < 0) { + r = -errno; + goto fail; + } + log_debug("Setting sticky bit on : %s", template); + } + + *dir_name = d; + + return 0; +fail: + if (remove) + rmdir(template); + return r; +} |