From: Mike Yuan Date: Wed, 25 Feb 2026 08:23:50 +0000 (+0100) Subject: core/namespace: two fixes for namespace_cleanup_tmpdir() X-Git-Tag: v260-rc1~6^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e438e5923d60440b643560799e41ea3092ae5cbe;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/core/namespace.c b/src/core/namespace.c index aa80570885e..b97eabd51bf 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -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;