struct kdbus_conn **conn)
{
const struct kdbus_msg *msg = &kmsg->msg;
- struct kdbus_conn *c;
+ struct kdbus_conn *c, *activator;
u64 name_id = 0;
int ret = 0;
if (msg->dst_id == KDBUS_DST_ID_NAME) {
- const struct kdbus_name_entry *name_entry;
-
BUG_ON(!kmsg->dst_name);
- name_entry = kdbus_name_lookup(bus->name_registry,
- kmsg->dst_name);
- if (!name_entry)
- return -ESRCH;
-
- name_id = name_entry->name_id;
+ ret = kdbus_name_lookup(bus->name_registry,
+ kmsg->dst_name,
+ &c,
+ &activator,
+ &name_id);
+ if (ret < 0)
+ return ret;
- if (!name_entry->conn && name_entry->activator)
- c = kdbus_conn_ref(name_entry->activator);
+ if (!c && activator)
+ c = activator;
else
- c = kdbus_conn_ref(name_entry->conn);
+ kdbus_conn_unref(activator);
if ((msg->flags & KDBUS_MSG_FLAGS_NO_AUTO_START) &&
(c->flags & KDBUS_HELLO_ACTIVATOR)) {
* was already set above.
*/
if (name) {
- struct kdbus_name_entry *e;
-
if (!kdbus_check_strlen(cmd_info, name)) {
ret = -EINVAL;
goto exit;
}
- e = kdbus_name_lookup(conn->bus->name_registry, name);
- if (!e) {
- ret = -ESRCH;
+ ret = kdbus_name_lookup(conn->bus->name_registry,
+ name,
+ &owner_conn,
+ NULL,
+ NULL);
+ if (ret < 0)
goto exit;
- }
-
- if (e->conn)
- owner_conn = kdbus_conn_ref(e->conn);
}
if (!owner_conn) {
* kdbus_name_lookup() - look up a name in a name registry
* @reg: The name registry
* @name: The name to look up
+ * @conn: Output for the connection owning the name or NULL
+ * @activator: Output for the activator owning the name or NULL
+ * @name_id: Output for the name-id or NULL
*
- * Return: name entry if found, otherwise NULL.
+ * Search for a name in a given name registry. The found connections are stored
+ * with a new reference in the output stores. If either is not found, they're
+ * set to NULL.
+ *
+ * Return: 0 if either @conn or @activator was found, -ESRCH if nothing found.
*/
-struct kdbus_name_entry *kdbus_name_lookup(struct kdbus_name_registry *reg,
- const char *name)
+int kdbus_name_lookup(struct kdbus_name_registry *reg,
+ const char *name,
+ struct kdbus_conn **conn,
+ struct kdbus_conn **activator,
+ u64 *name_id)
{
struct kdbus_name_entry *e = NULL;
u32 hash = kdbus_str_hash(name);
mutex_lock(®->lock);
e = __kdbus_name_lookup(reg, hash, name);
+ if (e) {
+ if (conn)
+ *conn = kdbus_conn_ref(e->conn);
+ if (activator)
+ *activator = kdbus_conn_ref(e->activator);
+ if (name_id)
+ *name_id = e->name_id;
+ }
mutex_unlock(®->lock);
- return e;
+ return e ? 0 : -ESRCH;
}
static int kdbus_name_queue_conn(struct kdbus_conn *conn, u64 flags,
struct kdbus_conn *conn,
struct kdbus_cmd_name_list *cmd);
-struct kdbus_name_entry *kdbus_name_lookup(struct kdbus_name_registry *reg,
- const char *name);
+int kdbus_name_lookup(struct kdbus_name_registry *reg,
+ const char *name,
+ struct kdbus_conn **conn,
+ struct kdbus_conn **activator,
+ u64 *name_id);
void kdbus_name_remove_by_conn(struct kdbus_name_registry *reg,
struct kdbus_conn *conn);