core/namespace: two fixes for namespace_cleanup_tmpdir()
* Make sure we're not passing NULL to rmdir() * Remove the inner "tmp" subdir as well, so that callers can handle this transparently (e.g. exec_shared_runtime_make() is not aware of the nested rmdir() requirements) While at it, remove unneeded PROTECT_ERRNO.
This commit is contained in:
+17
-7
@@ -3333,6 +3333,23 @@ int temporary_filesystem_add(
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* namespace_cleanup_tmpdir(char *p) {
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
if (!streq(p, RUN_SYSTEMD_EMPTY)) {
|
||||
_cleanup_free_ char *child = path_join(p, "tmp");
|
||||
if (!child)
|
||||
log_oom_debug();
|
||||
else
|
||||
(void) rmdir(child);
|
||||
|
||||
(void) rmdir(p);
|
||||
}
|
||||
|
||||
return mfree(p);
|
||||
}
|
||||
|
||||
static int make_tmp_prefix(const char *prefix) {
|
||||
_cleanup_free_ char *t = NULL;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
@@ -3444,13 +3461,6 @@ static int setup_one_tmp_dir(const char *id, const char *prefix, char **path, ch
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* namespace_cleanup_tmpdir(char *p) {
|
||||
PROTECT_ERRNO;
|
||||
if (!streq_ptr(p, RUN_SYSTEMD_EMPTY))
|
||||
(void) rmdir(p);
|
||||
return mfree(p);
|
||||
}
|
||||
|
||||
int setup_tmp_dirs(const char *id, char **tmp_dir, char **var_tmp_dir) {
|
||||
_cleanup_(namespace_cleanup_tmpdirp) char *a = NULL;
|
||||
_cleanup_(rmdir_and_freep) char *a_tmp = NULL;
|
||||
|
||||
Reference in New Issue
Block a user