]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
busctl: use set_dump_sorted() and FOREACH_ARRAY()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Apr 2025 01:17:33 +0000 (10:17 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Apr 2025 03:23:13 +0000 (12:23 +0900)
src/busctl/busctl.c

index 924defd2673b2c6e57ec8270b57518e9a4c7bcca..6eee7541f46b4087778acb8da2aaf83860c982ad 100644 (file)
@@ -791,10 +791,6 @@ static int member_compare_func(const Member *x, const Member *y) {
         return strcmp_ptr(x->signature, y->signature);
 }
 
-static int member_compare_funcp(Member * const *a, Member * const *b) {
-        return member_compare_func(*a, *b);
-}
-
 static Member* member_free(Member *m) {
         if (!m)
                 return NULL;
@@ -1110,9 +1106,6 @@ static int introspect(int argc, char **argv, void *userdata) {
         signature_width = strlen("SIGNATURE");
         result_width = strlen("RESULT/VALUE");
 
-        Member **sorted = newa(Member*, set_size(members));
-        size_t k = 0;
-
         SET_FOREACH(m, members) {
                 if (argv[3] && !streq(argv[3], m->interface))
                         continue;
@@ -1129,14 +1122,16 @@ static int introspect(int argc, char **argv, void *userdata) {
                         result_width = MAX(result_width, strlen(m->result));
                 if (m->value)
                         result_width = MAX(result_width, strlen(m->value));
-
-                sorted[k++] = m;
         }
 
         if (result_width > 40 && arg_full <= 0)
                 result_width = 40;
 
-        typesafe_qsort(sorted, k, member_compare_funcp);
+        size_t n;
+        _cleanup_free_ Member **sorted = NULL;
+        r = set_dump_sorted(members, (void***) &sorted, &n);
+        if (r < 0)
+                return log_oom();
 
         pager_open(arg_pager_flags);
 
@@ -1148,12 +1143,12 @@ static int introspect(int argc, char **argv, void *userdata) {
                        (int) result_width, "RESULT/VALUE",
                        "FLAGS");
 
-        for (size_t j = 0; j < k; j++) {
+        FOREACH_ARRAY(p, sorted, n) {
                 _cleanup_free_ char *ellipsized = NULL;
                 const char *rv;
                 bool is_interface;
 
-                m = sorted[j];
+                m = *p;
 
                 if (argv[3] && !streq(argv[3], m->interface))
                         continue;