summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/bus-kernel.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-30 16:36:46 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-30 16:36:46 +0100
commit9bd37b40fac198fee2ff4eabc8793f1a7f2770fe (patch)
tree34a776ca63ad35e2dbf8d315a2d56c6f2bee6c52 /src/libsystemd-bus/bus-kernel.c
parent3310dfd5bdba0e8218eca1eb6c1fa719adc45bb1 (diff)
nspawn: set up a kdbus namespace when starting a container
Diffstat (limited to 'src/libsystemd-bus/bus-kernel.c')
-rw-r--r--src/libsystemd-bus/bus-kernel.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 51e882c73d..09e084a02f 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -1042,7 +1042,7 @@ int kdbus_translate_attach_flags(uint64_t mask, uint64_t *kdbus_mask) {
return 0;
}
-int bus_kernel_create(const char *name, char **s) {
+int bus_kernel_create_bus(const char *name, char **s) {
struct kdbus_cmd_bus_make *make;
struct kdbus_item *n;
int fd;
@@ -1088,3 +1088,47 @@ int bus_kernel_create(const char *name, char **s) {
return fd;
}
+
+int bus_kernel_create_namespace(const char *name, char **s) {
+ struct kdbus_cmd_ns_make *make;
+ struct kdbus_item *n;
+ int fd;
+
+ assert(name);
+ assert(s);
+
+ fd = open("/dev/kdbus/control", O_RDWR|O_NOCTTY|O_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+
+ make = alloca0(ALIGN8(offsetof(struct kdbus_cmd_ns_make, items) +
+ offsetof(struct kdbus_item, str) +
+ strlen(name) + 1));
+
+ n = make->items;
+ strcpy(n->str, name);
+ n->size = offsetof(struct kdbus_item, str) + strlen(n->str) + 1;
+ n->type = KDBUS_MAKE_NAME;
+
+ make->size = ALIGN8(offsetof(struct kdbus_cmd_ns_make, items) + n->size);
+ make->flags = KDBUS_MAKE_POLICY_OPEN;
+
+ if (ioctl(fd, KDBUS_CMD_NS_MAKE, make) < 0) {
+ close_nointr_nofail(fd);
+ return -errno;
+ }
+
+ if (s) {
+ char *p;
+
+ p = strappend("/dev/kdbus/", name);
+ if (!p) {
+ close_nointr_nofail(fd);
+ return -ENOMEM;
+ }
+
+ *s = p;
+ }
+
+ return fd;
+}