summaryrefslogtreecommitdiff
path: root/src/systemctl/systemctl-mount.c
diff options
context:
space:
mode:
authorLuca Boccassi <luca.boccassi@microsoft.com>2020-07-30 19:37:10 +0100
committerLuca Boccassi <luca.boccassi@microsoft.com>2021-01-18 17:24:05 +0000
commit5e8deb94c6f05137942b10b5288a37d9b09fd43f (patch)
tree1cbed6e76c6398d4c183a6b71e0a9927386833d8 /src/systemctl/systemctl-mount.c
parent94293d65cd4125347e21b3e423d0e245226b1be2 (diff)
downloadsystemd-5e8deb94c6f05137942b10b5288a37d9b09fd43f.tar.gz
core: add DBUS method to bind mount new nodes without service restart
Allow to setup new bind mounts for a service at runtime (via either DBUS or a new 'systemctl bind' verb) with a new helper that forks into the unit's mount namespace. Add a new integration test to cover this. Useful for zero-downtime addition to services that are running inside mount namespaces, especially when using RootImage/RootDirectory. If a service runs with a read-only root, a tmpfs is added on /run to ensure we can create the airlock directory for incoming mounts under /run/host/incoming.
Diffstat (limited to 'src/systemctl/systemctl-mount.c')
-rw-r--r--src/systemctl/systemctl-mount.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/systemctl/systemctl-mount.c b/src/systemctl/systemctl-mount.c
new file mode 100644
index 0000000000..513a876f21
--- /dev/null
+++ b/src/systemctl/systemctl-mount.c
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "bus-error.h"
+#include "bus-locator.h"
+#include "systemctl-mount.h"
+#include "systemctl-util.h"
+#include "systemctl.h"
+
+int mount_bind(int argc, char *argv[], void *userdata) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_free_ char *n = NULL;
+ sd_bus *bus;
+ int r;
+
+ r = acquire_bus(BUS_MANAGER, &bus);
+ if (r < 0)
+ return r;
+
+ polkit_agent_open_maybe();
+
+ r = unit_name_mangle(argv[1], arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, &n);
+ if (r < 0)
+ return log_error_errno(r, "Failed to mangle unit name: %m");
+
+ r = bus_call_method(
+ bus,
+ bus_systemd_mgr,
+ "BindMountUnit",
+ &error,
+ NULL,
+ "sssbb",
+ n,
+ argv[2],
+ argv[3],
+ arg_read_only,
+ arg_mkdir);
+ if (r < 0)
+ return log_error_errno(r, "Failed to bind mount: %s", bus_error_message(&error, r));
+
+ return 0;
+}