ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
ac3a84
From 25e4d71e788ee7467e1d764c631de44d599e2b1c Mon Sep 17 00:00:00 2001
ac3a84
From: Yu Watanabe <watanabe.yu+github@gmail.com>
ac3a84
Date: Fri, 13 Jan 2023 14:12:31 +0900
ac3a84
Subject: [PATCH] busctl: fix introspecting DBus properties
ac3a84
ac3a84
Follow-up for f2f7785d7a47ffa48ac929648794e1288509ddd8.
ac3a84
ac3a84
Fixes #26033.
ac3a84
ac3a84
(cherry picked from commit 2cbb171d20a07ec0a25296f167b0385de102d74e)
ac3a84
ac3a84
Related: #2138081
ac3a84
---
ac3a84
 src/busctl/busctl.c | 21 +++++++++++++++++++--
ac3a84
 1 file changed, 19 insertions(+), 2 deletions(-)
ac3a84
ac3a84
diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c
ac3a84
index f57a5d605d..cc2d0e3458 100644
ac3a84
--- a/src/busctl/busctl.c
ac3a84
+++ b/src/busctl/busctl.c
ac3a84
@@ -1022,10 +1022,11 @@ static int introspect(int argc, char **argv, void *userdata) {
ac3a84
 
ac3a84
                 for (;;) {
ac3a84
                         Member *z;
ac3a84
-                        _cleanup_free_ char *buf = NULL;
ac3a84
+                        _cleanup_free_ char *buf = NULL, *signature = NULL;
ac3a84
                         _cleanup_fclose_ FILE *mf = NULL;
ac3a84
                         size_t sz = 0;
ac3a84
-                        const char *name;
ac3a84
+                        const char *name, *contents;
ac3a84
+                        char type;
ac3a84
 
ac3a84
                         r = sd_bus_message_enter_container(reply, 'e', "sv");
ac3a84
                         if (r < 0)
ac3a84
@@ -1042,6 +1043,21 @@ static int introspect(int argc, char **argv, void *userdata) {
ac3a84
                         if (r < 0)
ac3a84
                                 return bus_log_parse_error(r);
ac3a84
 
ac3a84
+                        r = sd_bus_message_peek_type(reply, &type, &contents);
ac3a84
+                        if (r <= 0)
ac3a84
+                                return bus_log_parse_error(r == 0 ? EINVAL : r);
ac3a84
+
ac3a84
+                        if (type == SD_BUS_TYPE_STRUCT_BEGIN)
ac3a84
+                                signature = strjoin(CHAR_TO_STR(SD_BUS_TYPE_STRUCT_BEGIN), contents, CHAR_TO_STR(SD_BUS_TYPE_STRUCT_END));
ac3a84
+                        else if (type == SD_BUS_TYPE_DICT_ENTRY_BEGIN)
ac3a84
+                                signature = strjoin(CHAR_TO_STR(SD_BUS_TYPE_DICT_ENTRY_BEGIN), contents, CHAR_TO_STR(SD_BUS_TYPE_DICT_ENTRY_END));
ac3a84
+                        else if (contents)
ac3a84
+                                signature = strjoin(CHAR_TO_STR(type), contents);
ac3a84
+                        else
ac3a84
+                                signature = strdup(CHAR_TO_STR(type));
ac3a84
+                        if (!signature)
ac3a84
+                                return log_oom();
ac3a84
+
ac3a84
                         mf = open_memstream_unlocked(&buf, &sz);
ac3a84
                         if (!mf)
ac3a84
                                 return log_oom();
ac3a84
@@ -1055,6 +1071,7 @@ static int introspect(int argc, char **argv, void *userdata) {
ac3a84
                         z = set_get(members, &((Member) {
ac3a84
                                                 .type = "property",
ac3a84
                                                 .interface = m->interface,
ac3a84
+                                                .signature = signature,
ac3a84
                                                 .name = (char*) name }));
ac3a84
                         if (z)
ac3a84
                                 free_and_replace(z->value, buf);