diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-12-23 22:42:55 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-12-23 22:44:32 +0100 |
commit | 4f44c03eaa7bc05240ef619d07766f61eda3d5b7 (patch) | |
tree | 76ded00d769ff9f5718c892cb8000f2d9a87672e | |
parent | 56a32c94ca0c76a2bd0de8dd644863d341b9f504 (diff) |
busctl: when introspecting objects, optionally limit output by interface name
-rw-r--r-- | man/busctl.xml | 6 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/busctl.c | 26 |
2 files changed, 26 insertions, 6 deletions
diff --git a/man/busctl.xml b/man/busctl.xml index 285725e684..c8a087c5c5 100644 --- a/man/busctl.xml +++ b/man/busctl.xml @@ -313,11 +313,13 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. </varlistentry> <varlistentry> - <term><command>introspect</command> <arg choice="plain"><replaceable>SERVICE</replaceable></arg> <arg choice="plain"><replaceable>OBJECT</replaceable></arg></term> + <term><command>introspect</command> <arg choice="plain"><replaceable>SERVICE</replaceable></arg> <arg choice="plain"><replaceable>OBJECT</replaceable></arg> <arg choice="opt"><replaceable>INTERFACE</replaceable></arg></term> <listitem><para>Show interfaces, methods, properties and signals of the specified object (identified by its path) on - the specified service.</para></listitem> + the specified service. If the interface argument is passed the + output is limited to members of the specified + interface.</para></listitem> </varlistentry> <varlistentry> diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c index 3233c1b29b..009739fc0f 100644 --- a/src/libsystemd/sd-bus/busctl.c +++ b/src/libsystemd/sd-bus/busctl.c @@ -883,13 +883,19 @@ static int introspect(sd_bus *bus, char **argv) { int r; unsigned name_width, type_width, signature_width, result_width; Member **sorted = NULL; - unsigned k = 0, j; + unsigned k = 0, j, n_args; - if (strv_length(argv) != 3) { + n_args = strv_length(argv); + if (n_args < 3) { log_error("Requires service and object path argument."); return -EINVAL; } + if (n_args > 4) { + log_error("Too many arguments."); + return -EINVAL; + } + members = set_new(&member_hash_ops); if (!members) return log_oom(); @@ -918,6 +924,9 @@ static int introspect(sd_bus *bus, char **argv) { if (m->value) continue; + if (argv[3] && !streq(argv[3], m->interface)) + continue; + r = sd_bus_call_method(bus, argv[1], argv[2], "org.freedesktop.DBus.Properties", "GetAll", &error, &reply, "s", m->interface); if (r < 0) { log_error("%s", bus_error_message(&error, r)); @@ -995,6 +1004,10 @@ static int introspect(sd_bus *bus, char **argv) { sorted = newa(Member*, set_size(members)); SET_FOREACH(m, members, i) { + + if (argv[3] && !streq(argv[3], m->interface)) + continue; + if (m->interface) name_width = MAX(name_width, strlen(m->interface)); if (m->name) @@ -1014,7 +1027,6 @@ static int introspect(sd_bus *bus, char **argv) { if (result_width > 40) result_width = 40; - assert(k == set_size(members)); qsort(sorted, k, sizeof(Member*), member_compare_funcp); if (arg_legend) { @@ -1033,8 +1045,14 @@ static int introspect(sd_bus *bus, char **argv) { m = sorted[j]; + if (argv[3] && !streq(argv[3], m->interface)) + continue; + is_interface = streq(m->type, "interface"); + if (argv[3] && is_interface) + continue; + if (m->value) { ellipsized = ellipsize(m->value, result_width, 100); if (!ellipsized) @@ -1686,7 +1704,7 @@ static int help(void) { " monitor [SERVICE...] Show bus traffic\n" " capture [SERVICE...] Capture bus traffic as pcap\n" " tree [SERVICE...] Show object tree of service\n" - " introspect SERVICE OBJECT\n" + " introspect SERVICE OBJECT [INTERFACE]\n" " call SERVICE OBJECT INTERFACE METHOD [SIGNATURE [ARGUMENT...]]\n" " Call a method\n" " get-property SERVICE OBJECT INTERFACE PROPERTY...\n" |