summaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/reserve-monitor.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/modules/reserve-monitor.c b/src/modules/reserve-monitor.c
index 13ecde2b..97cb9b9e 100644
--- a/src/modules/reserve-monitor.c
+++ b/src/modules/reserve-monitor.c
@@ -38,6 +38,7 @@ struct rm_monitor {
char *device_name;
char *service_name;
+ char *match;
DBusConnection *connection;
@@ -51,6 +52,13 @@ struct rm_monitor {
#define SERVICE_PREFIX "org.freedesktop.ReserveDevice1."
+#define SERVICE_FILTER \
+ "type='signal'," \
+ "sender='" DBUS_SERVICE_DBUS "'," \
+ "interface='" DBUS_INTERFACE_DBUS "'," \
+ "member='NameOwnerChanged'," \
+ "arg0='%s'"
+
static DBusHandlerResult filter_handler(
DBusConnection *c,
DBusMessage *s,
@@ -175,11 +183,13 @@ int rm_watch(
m->filtering = 1;
- dbus_bus_add_match(m->connection,
- "type='signal',"
- "sender='" DBUS_SERVICE_DBUS "',"
- "interface='" DBUS_INTERFACE_DBUS "',"
- "member='NameOwnerChanged'", error);
+ if (!(m->match = malloc(sizeof(SERVICE_FILTER) - 2 + strlen(m->service_name)))) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ sprintf(m->match, SERVICE_FILTER, m->service_name);
+ dbus_bus_add_match(m->connection, m->match, error);
if (dbus_error_is_set(error)) {
r = -EIO;
@@ -220,10 +230,8 @@ void rm_release(rm_monitor *m) {
if (m->matching)
dbus_bus_remove_match(
m->connection,
- "type='signal',"
- "sender='" DBUS_SERVICE_DBUS "',"
- "interface='" DBUS_INTERFACE_DBUS "',"
- "member='NameOwnerChanged'", NULL);
+ m->match,
+ NULL);
if (m->filtering)
dbus_connection_remove_filter(
@@ -233,6 +241,7 @@ void rm_release(rm_monitor *m) {
free(m->device_name);
free(m->service_name);
+ free(m->match);
if (m->connection)
dbus_connection_unref(m->connection);