]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bus-util: do not reset the count returned by sd_bus_track_count_name()
authorMike Yuan <me@yhndnzj.com>
Sat, 11 Jan 2025 15:26:55 +0000 (16:26 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 9 Oct 2025 11:22:30 +0000 (13:22 +0200)
Follow-up for 8402ca04d1a063c3d8a9e3d5c16df8bb8778ae98

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

(cherry picked from commit 33eeea4128f31df7ab4bd8866b582062d70114ae)

src/shared/bus-util.c

index 2cdde97b789245babdb00095a967117fcd8dda7a..d8db2bf9bb381f7596626548536068c8d8b2ef95 100644 (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) {