assert_return(!bus_pid_changed(bus), -ECHILD);
if (bus->is_kernel) {
- _cleanup_free_ struct kdbus_cmd_names *names = NULL;
+ _cleanup_free_ struct kdbus_cmd_name_list *cmd = NULL;
+ struct kdbus_name_list *name_list;
struct kdbus_cmd_name *name;
- size_t size;
- /* assume 8k size first. If that doesn't suffice, kdbus will tell us
- * how big the buffer needs to be. */
- size = 8192;
-
- for(;;) {
- names = realloc(names, size);
- if (!names)
- return -ENOMEM;
-
- names->size = size;
- names->flags = KDBUS_NAME_LIST_UNIQUE_NAMES;
+ cmd = malloc0(sizeof(struct kdbus_cmd_name_list *));
+ if (!cmd)
+ return -ENOMEM;
- r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_NAME_LIST, names);
- if (r < 0) {
- if (errno == ENOBUFS && size != names->size) {
- size = names->size;
- continue;
- }
+ cmd->flags = KDBUS_NAME_LIST_UNIQUE_NAMES;
- return -errno;
- }
+ r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_NAME_LIST, cmd);
+ if (r < 0)
+ return -errno;
- break;
- }
+ name_list = (struct kdbus_name_list *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
- KDBUS_PART_FOREACH(name, names, names) {
+ KDBUS_PART_FOREACH(name, name_list, names) {
char *n;
if (name->size > sizeof(*name))
return -ENOMEM;
}
+ r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_FREE, &cmd->offset);
+ if (r < 0)
+ return -errno;
+
*l = x;
} else {
r = sd_bus_call_method(
return 0;
}
-static int kdbus_name_query(
+static int kdbus_name_info(
sd_bus *bus,
const char *name,
uint64_t mask,
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
+ _cleanup_free_ struct kdbus_cmd_name_info *cmd = NULL;
_cleanup_free_ char *unique = NULL;
- struct kdbus_cmd_name_info *name_info = NULL;
+ struct kdbus_name_info *name_info;
struct kdbus_item *item;
uint64_t attach_flags, m;
- size_t slen, size;
+ size_t size;
int r;
r = kdbus_translate_attach_flags(mask, &attach_flags);
if (r < 0)
return r;
- slen = strlen(name) + 1;
-
- /*
- * The structure is used for both directions. Start with 8k buffer size and
- * expand to the size kdbus reports in case we fail.
- */
- size = slen + 8192;
-
- for(;;) {
- name_info = realloc(name_info, size);
- if (!name_info)
- return -ENOMEM;
-
- memset(name_info, 0, size);
-
- name_info->size = size;
- name_info->attach_flags = attach_flags;
-
- item = name_info->items;
- item->type = KDBUS_NAME_INFO_ITEM_NAME;
- item->size = KDBUS_ITEM_SIZE(slen);
- strcpy(item->str, name);
+ size = sizeof(struct kdbus_cmd_name_info) + strlen(name) + 1;
+ cmd = malloc0(size);
+ if (!cmd)
+ return -ENOMEM;
- r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_NAME_QUERY, name_info);
- if (r < 0) {
- if (errno == ENOBUFS && size != name_info->size) {
- size = name_info->size;
- continue;
- }
+ cmd ->size = size;
+ cmd->attach_flags = attach_flags;
+ strcpy(cmd->name, name);
- return -errno;
- }
+ r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_NAME_INFO, cmd);
+ if (r < 0)
+ return -errno;
- break;
- }
+ name_info = (struct kdbus_name_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
asprintf(&unique, ":1.%llu", (unsigned long long) name_info->id);
}
}
+ r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_FREE, &cmd->offset);
+ if (r < 0)
+ return -errno;
+
if (creds) {
*creds = c;
c = NULL;
assert_return(!bus_pid_changed(bus), -ECHILD);
if (bus->is_kernel)
- return kdbus_name_query(bus, name, mask, owner, creds);
+ return kdbus_name_info(bus, name, mask, owner, creds);
return sd_bus_get_owner_dbus(bus, name, mask, owner, creds);
}
assert(k);
off = (uint8_t *)k - (uint8_t *)bus->kdbus_buffer;
- ioctl(bus->input_fd, KDBUS_CMD_MSG_RELEASE, &off);
+ ioctl(bus->input_fd, KDBUS_CMD_FREE, &off);
KDBUS_PART_FOREACH(d, k, items) {
uint64_t off;
off = (uint8_t *)m->kdbus - (uint8_t *)m->bus->kdbus_buffer;
- ioctl(m->bus->input_fd, KDBUS_CMD_MSG_RELEASE, &off);
+ ioctl(m->bus->input_fd, KDBUS_CMD_FREE, &off);
}
if (m->bus)
enum {
_KDBUS_MAKE_NULL,
KDBUS_MAKE_NAME,
+ KDBUS_MAKE_CRED, /* allow translator services which connect
+ * to the bus on behalf of somebody else,
+ * allow specifying the credentials of the
+ * client to connect on behalf on. Needs
+ * privileges */
};
struct kdbus_cmd_bus_make {
KDBUS_NAME_IN_QUEUE = 1 << 16,
};
-/* We allow (de)regestration of names of other peers */
+/* We allow (de)registration of names of other peers */
struct kdbus_cmd_name {
__u64 size;
__u64 flags;
char name[0];
};
+/* KDBUS_CMD_NAME_LIST */
enum {
KDBUS_NAME_LIST_UNIQUE_NAMES = 1 << 0,
};
-struct kdbus_cmd_names {
- __u64 size;
+struct kdbus_cmd_name_list {
__u64 flags;
- struct kdbus_cmd_name names[0];
+ __u64 offset; /* returned offset in the caller's buffer */
};
-enum {
- _KDBUS_NAME_INFO_ITEM_NULL,
- KDBUS_NAME_INFO_ITEM_NAME, /* userspace → kernel */
- KDBUS_NAME_INFO_ITEM_SECLABEL, /* kernel → userspace */
- KDBUS_NAME_INFO_ITEM_AUDIT, /* kernel → userspace */
+struct kdbus_name_list {
+ __u64 size;
+ struct kdbus_cmd_name names[0];
};
+/* KDBUS_CMD_NAME_INFO */
struct kdbus_cmd_name_info {
- __u64 size; /* overall size of info */
+ __u64 size;
__u64 flags; /* query flags */
__u64 attach_flags; /* which meta data payload to attach */
- __u64 id; /* either ID, or 0 and _ITEM_NAME follows */
- struct kdbus_creds creds;
+ __u64 id; /* either ID, or 0 and name follows */
+ __u64 offset; /* returned offset in the caller's buffer */
+ char name[0];
+};
+
+struct kdbus_name_info {
+ __u64 size;
+ __u64 id;
+ __u64 flags; /* connection flags */
struct kdbus_item items[0]; /* list of item records */
};
+/* KDBUS_CMD_MATCH_ADD/REMOVE */
enum {
_KDBUS_MATCH_NULL,
KDBUS_MATCH_BLOOM, /* Matches a mask blob against KDBUS_MSG_BLOOM */
struct kdbus_item items[0];
};
+/* KDBUS_CMD_MONITOR */
struct kdbus_cmd_monitor {
__u64 id; /* We allow setting the monitor flag of other peers */
unsigned int enable; /* A boolean to enable/disable monitoring */
__u32 __pad;
};
-/* FD states:
- * control nodes: unset
- * bus owner (via KDBUS_CMD_BUS_MAKE)
- * ns owner (via KDBUS_CMD_NS_MAKE)
- *
- * ep nodes: unset
- * connected (via KDBUS_CMD_HELLO)
- * starter (via KDBUS_CMD_HELLO with KDBUS_CMD_HELLO_STARTER)
- * ep owner (via KDBUS_CMD_EP_MAKE)
- */
enum {
/* kdbus control node commands: require unset state */
KDBUS_CMD_BUS_MAKE = _IOW(KDBUS_IOC_MAGIC, 0x00, struct kdbus_cmd_bus_make),
/* kdbus ep node commands: require connected state */
KDBUS_CMD_MSG_SEND = _IOW(KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
KDBUS_CMD_MSG_RECV = _IOR(KDBUS_IOC_MAGIC, 0x41, __u64 *),
- KDBUS_CMD_MSG_RELEASE = _IOW(KDBUS_IOC_MAGIC, 0x42, __u64 *),
+ KDBUS_CMD_FREE = _IOW(KDBUS_IOC_MAGIC, 0x42, __u64 *),
KDBUS_CMD_NAME_ACQUIRE = _IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
KDBUS_CMD_NAME_RELEASE = _IOW(KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
- KDBUS_CMD_NAME_LIST = _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_names),
- KDBUS_CMD_NAME_QUERY = _IOWR(KDBUS_IOC_MAGIC, 0x53, struct kdbus_cmd_name_info),
+ KDBUS_CMD_NAME_LIST = _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_name_list),
+ KDBUS_CMD_NAME_INFO = _IOWR(KDBUS_IOC_MAGIC, 0x53, struct kdbus_cmd_name_info),
KDBUS_CMD_MATCH_ADD = _IOW(KDBUS_IOC_MAGIC, 0x60, struct kdbus_cmd_match),
KDBUS_CMD_MATCH_REMOVE = _IOW(KDBUS_IOC_MAGIC, 0x61, struct kdbus_cmd_match),
/* We'll leave the fd open in case this is a kernel bus, since
* there might still be memblocks around that reference this
- * bus, and they might need to invoke the
- * KDBUS_CMD_MSG_RELEASE ioctl on the fd when they are
- * freed. */
+ * bus, and they might need to invoke the * KDBUS_CMD_FREE
+ * ioctl on the fd when they are freed. */
}
static void bus_enter_closing(sd_bus *bus) {