summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/sd-bus.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-05-19 18:39:08 +0200
committerLennart Poettering <lennart@poettering.net>2013-05-20 10:13:38 +0200
commitc78196699d3d805b2237896a1d2b8efeec6068d0 (patch)
tree91a473710b96a395b4c7543d85c08e73bad13cab /src/libsystemd-bus/sd-bus.c
parent12f25b6e741bc8394f63778598fc203e3f6d4ae6 (diff)
bus: calculate bloom filter for match
Yay! Filtering using kernel bloom filter matches works now! Yippieh!
Diffstat (limited to 'src/libsystemd-bus/sd-bus.c')
-rw-r--r--src/libsystemd-bus/sd-bus.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 6033aa744f..7ae32036bd 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -2404,6 +2404,9 @@ int sd_bus_remove_fallback(sd_bus *bus, const char *prefix, sd_bus_message_handl
}
int sd_bus_add_match(sd_bus *bus, const char *match, sd_bus_message_handler_t callback, void *userdata) {
+ struct bus_match_component *components = NULL;
+ unsigned n_components = 0;
+ uint64_t cookie = 0;
int r = 0;
if (!bus)
@@ -2413,27 +2416,35 @@ int sd_bus_add_match(sd_bus *bus, const char *match, sd_bus_message_handler_t ca
if (bus_pid_changed(bus))
return -ECHILD;
+ r = bus_match_parse(match, &components, &n_components);
+ if (r < 0)
+ goto finish;
+
if (bus->bus_client) {
- r = bus_add_match_internal(bus, match);
+ cookie = ++bus->match_cookie;
+
+ r = bus_add_match_internal(bus, match, components, n_components, cookie);
if (r < 0)
- return r;
+ goto finish;
}
- if (callback) {
- bus->match_callbacks_modified = true;
- r = bus_match_add(&bus->match_callbacks, match, callback, userdata, NULL);
- if (r < 0) {
-
- if (bus->bus_client)
- bus_remove_match_internal(bus, match);
- }
+ bus->match_callbacks_modified = true;
+ r = bus_match_add(&bus->match_callbacks, components, n_components, callback, userdata, cookie, NULL);
+ if (r < 0) {
+ if (bus->bus_client)
+ bus_remove_match_internal(bus, match, cookie);
}
+finish:
+ bus_match_parse_free(components, n_components);
return r;
}
int sd_bus_remove_match(sd_bus *bus, const char *match, sd_bus_message_handler_t callback, void *userdata) {
+ struct bus_match_component *components = NULL;
+ unsigned n_components = 0;
int r = 0, q = 0;
+ uint64_t cookie = 0;
if (!bus)
return -EINVAL;
@@ -2442,17 +2453,19 @@ int sd_bus_remove_match(sd_bus *bus, const char *match, sd_bus_message_handler_t
if (bus_pid_changed(bus))
return -ECHILD;
+ r = bus_match_parse(match, &components, &n_components);
+ if (r < 0)
+ return r;
+
+ bus->match_callbacks_modified = true;
+ r = bus_match_remove(&bus->match_callbacks, components, n_components, callback, userdata, &cookie);
+
if (bus->bus_client)
- r = bus_remove_match_internal(bus, match);
+ q = bus_remove_match_internal(bus, match, cookie);
- if (callback) {
- bus->match_callbacks_modified = true;
- q = bus_match_remove(&bus->match_callbacks, match, callback, userdata);
- }
+ bus_match_parse_free(components, n_components);
- if (r < 0)
- return r;
- return q;
+ return r < 0 ? r : q;
}
int sd_bus_emit_signal(