From ba0d3d490fa772d00e8f4a0dda34c858de00e16f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 13 Oct 2024 13:17:26 +0900 Subject: [PATCH] busctl: show information of passed file descriptor --- src/busctl/busctl.c | 10 +++++++--- test/units/TEST-74-AUX-UTILS.busctl.sh | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index 49ba7baa061..1e352a37294 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -21,6 +21,7 @@ #include "fileio.h" #include "format-table.h" #include "glyph-util.h" +#include "json-util.h" #include "log.h" #include "main-func.h" #include "memstream-util.h" @@ -2008,16 +2009,19 @@ static int json_transform_one(sd_bus_message *m, sd_json_variant **ret) { break; } - case SD_BUS_TYPE_UNIX_FD: - r = sd_bus_message_read_basic(m, type, NULL); + case SD_BUS_TYPE_UNIX_FD: { + int fd; + + r = sd_bus_message_read_basic(m, type, &fd); if (r < 0) return bus_log_parse_error(r); - r = sd_json_variant_new_null(&v); + r = json_variant_new_fd_info(&v, fd); if (r < 0) return log_error_errno(r, "Failed to transform fd: %m"); break; + } case SD_BUS_TYPE_ARRAY: case SD_BUS_TYPE_VARIANT: diff --git a/test/units/TEST-74-AUX-UTILS.busctl.sh b/test/units/TEST-74-AUX-UTILS.busctl.sh index eb1f9e265d7..4949f4bac77 100755 --- a/test/units/TEST-74-AUX-UTILS.busctl.sh +++ b/test/units/TEST-74-AUX-UTILS.busctl.sh @@ -46,6 +46,10 @@ busctl call -j \ busctl call --verbose --timeout=60 --expect-reply=yes \ org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \ ListUnitsByPatterns asas 1 "active" 2 "systemd-*.socket" "*.mount" +# show information passed fd +busctl call --json=pretty \ + org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \ + DumpByFileDescriptor | jq busctl emit /org/freedesktop/login1 org.freedesktop.login1.Manager \ PrepareForSleep b false -- 2.47.3