diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-05-26 08:40:12 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-05-31 23:48:47 +0200 |
commit | 2485b7e2b8a66504e0b6f3bfd03dd48ea5629497 (patch) | |
tree | 8d692db73011acb203f8650f8843e8750a217aa0 /src/busctl | |
parent | util: introduce memstream-util (diff) | |
download | systemd-2485b7e2b8a66504e0b6f3bfd03dd48ea5629497.tar.xz systemd-2485b7e2b8a66504e0b6f3bfd03dd48ea5629497.zip |
tree-wide: use memstream-util
Diffstat (limited to 'src/busctl')
-rw-r--r-- | src/busctl/busctl.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index 4d69aee5eb..b1ea0dea56 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -21,6 +21,7 @@ #include "json.h" #include "log.h" #include "main-func.h" +#include "memstream-util.h" #include "os-util.h" #include "pager.h" #include "parse-argument.h" @@ -1035,12 +1036,12 @@ static int introspect(int argc, char **argv, void *userdata) { return bus_log_parse_error(r); for (;;) { - _cleanup_fclose_ FILE *mf = NULL; + _cleanup_(memstream_done) MemStream ms = {}; _cleanup_free_ char *buf = NULL; const char *name, *contents; - size_t sz = 0; Member *z; char type; + FILE *mf; r = sd_bus_message_enter_container(reply, 'e', "sv"); if (r < 0) @@ -1062,7 +1063,7 @@ static int introspect(int argc, char **argv, void *userdata) { if (r < 0) return bus_log_parse_error(r); - mf = open_memstream_unlocked(&buf, &sz); + mf = memstream_init(&ms); if (!mf) return log_oom(); @@ -1070,10 +1071,9 @@ static int introspect(int argc, char **argv, void *userdata) { if (r < 0) return bus_log_parse_error(r); - mf = safe_fclose(mf); - - if (!buf) - return bus_log_parse_error(ENOMEM); + r = memstream_finalize(&ms, &buf, NULL); + if (r < 0) + return log_error_errno(r, "Failed to flush and close memstream: %m"); z = set_get(members, &((Member) { .type = "property", |