X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd-bus%2Fbus-kernel.c;h=d2fcfd7f928e38780053e31be826f408d002eeb0;hb=c58dea190c4cc66330942ccb7a9d485ff45504d3;hp=84d84df59dab4971e98d9d3c90fe85e53000754f;hpb=5b12334d35eadf1f45cc3d631fd1a2e72ffaea0a;p=elogind.git diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c index 84d84df59..d2fcfd7f9 100644 --- a/src/libsystemd-bus/bus-kernel.c +++ b/src/libsystemd-bus/bus-kernel.c @@ -326,6 +326,7 @@ int bus_kernel_take_fd(sd_bus *b) { zero(hello); hello.size = sizeof(hello); hello.conn_flags = b->hello_flags; + hello.attach_flags = b->attach_flags; hello.pool_size = KDBUS_POOL_SIZE; r = ioctl(b->input_fd, KDBUS_CMD_HELLO, &hello); @@ -356,6 +357,9 @@ int bus_kernel_take_fd(sd_bus *b) { b->bus_client = true; b->can_fds = !!(hello.conn_flags & KDBUS_HELLO_ACCEPT_FD); + /* the kernel told us the UUID of the underlying bus */ + memcpy(b->server_id.bytes, hello.id128, sizeof(b->server_id.bytes)); + r = bus_start_running(b); if (r < 0) return r; @@ -409,7 +413,7 @@ static void close_kdbus_msg(sd_bus *bus, struct kdbus_msg *k) { off = (uint8_t *)k - (uint8_t *)bus->kdbus_buffer; ioctl(bus->input_fd, KDBUS_CMD_MSG_RELEASE, &off); - KDBUS_ITEM_FOREACH(d, k) { + KDBUS_PART_FOREACH(d, k, items) { if (d->type == KDBUS_MSG_FDS) close_many(d->fds, (d->size - offsetof(struct kdbus_item, fds)) / sizeof(int)); @@ -435,7 +439,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess if (k->payload_type != KDBUS_PAYLOAD_DBUS1) return 0; - KDBUS_ITEM_FOREACH(d, k) { + KDBUS_PART_FOREACH(d, k, items) { size_t l; l = d->size - offsetof(struct kdbus_item, data); @@ -489,7 +493,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess if (r < 0) return r; - KDBUS_ITEM_FOREACH(d, k) { + KDBUS_PART_FOREACH(d, k, items) { size_t l; l = d->size - offsetof(struct kdbus_item, data); @@ -593,7 +597,8 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k, sd_bus_mess } else if (d->type == KDBUS_MSG_DST_NAME) destination = d->str; else if (d->type != KDBUS_MSG_FDS && - d->type != KDBUS_MSG_SRC_SECLABEL) + d->type != KDBUS_MSG_SRC_SECLABEL && + d->type != KDBUS_MSG_SRC_NAMES) log_debug("Got unknown field from kernel %llu", d->type); } @@ -684,13 +689,13 @@ int bus_kernel_create(const char *name, char **s) { l = strlen(name); make = alloca0(offsetof(struct kdbus_cmd_bus_make, items) + - KDBUS_ITEM_HEADER_SIZE + sizeof(uint64_t) + - KDBUS_ITEM_HEADER_SIZE + DECIMAL_STR_MAX(uid_t) + 1 + l + 1); + KDBUS_PART_HEADER_SIZE + sizeof(uint64_t) + + KDBUS_PART_HEADER_SIZE + DECIMAL_STR_MAX(uid_t) + 1 + l + 1); n = make->items; n->type = KDBUS_MAKE_NAME; sprintf(n->str, "%lu-%s", (unsigned long) getuid(), name); - n->size = KDBUS_ITEM_HEADER_SIZE + strlen(n->str) + 1; + n->size = KDBUS_PART_HEADER_SIZE + strlen(n->str) + 1; make->size = offsetof(struct kdbus_cmd_bus_make, items) + n->size; make->flags = KDBUS_MAKE_POLICY_OPEN; @@ -805,3 +810,21 @@ void bus_kernel_flush_memfd(sd_bus *b) { for (i = 0; i < b->n_memfd_cache; i++) close_and_munmap(b->memfd_cache[i].fd, b->memfd_cache[i].address, b->memfd_cache[i].size); } + +int sd_bus_kernel_translate_request_name_flags(uint64_t sd_bus_flags, uint64_t *kdbus_flags) { + + assert_return(kdbus_flags != NULL, -EINVAL); + + *kdbus_flags = 0; + + if (sd_bus_flags & SD_BUS_NAME_ALLOW_REPLACEMENT) + *kdbus_flags |= KDBUS_NAME_ALLOW_REPLACEMENT; + + if (sd_bus_flags & SD_BUS_NAME_REPLACE_EXISTING) + *kdbus_flags |= KDBUS_NAME_REPLACE_EXISTING; + + if (!(sd_bus_flags & SD_BUS_NAME_DO_NOT_QUEUE)) + *kdbus_flags |= KDBUS_NAME_QUEUE; + + return 0; +}