]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: mount namespaces: Remove auxiliary bind mounts directory after unit termination
authorMichal Koutný <mkoutny@suse.com>
Wed, 18 Jan 2023 22:20:31 +0000 (23:20 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 19 Jan 2023 20:58:10 +0000 (21:58 +0100)
Unit that requires its own mount namespace creates a temporary directory
to implement dynamic bind mounts (org.freedesktop.systemd1.Manager.BindMountUnit).
However, this directory is never removed and they will accumulate for
each unique unit (e.g. templated units of systemd-coredump@).

Attach the auxiliary runtime directory existence to lifetime of other
"runtime" only per-unit directories.

src/core/execute.c
src/core/execute.h
src/core/unit.c

index 4c440895c19ecf961016a19bdc9f5255edfb6fc4..221da31065950a4cd59be340e8b75cf6a6ebaffe 100644 (file)
@@ -5626,6 +5626,23 @@ int exec_context_destroy_credentials(const ExecContext *c, const char *runtime_p
         return 0;
 }
 
+int exec_context_destroy_mount_ns_dir(Unit *u) {
+        _cleanup_free_ char *p = NULL;
+
+        if (!u || !MANAGER_IS_SYSTEM(u->manager))
+                return 0;
+
+        p = path_join("/run/systemd/propagate/", u->id);
+        if (!p)
+                return -ENOMEM;
+
+        /* This is only filled transiently (see mount_in_namespace()), should be empty or even non-existent*/
+        if (rmdir(p) < 0 && errno != ENOENT)
+                log_unit_debug_errno(u, errno, "Unable to remove propagation dir '%s', ignoring: %m", p);
+
+        return 0;
+}
+
 static void exec_command_done(ExecCommand *c) {
         assert(c);
 
index 62ad6d2eb2aacf453420762843944b89ce860f7a..325f340862c59aa790952bb0676595eb4811fead 100644 (file)
@@ -459,6 +459,7 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix);
 
 int exec_context_destroy_runtime_directory(const ExecContext *c, const char *runtime_root);
 int exec_context_destroy_credentials(const ExecContext *c, const char *runtime_root, const char *unit);
+int exec_context_destroy_mount_ns_dir(Unit *u);
 
 const char* exec_context_fdname(const ExecContext *c, int fd_index);
 
index 0e66cae4341ee5293f96f5ca909fbb5b5143fd21..166246901244365730298a0b858ecbf715c7aefc 100644 (file)
@@ -5765,6 +5765,7 @@ void unit_destroy_runtime_data(Unit *u, const ExecContext *context) {
                 exec_context_destroy_runtime_directory(context, u->manager->prefix[EXEC_DIRECTORY_RUNTIME]);
 
         exec_context_destroy_credentials(context, u->manager->prefix[EXEC_DIRECTORY_RUNTIME], u->id);
+        exec_context_destroy_mount_ns_dir(u);
 }
 
 int unit_clean(Unit *u, ExecCleanMask mask) {