From 902bb5d8abb2a7d258741828d212ca549ab16950 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 6 Aug 2014 16:59:48 +0200 Subject: [PATCH] resolved: verify all RRs when we come back from suspend --- src/resolve/resolved-bus.c | 33 +++++++++++++++++++++++++++++++++ src/resolve/resolved-dns-zone.c | 14 ++++++++++++++ src/resolve/resolved-dns-zone.h | 2 ++ src/resolve/resolved-manager.c | 10 ++++++++++ src/resolve/resolved-manager.h | 5 +++++ 5 files changed, 64 insertions(+) diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c index 6a3343e0006..cfe12d3bed5 100644 --- a/src/resolve/resolved-bus.c +++ b/src/resolve/resolved-bus.c @@ -638,6 +638,28 @@ static int on_bus_retry(sd_event_source *s, usec_t usec, void *userdata) { return 0; } +static int match_prepare_for_sleep(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *ret_error) { + Manager *m = userdata; + int b, r; + + assert(bus); + assert(bus); + + r = sd_bus_message_read(message, "b", &b); + if (r < 0) { + log_debug("Failed to parse PrepareForSleep signal: %s", strerror(-r)); + return 0; + } + + if (b) + return 0; + + log_debug("Coming back from suspend, verifying all RRs..."); + + manager_verify_all(m); + return 0; +} + int manager_connect_bus(Manager *m) { int r; @@ -681,5 +703,16 @@ int manager_connect_bus(Manager *m) { return r; } + r = sd_bus_add_match(m->bus, &m->prepare_for_sleep_slot, + "type='signal'," + "sender='org.freedesktop.login1'," + "interface='org.freedesktop.login1.Manager'," + "member='PrepareForSleep'," + "path='/org/freedesktop/login1'", + match_prepare_for_sleep, + m); + if (r < 0) + log_error("Failed to add match for PrepareForSleep: %s", strerror(-r)); + return 0; } diff --git a/src/resolve/resolved-dns-zone.c b/src/resolve/resolved-dns-zone.c index d96ddd270cd..5f250e7ca39 100644 --- a/src/resolve/resolved-dns-zone.c +++ b/src/resolve/resolved-dns-zone.c @@ -625,3 +625,17 @@ int dns_zone_verify_conflicts(DnsZone *zone, DnsResourceKey *key) { return c; } + +void dns_zone_verify_all(DnsZone *zone) { + DnsZoneItem *i; + Iterator iterator; + + assert(zone); + + HASHMAP_FOREACH(i, zone->by_key, iterator) { + DnsZoneItem *j; + + LIST_FOREACH(by_key, j, i) + dns_zone_item_verify(j); + } +} diff --git a/src/resolve/resolved-dns-zone.h b/src/resolve/resolved-dns-zone.h index 37fdafe040a..482df2f15f5 100644 --- a/src/resolve/resolved-dns-zone.h +++ b/src/resolve/resolved-dns-zone.h @@ -74,3 +74,5 @@ void dns_zone_item_ready(DnsZoneItem *i); int dns_zone_check_conflicts(DnsZone *zone, DnsResourceRecord *rr); int dns_zone_verify_conflicts(DnsZone *zone, DnsResourceKey *key); + +void dns_zone_verify_all(DnsZone *zone); diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index a93f4a597f7..1d33c2ae19c 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -554,6 +554,7 @@ Manager *manager_free(Manager *m) { manager_llmnr_stop(m); + sd_bus_slot_unref(m->prepare_for_sleep_slot); sd_event_source_unref(m->bus_retry_event_source); sd_bus_unref(m->bus); @@ -1722,6 +1723,15 @@ DnsScope* manager_find_scope(Manager *m, DnsPacket *p) { return NULL; } +void manager_verify_all(Manager *m) { + DnsScope *s; + + assert(m); + + LIST_FOREACH(scopes, s, m->dns_scopes) + dns_zone_verify_all(&s->zone); +} + static const char* const support_table[_SUPPORT_MAX] = { [SUPPORT_NO] = "no", [SUPPORT_YES] = "yes", diff --git a/src/resolve/resolved-manager.h b/src/resolve/resolved-manager.h index f960bc2f1e2..f8cb91c330b 100644 --- a/src/resolve/resolved-manager.h +++ b/src/resolve/resolved-manager.h @@ -108,6 +108,9 @@ struct Manager { /* Watch the system hostname */ int hostname_fd; sd_event_source *hostname_event_source; + + /* Watch for system suspends */ + sd_bus_slot *prepare_for_sleep_slot; }; /* Manager */ @@ -146,6 +149,8 @@ int manager_next_hostname(Manager *m); bool manager_our_packet(Manager *m, DnsPacket *p); DnsScope* manager_find_scope(Manager *m, DnsPacket *p); +void manager_verify_all(Manager *m); + DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); #define EXTRA_CMSG_SPACE 1024