#include <fcntl.h>
#include <malloc.h>
-#include <libgen.h>
#include <sys/mman.h>
#include <sys/prctl.h>
+/* When we include libgen.h because we need dirname() we immediately
+ * undefine basename() since libgen.h defines it as a macro to the XDG
+ * version which is really broken. */
+#include <libgen.h>
+#undef basename
+
#include "util.h"
#include "strv.h"
#include "memfd-util.h"
case KDBUS_ITEM_PAYLOAD_OFF:
if (!h) {
- h = (struct bus_header *)((uint8_t *)bus->kdbus_buffer + d->vec.offset);
+ h = (struct bus_header *)((uint8_t *)k + d->vec.offset);
if (!bus_header_is_complete(h, d->vec.size))
return -EBADMSG;
if (idx >= begin_body) {
if (!part->is_zero)
- part->data = (uint8_t *)bus->kdbus_buffer + d->vec.offset;
+ part->data = (uint8_t *)k + d->vec.offset;
part->size = d->vec.size;
} else {
if (!part->is_zero)
- part->data = (uint8_t *)bus->kdbus_buffer + d->vec.offset + (begin_body - idx);
+ part->data = (uint8_t *)k + d->vec.offset + (begin_body - idx);
part->size = d->vec.size - (begin_body - idx);
}
}
int bus_kernel_take_fd(sd_bus *b) {
- struct kdbus_cmd_free cmd_free = {
- .size = sizeof(cmd_free),
- .flags = 0,
- };
struct kdbus_bloom_parameter *bloom = NULL;
struct kdbus_cmd_hello *hello;
struct kdbus_item_list *items;
/* free returned items */
(void) bus_kernel_cmd_free(b, hello->offset);
-
return bus_start_running(b);
fail:
- cmd_free.offset = hello->offset;
- (void) ioctl(b->input_fd, KDBUS_CMD_FREE, &cmd_free);
+ (void) bus_kernel_cmd_free(b, hello->offset);
return r;
}
int bus_kernel_cmd_free(sd_bus *bus, uint64_t offset) {
struct kdbus_cmd_free cmd = {
.size = sizeof(cmd),
- .flags = 0,
.offset = offset,
};
int r;
return -errno;
}
- k = (struct kdbus_msg *)((uint8_t *)bus->kdbus_buffer + recv.reply.offset);
+ k = (struct kdbus_msg *)((uint8_t *)bus->kdbus_buffer + recv.msg.offset);
if (k->payload_type == KDBUS_PAYLOAD_DBUS) {
r = bus_kernel_make_message(bus, k);
}
int bus_kernel_create_bus(const char *name, bool world, char **s) {
- struct kdbus_cmd_make *make;
+ struct kdbus_cmd *make;
struct kdbus_item *n;
size_t l;
int fd;
return -errno;
l = strlen(name);
- make = alloca0_align(offsetof(struct kdbus_cmd_make, items) +
+ make = alloca0_align(offsetof(struct kdbus_cmd, items) +
ALIGN8(offsetof(struct kdbus_item, bloom_parameter) + sizeof(struct kdbus_bloom_parameter)) +
ALIGN8(offsetof(struct kdbus_item, data64) + sizeof(uint64_t)) +
ALIGN8(offsetof(struct kdbus_item, data64) + sizeof(uint64_t)) +
ALIGN8(offsetof(struct kdbus_item, str) + DECIMAL_STR_MAX(uid_t) + 1 + l + 1),
8);
- make->size = offsetof(struct kdbus_cmd_make, items);
+ make->size = offsetof(struct kdbus_cmd, items);
/* Set the bloom parameters */
n = make->items;
int bus_kernel_create_endpoint(const char *bus_name, const char *ep_name, char **ep_path) {
_cleanup_free_ char *path = NULL;
- struct kdbus_cmd_make *make;
+ struct kdbus_cmd *make;
struct kdbus_item *n;
const char *name;
int fd;
if (fd < 0)
return fd;
- make = alloca0_align(ALIGN8(offsetof(struct kdbus_cmd_make, items)) +
+ make = alloca0_align(ALIGN8(offsetof(struct kdbus_cmd, items)) +
ALIGN8(offsetof(struct kdbus_item, str) + DECIMAL_STR_MAX(uid_t) + 1 + strlen(ep_name) + 1),
8);
- make->size = ALIGN8(offsetof(struct kdbus_cmd_make, items));
+ make->size = ALIGN8(offsetof(struct kdbus_cmd, items));
make->flags = KDBUS_MAKE_ACCESS_WORLD;
n = make->items;
}
int bus_kernel_try_close(sd_bus *bus) {
+ struct kdbus_cmd byebye = { .size = sizeof(byebye) };
+
assert(bus);
assert(bus->is_kernel);
- if (ioctl(bus->input_fd, KDBUS_CMD_BYEBYE) < 0)
+ if (ioctl(bus->input_fd, KDBUS_CMD_BYEBYE, &byebye) < 0)
return -errno;
return 0;
}
int bus_kernel_realize_attach_flags(sd_bus *bus) {
- struct kdbus_cmd_update *update;
+ struct kdbus_cmd *update;
struct kdbus_item *n;
assert(bus);
assert(bus->is_kernel);
- update = alloca0_align(offsetof(struct kdbus_cmd_update, items) +
+ update = alloca0_align(offsetof(struct kdbus_cmd, items) +
ALIGN8(offsetof(struct kdbus_item, data64) + sizeof(uint64_t)),
8);
n->data64[0] = bus->attach_flags;
update->size =
- offsetof(struct kdbus_cmd_update, items) +
+ offsetof(struct kdbus_cmd, items) +
ALIGN8(n->size);
- if (ioctl(bus->input_fd, KDBUS_CMD_CONN_UPDATE, update) < 0)
+ if (ioctl(bus->input_fd, KDBUS_CMD_UPDATE, update) < 0)
return -errno;
return 0;
/* By default we don't want any kdbus metadata fields to be
* suppressed, hence we reset the kernel mask for it to
- * (uint64_t) -1. This is overridable via a kernel command
- * line option, however. */
+ * (uint64_t) -1. If the module argument was overwritten by
+ * the kernel cmdline, we leave it as is. */
- r = get_proc_cmdline_key("systemd.kdbus_attach_flags_mask=", &mask);
+ r = get_proc_cmdline_key("kdbus.attach_flags_mask=", &mask);
if (r < 0)
return log_warning_errno(r, "Failed to read kernel command line: %m");
- if (mask) {
- const char *p = mask;
-
- if (startswith(p, "0x"))
- p += 2;
-
- if (sscanf(p, "%" PRIx64, &m) != 1)
- log_warning("Couldn't parse systemd.kdbus_attach_flags_mask= kernel command line parameter.");
+ if (r == 0) {
+ sprintf(buf, "0x%" PRIx64 "\n", m);
+ r = write_string_file("/sys/module/kdbus/parameters/attach_flags_mask", buf);
+ if (r < 0)
+ return log_full_errno(IN_SET(r, -ENOENT, -EROFS) ? LOG_DEBUG : LOG_WARNING, r,
+ "Failed to write kdbus attach mask: %m");
}
- sprintf(buf, "0x%" PRIx64 "\n", m);
- r = write_string_file("/sys/module/kdbus/parameters/attach_flags_mask", buf);
- if (r < 0)
- return log_full_errno(
- IN_SET(r, -ENOENT, -EROFS) ? LOG_DEBUG : LOG_WARNING, r,
- "Failed to write kdbus attach mask: %m");
-
return 0;
}