chiark / gitweb /
resolved: destroy outstanding queries if the clients that initiated them die
authorLennart Poettering <lennart@poettering.net>
Wed, 6 Aug 2014 14:32:55 +0000 (16:32 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 11 Aug 2014 13:06:22 +0000 (15:06 +0200)
src/resolve/resolved-bus.c
src/resolve/resolved-dns-query.c
src/resolve/resolved-dns-query.h

index 89a9300..6a3343e 100644 (file)
@@ -319,6 +319,10 @@ static int bus_method_resolve_hostname(sd_bus *bus, sd_bus_message *message, voi
         q->request_hostname = hostname;
         q->complete = bus_method_resolve_hostname_complete;
 
+        r = dns_query_bus_track(q, bus, message);
+        if (r < 0)
+                return r;
+
         r = dns_query_go(q);
         if (r < 0) {
                 dns_query_free(q);
@@ -457,6 +461,10 @@ static int bus_method_resolve_address(sd_bus *bus, sd_bus_message *message, void
         memcpy(&q->request_address, d, sz);
         q->complete = bus_method_resolve_address_complete;
 
+        r = dns_query_bus_track(q, bus, message);
+        if (r < 0)
+                return r;
+
         r = dns_query_go(q);
         if (r < 0) {
                 dns_query_free(q);
@@ -593,6 +601,10 @@ static int bus_method_resolve_record(sd_bus *bus, sd_bus_message *message, void
         q->request_hostname = name;
         q->complete = bus_method_resolve_record_complete;
 
+        r = dns_query_bus_track(q, bus, message);
+        if (r < 0)
+                return r;
+
         r = dns_query_go(q);
         if (r < 0) {
                 dns_query_free(q);
index ae285ef..6d77c10 100644 (file)
@@ -54,6 +54,7 @@ DnsQuery *dns_query_free(DnsQuery *q) {
         dns_answer_unref(q->answer);
 
         sd_bus_message_unref(q->request);
+        sd_bus_track_unref(q->bus_track);
 
         if (q->manager) {
                 LIST_REMOVE(queries, q->manager->dns_queries, q);
@@ -450,3 +451,33 @@ int dns_query_cname_redirect(DnsQuery *q, const char *name) {
 
         return 0;
 }
+
+static int on_bus_track(sd_bus_track *t, void *userdata) {
+        DnsQuery *q = userdata;
+
+        assert(t);
+        assert(q);
+
+        log_debug("Client of active query vanished, aborting query.");
+        dns_query_complete(q, DNS_TRANSACTION_ABORTED);
+        return 0;
+}
+
+int dns_query_bus_track(DnsQuery *q, sd_bus *bus, sd_bus_message *m) {
+        int r;
+
+        assert(q);
+        assert(m);
+
+        if (!q->bus_track) {
+                r = sd_bus_track_new(bus, &q->bus_track, on_bus_track, q);
+                if (r < 0)
+                        return r;
+        }
+
+        r = sd_bus_track_add_sender(q->bus_track, m);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
index adaf7b2..50fa3a2 100644 (file)
@@ -63,6 +63,8 @@ struct DnsQuery {
 
         Set *transactions;
 
+        sd_bus_track *bus_track;
+
         LIST_FIELDS(DnsQuery, queries);
 };
 
@@ -74,4 +76,6 @@ void dns_query_ready(DnsQuery *q);
 
 int dns_query_cname_redirect(DnsQuery *q, const char *name);
 
+int dns_query_bus_track(DnsQuery *q, sd_bus *bus, sd_bus_message *m);
+
 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuery*, dns_query_free);