diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-30 16:36:46 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-30 16:36:46 +0100 |
commit | 9bd37b40fac198fee2ff4eabc8793f1a7f2770fe (patch) | |
tree | 34a776ca63ad35e2dbf8d315a2d56c6f2bee6c52 /src/libsystemd-bus | |
parent | 3310dfd5bdba0e8218eca1eb6c1fa719adc45bb1 (diff) |
nspawn: set up a kdbus namespace when starting a container
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r-- | src/libsystemd-bus/bus-kernel.c | 46 | ||||
-rw-r--r-- | src/libsystemd-bus/bus-kernel.h | 3 | ||||
-rw-r--r-- | src/libsystemd-bus/test-bus-kernel-benchmark.c | 2 | ||||
-rw-r--r-- | src/libsystemd-bus/test-bus-kernel-bloom.c | 2 | ||||
-rw-r--r-- | src/libsystemd-bus/test-bus-kernel.c | 2 | ||||
-rw-r--r-- | src/libsystemd-bus/test-bus-zero-copy.c | 2 |
6 files changed, 51 insertions, 6 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; +} diff --git a/src/libsystemd-bus/bus-kernel.h b/src/libsystemd-bus/bus-kernel.h index 746ab227a4..92d3888ed5 100644 --- a/src/libsystemd-bus/bus-kernel.h +++ b/src/libsystemd-bus/bus-kernel.h @@ -60,7 +60,8 @@ int bus_kernel_take_fd(sd_bus *b); int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m); int bus_kernel_read_message(sd_bus *bus); -int bus_kernel_create(const char *name, char **s); +int bus_kernel_create_bus(const char *name, char **s); +int bus_kernel_create_namespace(const char *name, char **s); int bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *size); void bus_kernel_push_memfd(sd_bus *bus, int fd, void *address, size_t size); diff --git a/src/libsystemd-bus/test-bus-kernel-benchmark.c b/src/libsystemd-bus/test-bus-kernel-benchmark.c index 6afae7f487..010a161328 100644 --- a/src/libsystemd-bus/test-bus-kernel-benchmark.c +++ b/src/libsystemd-bus/test-bus-kernel-benchmark.c @@ -239,7 +239,7 @@ int main(int argc, char *argv[]) { assert_se(arg_loop_usec > 0); - bus_ref = bus_kernel_create("deine-mutter", &bus_name); + bus_ref = bus_kernel_create_bus("deine-mutter", &bus_name); if (bus_ref == -ENOENT) exit(EXIT_TEST_SKIP); diff --git a/src/libsystemd-bus/test-bus-kernel-bloom.c b/src/libsystemd-bus/test-bus-kernel-bloom.c index dcf048338f..62983eacc8 100644 --- a/src/libsystemd-bus/test-bus-kernel-bloom.c +++ b/src/libsystemd-bus/test-bus-kernel-bloom.c @@ -42,7 +42,7 @@ static void test_one( sd_bus *a, *b; int r; - bus_ref = bus_kernel_create("deine-mutter", &bus_name); + bus_ref = bus_kernel_create_bus("deine-mutter", &bus_name); if (bus_ref == -ENOENT) exit(EXIT_TEST_SKIP); diff --git a/src/libsystemd-bus/test-bus-kernel.c b/src/libsystemd-bus/test-bus-kernel.c index 04dbc998dc..23b185d3fe 100644 --- a/src/libsystemd-bus/test-bus-kernel.c +++ b/src/libsystemd-bus/test-bus-kernel.c @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) { log_set_max_level(LOG_DEBUG); - bus_ref = bus_kernel_create("deine-mutter", &bus_name); + bus_ref = bus_kernel_create_bus("deine-mutter", &bus_name); if (bus_ref == -ENOENT) return EXIT_TEST_SKIP; diff --git a/src/libsystemd-bus/test-bus-zero-copy.c b/src/libsystemd-bus/test-bus-zero-copy.c index 032449a5d8..92a7398a78 100644 --- a/src/libsystemd-bus/test-bus-zero-copy.c +++ b/src/libsystemd-bus/test-bus-zero-copy.c @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) { log_set_max_level(LOG_DEBUG); - bus_ref = bus_kernel_create("deine-mutter", &bus_name); + bus_ref = bus_kernel_create_bus("deine-mutter", &bus_name); if (bus_ref == -ENOENT) return EXIT_TEST_SKIP; |