return 0;
}
-static int find_nodes(sd_bus *bus, const char *service, const char *path, Set *paths, bool many) {
+static int find_nodes(sd_bus *bus, const char *service, const char *path, Set *paths) {
static const XMLIntrospectOps ops = {
.on_path = on_path,
};
"org.freedesktop.DBus.Introspectable", "Introspect",
&error, &reply, "");
if (r < 0) {
- if (many)
- printf("Failed to introspect object %s of service %s: %s\n",
- path, service, bus_error_message(&error, r));
- else
- log_error_errno(r, "Failed to introspect object %s of service %s: %s",
- path, service, bus_error_message(&error, r));
+ printf("%sFailed to introspect object %s of service %s: %s%s\n",
+ ansi_highlight_red(),
+ path, service, bus_error_message(&error, r),
+ ansi_normal());
return r;
}
return parse_xml_introspect(path, xml, &ops, paths);
}
-static int tree_one(sd_bus *bus, const char *service, const char *prefix, bool many) {
+static int tree_one(sd_bus *bus, const char *service, const char *prefix) {
_cleanup_set_free_ Set *paths = NULL, *done = NULL, *failed = NULL;
_cleanup_free_ char **l = NULL;
int r;
set_contains(failed, p))
continue;
- q = find_nodes(bus, service, p, paths, many);
+ q = find_nodes(bus, service, p, paths);
if (q < 0 && r >= 0)
r = q;
char **i;
int r = 0;
+ /* Do superficial verification of arguments before even opening the bus */
+ STRV_FOREACH(i, strv_skip(argv, 1))
+ if (!sd_bus_service_name_is_valid(*i))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid bus service name: %s", *i);
+
if (!arg_unique && !arg_acquired)
arg_acquired = true;
printf("Service %s%s%s:\n", ansi_highlight(), *i, ansi_normal());
- q = tree_one(bus, *i, NULL, true);
+ q = tree_one(bus, *i, NULL);
if (q < 0 && r >= 0)
r = q;
not_first = true;
}
- } else {
- STRV_FOREACH(i, argv+1) {
+ } else
+ STRV_FOREACH(i, strv_skip(argv, 1)) {
int q;
if (i > argv+1)
printf("Service %s%s%s:\n", ansi_highlight(), *i, ansi_normal());
}
- q = tree_one(bus, *i, NULL, !!argv[2]);
+ q = tree_one(bus, *i, NULL);
if (q < 0 && r >= 0)
r = q;
}
- }
return r;
}