static int list_bus_names(sd_bus *bus, char **argv) { _cleanup_strv_free_ char **acquired = NULL, **activatable = NULL; _cleanup_free_ char **merged = NULL; _cleanup_hashmap_free_ Hashmap *names = NULL; char **i; int r; size_t max_i = 0; unsigned n = 0; void *v; char *k; Iterator iterator; assert(bus); r = sd_bus_list_names(bus, (arg_acquired || arg_unique) ? &acquired : NULL, arg_activatable ? &activatable : NULL); if (r < 0) { log_error("Failed to list names: %s", strerror(-r)); return r; } pager_open_if_enabled(); names = hashmap_new(&string_hash_ops); if (!names) return log_oom(); STRV_FOREACH(i, acquired) { max_i = MAX(max_i, strlen(*i)); r = hashmap_put(names, *i, INT_TO_PTR(1)); if (r < 0) { log_error("Failed to add to hashmap: %s", strerror(-r)); return r; } }
static int driver_list_activatable_names(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) { _cleanup_strv_free_ char **names = NULL; int r; r = sd_bus_list_names(bus, NULL, &names); if (r < 0) return r; /* Let's sort the names list to make it stable */ strv_sort(names); return return_strv(bus, m, names); }