]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/namespace: two fixes for namespace_cleanup_tmpdir()
authorMike Yuan <me@yhndnzj.com>
Wed, 25 Feb 2026 08:23:50 +0000 (09:23 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 25 Feb 2026 11:38:11 +0000 (12:38 +0100)
* 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.

src/core/namespace.c

index aa80570885e156b16810acb27f702ab793e491ef..b97eabd51bf5ab62e51e316c60a413447b8623a0 100644 (file)
@@ -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;