#include "pager.h"
#include "xml.h"
#include "path-util.h"
+#include "set.h"
#include "sd-bus.h"
#include "bus-message.h"
arg_unique = arg_acquired = arg_activatable = true;
r = sd_bus_list_names(bus, (arg_acquired || arg_unique) ? &acquired : NULL, arg_activatable ? &activatable : NULL);
- if (r < 0) {
- log_error_errno(-r, "Failed to list names: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to list names: %m");
pager_open_if_enabled();
max_i = MAX(max_i, strlen(*i));
r = hashmap_put(names, *i, NAME_IS_ACQUIRED);
- if (r < 0) {
- log_error_errno(-r, "Failed to add to hashmap: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to add to hashmap: %m");
}
STRV_FOREACH(i, activatable) {
max_i = MAX(max_i, strlen(*i));
r = hashmap_put(names, *i, NAME_IS_ACTIVATABLE);
- if (r < 0 && r != -EEXIST) {
- log_error_errno(-r, "Failed to add to hashmap: %m");
- return r;
- }
+ if (r < 0 && r != -EEXIST)
+ return log_error_errno(r, "Failed to add to hashmap: %m");
}
merged = new(char*, hashmap_size(names) + 1);
bool not_first = false;
r = sd_bus_list_names(bus, &names, NULL);
- if (r < 0) {
- log_error_errno(-r, "Failed to get name list: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to get name list: %m");
pager_open_if_enabled();
fprintf(f, "%s", contents);
}
- r = format_cmdline(m, f, true);
+ r = format_cmdline(m, f, needs_space || IN_SET(type, SD_BUS_TYPE_ARRAY, SD_BUS_TYPE_VARIANT));
if (r < 0)
return r;
assert_not_reached("Unknown basic type.");
}
+ needs_space = true;
}
}
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();
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));
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)
if (result_width > 40)
result_width = 40;
- assert(k == set_size(members));
qsort(sorted, k, sizeof(Member*), member_compare_funcp);
if (arg_legend) {
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)
return log_oom();
r = sd_bus_add_match(bus, NULL, m, NULL, NULL);
- if (r < 0) {
- log_error_errno(-r, "Failed to add match: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to add match: %m");
added_something = true;
}
STRV_FOREACH(i, arg_matches) {
r = sd_bus_add_match(bus, NULL, *i, NULL, NULL);
- if (r < 0) {
- log_error_errno(-r, "Failed to add match: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to add match: %m");
added_something = true;
}
if (!added_something) {
r = sd_bus_add_match(bus, NULL, "", NULL, NULL);
- if (r < 0) {
- log_error_errno(-r, "Failed to add match: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to add match: %m");
}
for (;;) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
r = sd_bus_process(bus, &m);
- if (r < 0) {
- log_error_errno(-r, "Failed to process bus: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to process bus: %m");
if (m) {
dump(m, stdout);
continue;
r = sd_bus_wait(bus, (uint64_t) -1);
- if (r < 0) {
- log_error_errno(-r, "Failed to wait for bus: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to wait for bus: %m");
}
}
&creds,
pid,
_SD_BUS_CREDS_ALL);
- } else
+ } else {
+ const char *scope, *address;
+ sd_id128_t bus_id;
+
+ r = sd_bus_get_address(bus, &address);
+ if (r >= 0)
+ printf("BusAddress=%s%s%s\n", ansi_highlight(), address, ansi_highlight_off());
+
+ r = sd_bus_get_scope(bus, &scope);
+ if (r >= 0)
+ printf("BusScope=%s%s%s\n", ansi_highlight(), scope, ansi_highlight_off());
+
+ r = sd_bus_get_bus_id(bus, &bus_id);
+ if (r >= 0)
+ printf("BusID=%s" SD_ID128_FORMAT_STR "%s\n", ansi_highlight(), SD_ID128_FORMAT_VAL(bus_id), ansi_highlight_off());
+
r = sd_bus_get_owner_creds(
bus,
(arg_augment_creds ? SD_BUS_CREDS_AUGMENT : 0) | _SD_BUS_CREDS_ALL,
&creds);
-
- if (r < 0) {
- log_error_errno(-r, "Failed to get credentials: %m");
- return r;
}
+ if (r < 0)
+ return log_error_errno(r, "Failed to get credentials: %m");
+
bus_creds_dump(creds, NULL, false);
return 0;
}
" 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"
r = sd_bus_new(&bus);
if (r < 0) {
- log_error_errno(-r, "Failed to allocate bus: %m");
+ log_error_errno(r, "Failed to allocate bus: %m");
goto finish;
}
r = sd_bus_set_monitor(bus, true);
if (r < 0) {
- log_error_errno(-r, "Failed to set monitor mode: %m");
+ log_error_errno(r, "Failed to set monitor mode: %m");
goto finish;
}
r = sd_bus_negotiate_creds(bus, true, _SD_BUS_CREDS_ALL);
if (r < 0) {
- log_error_errno(-r, "Failed to enable credentials: %m");
+ log_error_errno(r, "Failed to enable credentials: %m");
goto finish;
}
r = sd_bus_negotiate_timestamp(bus, true);
if (r < 0) {
- log_error_errno(-r, "Failed to enable timestamps: %m");
+ log_error_errno(r, "Failed to enable timestamps: %m");
goto finish;
}
r = sd_bus_negotiate_fds(bus, true);
if (r < 0) {
- log_error_errno(-r, "Failed to enable fds: %m");
+ log_error_errno(r, "Failed to enable fds: %m");
goto finish;
}
}
else {
r = sd_bus_set_bus_client(bus, true);
if (r < 0) {
- log_error_errno(-r, "Failed to set bus client: %m");
+ log_error_errno(r, "Failed to set bus client: %m");
goto finish;
}
switch (arg_transport) {
case BUS_TRANSPORT_LOCAL:
- if (arg_user)
+ if (arg_user) {
+ bus->is_user = true;
r = bus_set_address_user(bus);
- else
+ } else {
+ bus->is_system = true;
r = bus_set_address_system(bus);
+ }
break;
case BUS_TRANSPORT_REMOTE:
}
}
if (r < 0) {
- log_error_errno(-r, "Failed to set address: %m");
+ log_error_errno(r, "Failed to set address: %m");
goto finish;
}
r = sd_bus_start(bus);
if (r < 0) {
- log_error_errno(-r, "Failed to connect to bus: %m");
+ log_error_errno(r, "Failed to connect to bus: %m");
goto finish;
}