Kdbus can use a "name," instead of id, directly as a destination of
message, while Android has an external service manager which is some kind
of (service-)name lookup agent.
By adding lookup_name() to kdbus utility, I'd like to retain the similarity
between binder's and kdbus's bencharmk programs aiming to merge both into
one in the future.

Signed-off-by: AKASHI Takahiro <[email protected]>
---
 test/kdbus-util.c |   38 ++++++++++++++++++++++++++++++++++++++
 test/kdbus-util.h |    1 +
 2 files changed, 39 insertions(+)

diff --git a/test/kdbus-util.c b/test/kdbus-util.c
index 6c2c5db..2cac8be 100644
--- a/test/kdbus-util.c
+++ b/test/kdbus-util.c
@@ -605,6 +605,44 @@ int name_list(struct conn *conn, uint64_t flags)
        return 0;
 }
 
+int64_t lookup_name(struct conn *conn, uint64_t flags, const char *svcname)
+{
+       struct kdbus_cmd_name_list cmd_list;
+       struct kdbus_name_list *list;
+       struct kdbus_cmd_name *name;
+       int ret;
+       int64_t id = -1;
+
+       cmd_list.flags = flags;
+
+       ret = ioctl(conn->fd, KDBUS_CMD_NAME_LIST, &cmd_list);
+       if (ret < 0) {
+               fprintf(stderr, "error listing names: %d (%m)\n", ret);
+               return EXIT_FAILURE;
+       }
+
+       printf("REGISTRY:\n");
+       list = (struct kdbus_name_list *)(conn->buf + cmd_list.offset);
+       KDBUS_ITEM_FOREACH(name, list, names) {
+               printf("%8llu flags=0x%08llx conn=0x%08llx '%s'\n", 
name->owner_id,
+                      name->flags, name->conn_flags,
+                      name->size > sizeof(struct kdbus_cmd_name) ? name->name 
: "");
+               if (!strcmp(svcname, name->name)) {
+                       id = name->owner_id;
+                       break;
+               }
+       }
+       printf("\n");
+
+       ret = ioctl(conn->fd, KDBUS_CMD_FREE, &cmd_list.offset);
+       if (ret < 0) {
+               fprintf(stderr, "error free name list: %d (%m)\n", ret);
+               return EXIT_FAILURE;
+       }
+
+       return id;
+}
+
 void add_match_empty(int fd)
 {
        struct {
diff --git a/test/kdbus-util.h b/test/kdbus-util.h
index acdc34f..be6ccab 100644
--- a/test/kdbus-util.h
+++ b/test/kdbus-util.h
@@ -40,6 +40,7 @@ extern int lib_dump;
 extern int lib_verbose;
 
 int name_list(struct conn *conn, uint64_t flags);
+int64_t lookup_name(struct conn *conn, uint64_t flags, const char *name);
 int name_release(struct conn *conn, const char *name);
 int name_acquire(struct conn *conn, const char *name, uint64_t flags);
 int msg_recv(struct conn *conn);
-- 
1.7.9.5

_______________________________________________
systemd-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to