summaryrefslogtreecommitdiff
path: root/src/busctl/busctl.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-01-16 14:16:14 +0100
committerLennart Poettering <lennart@poettering.net>2023-01-16 20:54:44 +0100
commitec56edf55c26ed2c65cf8e86b81ab0b516c94dd9 (patch)
tree6034186a5e3843c3a89225594a448872ba6093df /src/busctl/busctl.c
parentea9dbf51c64337a48f4812213755c1197a50ed7a (diff)
downloadsystemd-ec56edf55c26ed2c65cf8e86b81ab0b516c94dd9.tar.gz
busctl: simplify peeking the type
let's peek the type before we enter the variant, not after, so that we can reuse it as-is, instead having to recombine it later. Follow-up for: #26049
Diffstat (limited to 'src/busctl/busctl.c')
-rw-r--r--src/busctl/busctl.c30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c
index 2b5552889b..87becdbc7e 100644
--- a/src/busctl/busctl.c
+++ b/src/busctl/busctl.c
@@ -1022,17 +1022,16 @@ static int introspect(int argc, char **argv, void *userdata) {
return bus_log_parse_error(r);
for (;;) {
- Member *z;
- _cleanup_free_ char *buf = NULL, *signature = NULL;
_cleanup_fclose_ FILE *mf = NULL;
- size_t sz = 0;
+ _cleanup_free_ char *buf = NULL;
const char *name, *contents;
+ size_t sz = 0;
+ Member *z;
char type;
r = sd_bus_message_enter_container(reply, 'e', "sv");
if (r < 0)
return bus_log_parse_error(r);
-
if (r == 0)
break;
@@ -1040,24 +1039,15 @@ static int introspect(int argc, char **argv, void *userdata) {
if (r < 0)
return bus_log_parse_error(r);
- r = sd_bus_message_enter_container(reply, 'v', NULL);
+ r = sd_bus_message_peek_type(reply, &type, &contents);
if (r < 0)
return bus_log_parse_error(r);
+ if (type != 'v')
+ return bus_log_parse_error(EINVAL);
- r = sd_bus_message_peek_type(reply, &type, &contents);
- if (r <= 0)
- return bus_log_parse_error(r == 0 ? EINVAL : r);
-
- if (type == SD_BUS_TYPE_STRUCT_BEGIN)
- signature = strjoin(CHAR_TO_STR(SD_BUS_TYPE_STRUCT_BEGIN), contents, CHAR_TO_STR(SD_BUS_TYPE_STRUCT_END));
- else if (type == SD_BUS_TYPE_DICT_ENTRY_BEGIN)
- signature = strjoin(CHAR_TO_STR(SD_BUS_TYPE_DICT_ENTRY_BEGIN), contents, CHAR_TO_STR(SD_BUS_TYPE_DICT_ENTRY_END));
- else if (contents)
- signature = strjoin(CHAR_TO_STR(type), contents);
- else
- signature = strdup(CHAR_TO_STR(type));
- if (!signature)
- return log_oom();
+ r = sd_bus_message_enter_container(reply, 'v', contents);
+ if (r < 0)
+ return bus_log_parse_error(r);
mf = open_memstream_unlocked(&buf, &sz);
if (!mf)
@@ -1072,7 +1062,7 @@ static int introspect(int argc, char **argv, void *userdata) {
z = set_get(members, &((Member) {
.type = "property",
.interface = m->interface,
- .signature = signature,
+ .signature = (char*) contents,
.name = (char*) name }));
if (z)
free_and_replace(z->value, buf);