bus-util: do not reset the count returned by sd_bus_track_count_name()

Follow-up for 8402ca04d1

While at it, turn the retval check for sd_bus_track_count_name()
into assertion, given we're working with already established tracks
(service_name_is_valid() should never yield false in this case).

Addresses https://github.com/systemd/systemd/pull/35406#discussion_r1912066774
This commit is contained in:
Mike Yuan
2025-01-11 16:26:55 +01:00
parent 38a2c2bf6a
commit 33eeea4128

View File

@@ -700,16 +700,15 @@ int bus_track_add_name_many(sd_bus_track *t, char **l) {
int bus_track_to_strv(sd_bus_track *t, char ***ret) {
_cleanup_strv_free_ char **subscribed = NULL;
int r = 0;
int r;
assert(ret);
for (const char *n = sd_bus_track_first(t); n; n = sd_bus_track_next(t)) {
r = sd_bus_track_count_name(t, n);
if (r < 0)
return r;
int c = sd_bus_track_count_name(t, n);
assert(c >= 0);
for (int j = 0; j < r; j++) {
for (int j = 0; j < c; j++) {
r = strv_extend(&subscribed, n);
if (r < 0)
return r;
@@ -717,7 +716,7 @@ int bus_track_to_strv(sd_bus_track *t, char ***ret) {
}
*ret = TAKE_PTR(subscribed);
return r;
return 0;
}
int bus_open_system_watch_bind_with_description(sd_bus **ret, const char *description) {