]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: let bus_match_dump() take an output file
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 4 Mar 2021 20:20:00 +0000 (21:20 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 6 Mar 2021 08:32:18 +0000 (09:32 +0100)
src/libsystemd/sd-bus/bus-match.c
src/libsystemd/sd-bus/bus-match.h
src/libsystemd/sd-bus/test-bus-chat.c
src/libsystemd/sd-bus/test-bus-match.c

index 2a3e7039a7b276d8e5d7a28303c1647bdf7c468c..f624d1ab3ca8b2c1816a226f0a76600efaa6ef2e 100644 (file)
@@ -1016,7 +1016,7 @@ const char* bus_match_node_type_to_string(enum bus_match_node_type t, char buf[]
         }
 }
 
-void bus_match_dump(struct bus_match_node *node, unsigned level) {
+void bus_match_dump(FILE *out, struct bus_match_node *node, unsigned level) {
         _cleanup_free_ char *pfx = NULL;
         char buf[32];
 
@@ -1024,29 +1024,29 @@ void bus_match_dump(struct bus_match_node *node, unsigned level) {
                 return;
 
         pfx = strrep("  ", level);
-        printf("%s[%s]", strempty(pfx), bus_match_node_type_to_string(node->type, buf, sizeof(buf)));
+        fprintf(out, "%s[%s]", strempty(pfx), bus_match_node_type_to_string(node->type, buf, sizeof(buf)));
 
         if (node->type == BUS_MATCH_VALUE) {
                 if (node->parent->type == BUS_MATCH_MESSAGE_TYPE)
-                        printf(" <%u>\n", node->value.u8);
+                        fprintf(out, " <%u>\n", node->value.u8);
                 else
-                        printf(" <%s>\n", node->value.str);
+                        fprintf(out, " <%s>\n", node->value.str);
         } else if (node->type == BUS_MATCH_ROOT)
-                puts(" root");
+                fputs(" root\n", out);
         else if (node->type == BUS_MATCH_LEAF)
-                printf(" %p/%p\n", node->leaf.callback->callback,
-                       container_of(node->leaf.callback, sd_bus_slot, match_callback)->userdata);
+                fprintf(out, " %p/%p\n", node->leaf.callback->callback,
+                        container_of(node->leaf.callback, sd_bus_slot, match_callback)->userdata);
         else
-                putchar('\n');
+                putc('\n', out);
 
         if (BUS_MATCH_CAN_HASH(node->type)) {
                 struct bus_match_node *c;
                 HASHMAP_FOREACH(c, node->compare.children)
-                        bus_match_dump(c, level + 1);
+                        bus_match_dump(out, c, level + 1);
         }
 
         for (struct bus_match_node *c = node->child; c; c = c->next)
-                bus_match_dump(c, level + 1);
+                bus_match_dump(out, c, level + 1);
 }
 
 enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, unsigned n_components) {
index d079f6aec7f76a469fd8deb308e67e2e9641155a..6042f90fbaa4bad23cea67de92f0cb4f748ddc75 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include <stdio.h>
+
 #include "sd-bus.h"
 
 #include "hashmap.h"
@@ -68,7 +70,7 @@ int bus_match_remove(struct bus_match_node *root, struct match_callback *callbac
 
 void bus_match_free(struct bus_match_node *node);
 
-void bus_match_dump(struct bus_match_node *node, unsigned level);
+void bus_match_dump(FILE *out, struct bus_match_node *node, unsigned level);
 
 const char* bus_match_node_type_to_string(enum bus_match_node_type t, char buf[], size_t l);
 enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n);
index ba367677cf8d65819755f4e122bd4b1067d413b7..df6dd62151d9e27faee4f4f43a49579eb68e483a 100644 (file)
@@ -101,7 +101,7 @@ static int server_init(sd_bus **_bus) {
                 goto fail;
         }
 
-        bus_match_dump(&bus->match_callbacks, 0);
+        bus_match_dump(stdout, &bus->match_callbacks, 0);
 
         *_bus = bus;
         return 0;
index 031e42ff46bebb1998c2ac31d250fd112bdd1898..701476ed03472c8dc1a7acf9e01689f0f1cba6a1 100644 (file)
@@ -105,7 +105,7 @@ int main(int argc, char *argv[]) {
         assert_se(match_add(slots, &root, "arg4has='po'", 17) >= 0);
         assert_se(match_add(slots, &root, "arg4='pi'", 18) >= 0);
 
-        bus_match_dump(&root, 0);
+        bus_match_dump(stdout, &root, 0);
 
         assert_se(sd_bus_message_new_signal(bus, &m, "/foo/bar", "bar.x", "waldo") >= 0);
         assert_se(sd_bus_message_append(m, "ssssas", "one", "two", "/prefix/three", "prefix.four", 3, "pi", "pa", "po") >= 0);
@@ -118,7 +118,7 @@ int main(int argc, char *argv[]) {
         assert_se(bus_match_remove(&root, &slots[8].match_callback) >= 0);
         assert_se(bus_match_remove(&root, &slots[13].match_callback) >= 0);
 
-        bus_match_dump(&root, 0);
+        bus_match_dump(stdout, &root, 0);
 
         zero(mask);
         assert_se(bus_match_run(NULL, &root, m) == 0);