1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

sd-bus: let bus_match_dump() take an output file

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-03-04 21:20:00 +01:00
parent 5963e6f43c
commit fc561c8eac
4 changed files with 16 additions and 14 deletions

View 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) {

View 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);

View 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;

View 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);