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.
This commit is contained in:
Michal Sekletar
2013-03-15 22:56:40 -04:00
committed by Zbigniew Jędrzejewski-Szmek
parent 3b953d68c6
commit c17ec25e4d
15 changed files with 307 additions and 155 deletions
+44
View File
@@ -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;
}
+1
View File
@@ -574,6 +574,7 @@ int on_ac_power(void);
int search_and_fopen(const char *path, const char *mode, const char **search, FILE **_f);
int search_and_fopen_nulstr(const char *path, const char *mode, const char *search, FILE **_f);
int create_tmp_dir(char template[], mode_t mask, bool need_sticky, char** dir_name);
#define FOREACH_LINE(line, f, on_error) \
for (;;) \