From bdff06de069fc83f18a126bf6b899ae2341572c3 Mon Sep 17 00:00:00 2001 From: Sebastian Scheibner Date: Fri, 22 May 2020 10:37:43 +0200 Subject: [PATCH 1/2] busctl: Fix warning about invaild introspection data The set_put function returns 0 if the element is already in the set and not EEXIST, like e.g. hashmap does. --- src/busctl/busctl.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index 0f97015bd4..c637d084e7 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -809,8 +809,9 @@ static int on_interface(const char *interface, uint64_t flags, void *userdata) { return log_oom(); r = set_put(members, m); - if (r == -EEXIST) - return log_error_errno(r, "Invalid introspection data: duplicate interface '%s'.", interface); + if (r == 0) + return log_error_errno(SYNTHETIC_ERRNO(EEXIST), + "Invalid introspection data: duplicate interface '%s'.", interface); if (r < 0) return log_oom(); @@ -852,8 +853,9 @@ static int on_method(const char *interface, const char *name, const char *signat return log_oom(); r = set_put(members, m); - if (r == -EEXIST) - return log_error_errno(r, "Invalid introspection data: duplicate method '%s' on interface '%s'.", name, interface); + if (r == 0) + return log_error_errno(SYNTHETIC_ERRNO(EEXIST), + "Invalid introspection data: duplicate method '%s' on interface '%s'.", name, interface); if (r < 0) return log_oom(); @@ -891,8 +893,9 @@ static int on_signal(const char *interface, const char *name, const char *signat return log_oom(); r = set_put(members, m); - if (r == -EEXIST) - return log_error_errno(r, "Invalid introspection data: duplicate signal '%s' on interface '%s'.", name, interface); + if (r == 0) + return log_error_errno(SYNTHETIC_ERRNO(EEXIST), + "Invalid introspection data: duplicate signal '%s' on interface '%s'.", name, interface); if (r < 0) return log_oom(); @@ -931,8 +934,9 @@ static int on_property(const char *interface, const char *name, const char *sign return log_oom(); r = set_put(members, m); - if (r == -EEXIST) - return log_error_errno(r, "Invalid introspection data: duplicate property '%s' on interface '%s'.", name, interface); + if (r == 0) + return log_error_errno(SYNTHETIC_ERRNO(EEXIST), + "Invalid introspection data: duplicate property '%s' on interface '%s'.", name, interface); if (r < 0) return log_oom(); From f2f7785d7a47ffa48ac929648794e1288509ddd8 Mon Sep 17 00:00:00 2001 From: Sebastian Scheibner Date: Sun, 17 May 2020 14:52:10 +0200 Subject: [PATCH 2/2] busctl: Add introspect support for methods with same name but different signature D-Bus interfaces can have multiple methods with the same name, as long as they have different arguments (signature). Currently busctl can call those methods but when introspecting the interface it just displays "Duplicate method" This PR fixes the behavior, by also adding the signature to the hash for the members set. Before this patch: $ busctl introspect org.asamk.Signal /org/asamk/Signal Invalid introspection data: duplicate method 'sendMessage' on interface 'org.asamk.Signal'. After this patch: $ busctl introspect org.asamk.Signal /org/asamk/Signal NAME TYPE SIGNATURE RESULT/VALUE FLAGS org.asamk.Signal interface - - - .sendMessage method as x - .sendMessage method s x - Calling the methods already works as expected, as the user must specify the signature explicitely: busctl --user call org.asamk.Signal /org/asamk/Signal org.asamk.Signal sendMessage "as" 2 foo bar busctl --user call org.asamk.Signal /org/asamk/Signal org.asamk.Signal sendMessage "s" foo $ busctl --xml introspect org.asamk.Signal /org/asamk/Signal --- src/busctl/busctl.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index c637d084e7..a6dbf0ddb5 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -742,6 +742,9 @@ static void member_hash_func(const Member *m, struct siphash *state) { if (m->name) string_hash_func(m->name, state); + if (m->signature) + string_hash_func(m->signature, state); + if (m->interface) string_hash_func(m->interface, state); } @@ -762,7 +765,11 @@ static int member_compare_func(const Member *x, const Member *y) { if (d != 0) return d; - return strcmp_ptr(x->name, y->name); + d = strcmp_ptr(x->name, y->name); + if (d != 0) + return d; + + return strcmp_ptr(x->signature, y->signature); } static int member_compare_funcp(Member * const *a, Member * const *b) {