summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r--src/libsystemd-bus/bus-control.c18
-rw-r--r--src/libsystemd-bus/bus-control.h3
-rw-r--r--src/libsystemd-bus/bus-match.c40
-rw-r--r--src/libsystemd-bus/bus-match.h1
4 files changed, 53 insertions, 9 deletions
diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index b51007d1e2..b8f6360fb7 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -851,7 +851,7 @@ static int add_name_change_match(sd_bus *bus,
item = m->items;
item->size = offsetof(struct kdbus_item, id_change) + sizeof(struct kdbus_notify_id_change);
- item->id_change.id = name_id;
+ /* item->id_change.id = name_id; */
/* If the old name is unset or empty, then this can
* match against added ids */
@@ -877,9 +877,9 @@ static int add_name_change_match(sd_bus *bus,
return 0;
}
-static int bus_add_match_internal_kernel(
+int bus_add_match_internal_kernel(
sd_bus *bus,
- const char *match,
+ uint64_t id,
struct bus_match_component *components,
unsigned n_components,
uint64_t cookie) {
@@ -898,7 +898,6 @@ static int bus_add_match_internal_kernel(
int r;
assert(bus);
- assert(match);
zero(bloom);
@@ -1018,6 +1017,7 @@ static int bus_add_match_internal_kernel(
m->size = sz;
m->cookie = cookie;
m->src_id = src_id;
+ m->id = id;
item = m->items;
@@ -1084,25 +1084,25 @@ int bus_add_match_internal(
assert(match);
if (bus->is_kernel)
- return bus_add_match_internal_kernel(bus, match, components, n_components, cookie);
+ return bus_add_match_internal_kernel(bus, 0, components, n_components, cookie);
else
return bus_add_match_internal_dbus1(bus, match);
}
-static int bus_remove_match_internal_kernel(
+int bus_remove_match_internal_kernel(
sd_bus *bus,
- const char *match,
+ uint64_t id,
uint64_t cookie) {
struct kdbus_cmd_match m;
int r;
assert(bus);
- assert(match);
zero(m);
m.size = offsetof(struct kdbus_cmd_match, items);
m.cookie = cookie;
+ m.id = id;
r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_REMOVE, &m);
if (r < 0)
@@ -1139,7 +1139,7 @@ int bus_remove_match_internal(
assert(match);
if (bus->is_kernel)
- return bus_remove_match_internal_kernel(bus, match, cookie);
+ return bus_remove_match_internal_kernel(bus, 0, cookie);
else
return bus_remove_match_internal_dbus1(bus, match);
}
diff --git a/src/libsystemd-bus/bus-control.h b/src/libsystemd-bus/bus-control.h
index 2cac5d83ae..b610bef842 100644
--- a/src/libsystemd-bus/bus-control.h
+++ b/src/libsystemd-bus/bus-control.h
@@ -25,3 +25,6 @@
int bus_add_match_internal(sd_bus *bus, const char *match, struct bus_match_component *components, unsigned n_components, uint64_t cookie);
int bus_remove_match_internal(sd_bus *bus, const char *match, uint64_t cookie);
+
+int bus_add_match_internal_kernel(sd_bus *bus, uint64_t id, struct bus_match_component *components, unsigned n_components, uint64_t cookie);
+int bus_remove_match_internal_kernel(sd_bus *bus, uint64_t id, uint64_t cookie);
diff --git a/src/libsystemd-bus/bus-match.c b/src/libsystemd-bus/bus-match.c
index 342819d9c0..7638f2038b 100644
--- a/src/libsystemd-bus/bus-match.c
+++ b/src/libsystemd-bus/bus-match.c
@@ -816,6 +816,46 @@ fail:
return r;
}
+char *bus_match_to_string(struct bus_match_component *components, unsigned n_components) {
+ _cleanup_free_ FILE *f = NULL;
+ char *buffer = NULL;
+ size_t size = 0;
+ unsigned i;
+
+ if (n_components <= 0)
+ return strdup("");
+
+ assert(components);
+
+ f = open_memstream(&buffer, &size);
+ if (!f)
+ return NULL;
+
+ for (i = 0; i < n_components; i++) {
+ char buf[32];
+
+ if (i != 0)
+ fputc(',', f);
+
+ fputs(bus_match_node_type_to_string(components[i].type, buf, sizeof(buf)), f);
+ fputc('=', f);
+ fputc('\'', f);
+
+ if (components[i].type == BUS_MATCH_MESSAGE_TYPE)
+ fputs(bus_message_type_to_string(components[i].value_u8), f);
+ else
+ fputs(components[i].value_str, f);
+
+ fputc('\'', f);
+ }
+
+ fflush(f);
+ if (ferror(f))
+ return NULL;
+
+ return buffer;
+}
+
int bus_match_add(
struct bus_match_node *root,
struct bus_match_component *components,
diff --git a/src/libsystemd-bus/bus-match.h b/src/libsystemd-bus/bus-match.h
index 1d38126600..056082b908 100644
--- a/src/libsystemd-bus/bus-match.h
+++ b/src/libsystemd-bus/bus-match.h
@@ -90,3 +90,4 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n
int bus_match_parse(const char *match, struct bus_match_component **_components, unsigned *_n_components);
void bus_match_parse_free(struct bus_match_component *components, unsigned n_components);
+char *bus_match_to_string(struct bus_match_component *components, unsigned n_components);