summaryrefslogtreecommitdiff
path: root/src/resolve
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-08-06 16:32:55 +0200
committerLennart Poettering <lennart@poettering.net>2014-08-11 15:06:22 +0200
commit82bd6dddc4a363a9c3c6f41eb46eb171a80dca27 (patch)
tree62c653d001a821d5101e312bcc72076acc4ab019 /src/resolve
parent818f766b12e025683cf4fed12b3da2a025bb0b31 (diff)
resolved: destroy outstanding queries if the clients that initiated them die
Diffstat (limited to 'src/resolve')
-rw-r--r--src/resolve/resolved-bus.c12
-rw-r--r--src/resolve/resolved-dns-query.c31
-rw-r--r--src/resolve/resolved-dns-query.h4
3 files changed, 47 insertions, 0 deletions
diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c
index 89a9300dfb..6a3343e000 100644
--- a/src/resolve/resolved-bus.c
+++ b/src/resolve/resolved-bus.c
@@ -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);
diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c
index ae285ef112..6d77c109b4 100644
--- a/src/resolve/resolved-dns-query.c
+++ b/src/resolve/resolved-dns-query.c
@@ -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;
+}
diff --git a/src/resolve/resolved-dns-query.h b/src/resolve/resolved-dns-query.h
index adaf7b2588..50fa3a2fe2 100644
--- a/src/resolve/resolved-dns-query.h
+++ b/src/resolve/resolved-dns-query.h
@@ -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);