m->kdbus->dst_id =
well_known ? 0 :
m->destination ? unique : KDBUS_DST_ID_BROADCAST;
- m->kdbus->payload_type = KDBUS_PAYLOAD_DBUS1;
+ m->kdbus->payload_type = KDBUS_PAYLOAD_DBUS;
m->kdbus->cookie = m->header->serial;
m->kdbus->timeout_ns = m->timeout * NSEC_PER_USEC;
b->is_kernel = true;
b->bus_client = true;
b->can_fds = !!(hello.conn_flags & KDBUS_HELLO_ACCEPT_FD);
+ b->message_version = 2;
+ b->message_endian = BUS_NATIVE_ENDIAN;
/* the kernel told us the UUID of the underlying bus */
memcpy(b->server_id.bytes, hello.id128, sizeof(b->server_id.bytes));
if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
sd_bus_error_setf(&error, SD_BUS_ERROR_SERVICE_UNKNOWN, "Destination %s not known", m->destination);
- else
+ else {
+ log_debug("Could not deliver message to %s as destination is not known. Ignoring.", m->destination);
return 0;
+ }
} else if (errno == EADDRNOTAVAIL) {
if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
sd_bus_error_setf(&error, SD_BUS_ERROR_SERVICE_UNKNOWN, "Activation of %s not requested", m->destination);
- else
+ else {
+ log_debug("Could not deliver message to %s as destination is not activated. Ignoring.", m->destination);
return 0;
+ }
} else
return -errno;
assert(k);
assert(d);
- if (d->name_change.flags != 0)
- return 0;
-
- if (d->type == KDBUS_ITEM_NAME_ADD)
+ if (d->type == KDBUS_ITEM_NAME_ADD || (d->name_change.old_flags & (KDBUS_NAME_IN_QUEUE|KDBUS_NAME_ACTIVATOR)))
old_owner[0] = 0;
else
sprintf(old_owner, ":1.%llu", (unsigned long long) d->name_change.old_id);
- if (d->type == KDBUS_ITEM_NAME_REMOVE)
+ if (d->type == KDBUS_ITEM_NAME_REMOVE || (d->name_change.new_flags & (KDBUS_NAME_IN_QUEUE|KDBUS_NAME_ACTIVATOR))) {
+
+ if (isempty(old_owner))
+ return 0;
+
new_owner[0] = 0;
- else
+ } else
sprintf(new_owner, ":1.%llu", (unsigned long long) d->name_change.new_id);
return push_name_owner_changed(bus, d->name_change.name, old_owner, new_owner);
assert(bus);
assert(k);
- assert(k->payload_type == KDBUS_PAYLOAD_DBUS1);
+ assert(k->payload_type == KDBUS_PAYLOAD_DBUS);
KDBUS_ITEM_FOREACH(d, k, items) {
size_t l;
if (n_bytes != total)
return -EBADMSG;
+ /* on kdbus we only speak native endian gvariant, never dbus1
+ * marshalling or reverse endian */
+ if (h->version != 2 ||
+ h->endian != BUS_NATIVE_ENDIAN)
+ return -EPROTOTYPE;
+
r = bus_message_from_header(bus, h, sizeof(struct bus_header), fds, n_fds, NULL, seclabel, 0, &m);
if (r < 0)
return r;
if (r < 0)
goto fail;
+ /* Override information from the user header with data from the kernel */
if (k->src_id == KDBUS_SRC_ID_KERNEL)
m->sender = "org.freedesktop.DBus";
else {
}
k = (struct kdbus_msg *)((uint8_t *)bus->kdbus_buffer + off);
- if (k->payload_type == KDBUS_PAYLOAD_DBUS1)
+ if (k->payload_type == KDBUS_PAYLOAD_DBUS) {
r = bus_kernel_make_message(bus, k);
- else if (k->payload_type == KDBUS_PAYLOAD_KERNEL)
+
+ /* Anybody can send us invalid messages, let's just drop them. */
+ if (r == -EBADMSG || r == -EPROTOTYPE) {
+ log_debug("Ignoring invalid message: %s", strerror(-r));
+ r = 0;
+ }
+
+ } else if (k->payload_type == KDBUS_PAYLOAD_KERNEL)
r = bus_kernel_translate_message(bus, k);
else
r = 0;
if (flags & SD_BUS_NAME_REPLACE_EXISTING)
f |= KDBUS_NAME_REPLACE_EXISTING;
- if (!(flags & SD_BUS_NAME_DO_NOT_QUEUE))
+ if (flags & SD_BUS_NAME_QUEUE)
f |= KDBUS_NAME_QUEUE;
*kdbus_flags = f;
n = hello->items;
strcpy(n->str, name);
n->size = offsetof(struct kdbus_item, str) + strlen(n->str) + 1;
- n->type = KDBUS_ITEM_STARTER_NAME;
+ n->type = KDBUS_ITEM_ACTIVATOR_NAME;
hello->size = ALIGN8(offsetof(struct kdbus_cmd_hello, items) + n->size);
- hello->conn_flags = KDBUS_HELLO_STARTER;
+ hello->conn_flags = KDBUS_HELLO_ACTIVATOR;
hello->pool_size = KDBUS_POOL_SIZE;
if (ioctl(fd, KDBUS_CMD_HELLO, hello) < 0) {
return fd;
}
+
+int bus_kernel_monitor(sd_bus *bus) {
+ struct kdbus_cmd_monitor cmd_monitor;
+ int r;
+
+ assert(bus);
+
+ cmd_monitor.id = 0;
+ cmd_monitor.flags = KDBUS_MONITOR_ENABLE;
+
+ r = ioctl(bus->input_fd, KDBUS_CMD_MONITOR, &cmd_monitor);
+ if (r < 0)
+ return -errno;
+
+ return 1;
+}