return conn->fd;
}
+static void set_item_str(struct kdbus_item *item, const char *str, __u64 str_length, __u64 type)
+{
+ item->size = KDBUS_ITEM_SIZE(str_length);
+ item->type = type;
+ memcpy(item->str, str, str_length);
+}
+
static int kdbus_hello(struct kdbus_connection *conn,
uint64_t hello_flags,
uint64_t attach_flags_send,
cmd->attach_flags_recv = attach_flags_recv;
cmd->pool_size = KDBUS_POOL_SIZE;
- struct kdbus_item *item = cmd->items;
- item->size = offsetof(struct kdbus_item, data) + sizeof(CONNECTION_LABEL);
- item->type = KDBUS_ITEM_CONN_DESCRIPTION;
- memcpy(item->str, CONNECTION_LABEL, sizeof(CONNECTION_LABEL));
+ set_item_str(cmd->items, CONNECTION_LABEL, sizeof(CONNECTION_LABEL), KDBUS_ITEM_CONN_DESCRIPTION);
+
if (ioctl(conn->fd, KDBUS_CMD_HELLO, cmd) < 0)
return -errno;
return res;
}
-static void set_item_info(struct kdbus_item *item, const char *str, __u64 str_length, __u64 type)
-{
- item->size = (__u64)offsetof(struct kdbus_item, data) + str_length + (__u64)1;
- item->type = type;
- *(uint64_t*)ALIGNDN8((uintptr_t)item->str + str_length) = 0; /* trailing zero + padding */
- memcpy(item->str, str, str_length+1);
-}
-
int kdbus_get_conn_info(kdbus_connection *conn,
const char *destination,
struct kdbus_cmd_param *info,
auto l = strlen(destination);
cmd->size += KDBUS_ITEM_SIZE_ALIGN(ALIGN8(l+1));
cmd->id = 0;
- set_item_info(cmd->items, destination, l, KDBUS_ITEM_NAME);
+ set_item_str(cmd->items, destination, l+1, KDBUS_ITEM_NAME);
}
if (ioctl(conn->fd, KDBUS_CMD_CONN_INFO, cmd) < 0) {
if (errno == ENXIO || errno == ESRCH)