chiark / gitweb /
resolved: use CLOCK_BOOTTIME instead of CLOCK_MONOTONIC when aging caches and timeing...
authorLennart Poettering <lennart@poettering.net>
Thu, 31 Jul 2014 22:55:51 +0000 (00:55 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 31 Jul 2014 22:58:12 +0000 (00:58 +0200)
That way the cache doens't get confused when the system is suspended.

src/resolve/resolved-dns-cache.c
src/resolve/resolved-dns-query.c
src/resolve/resolved-dns-stream.c
src/resolve/resolved-dns-transaction.c

index 7359dfa271973272637ca15f050b6e2538df090c..f7091f07bf4b5c18e1ba949ca6bd4a4fed548f32 100644 (file)
@@ -153,7 +153,7 @@ void dns_cache_prune(DnsCache *c) {
                         break;
 
                 if (t <= 0)
                         break;
 
                 if (t <= 0)
-                        t = now(CLOCK_MONOTONIC);
+                        t = now(CLOCK_BOOTTIME);
 
                 if (i->until > t)
                         break;
 
                 if (i->until > t)
                         break;
@@ -376,7 +376,7 @@ int dns_cache_put(DnsCache *c, DnsQuestion *q, int rcode, DnsAnswer *answer, uns
         dns_cache_make_space(c, answer->n_rrs + q->n_keys);
 
         if (timestamp <= 0)
         dns_cache_make_space(c, answer->n_rrs + q->n_keys);
 
         if (timestamp <= 0)
-                timestamp = now(CLOCK_MONOTONIC);
+                timestamp = now(CLOCK_BOOTTIME);
 
         /* Second, add in positive entries for all contained RRs */
         for (i = 0; i < MIN(max_rrs, answer->n_rrs); i++) {
 
         /* Second, add in positive entries for all contained RRs */
         for (i = 0; i < MIN(max_rrs, answer->n_rrs); i++) {
index 57f7467667db68aa710be8b2ec5293bbef563108..36cfc026eaf7a67641b25f82c89448f7bbedd7d0 100644 (file)
@@ -278,7 +278,12 @@ int dns_query_go(DnsQuery *q) {
         q->answer_ifindex = 0;
         q->answer_rcode = 0;
 
         q->answer_ifindex = 0;
         q->answer_rcode = 0;
 
-        r = sd_event_add_time(q->manager->event, &q->timeout_event_source, CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + QUERY_TIMEOUT_USEC, 0, on_query_timeout, q);
+        r = sd_event_add_time(
+                        q->manager->event,
+                        &q->timeout_event_source,
+                        clock_boottime_or_monotonic(),
+                        now(clock_boottime_or_monotonic()) + QUERY_TIMEOUT_USEC, 0,
+                        on_query_timeout, q);
         if (r < 0)
                 goto fail;
 
         if (r < 0)
                 goto fail;
 
index 47130c4231923a42219e73358b3f602e678e8b67..9a0d59d2247d9500c7b6147aeea30f7744618962 100644 (file)
@@ -368,7 +368,12 @@ int dns_stream_new(Manager *m, DnsStream **ret, DnsProtocol protocol, int fd) {
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
-        r = sd_event_add_time(m->event, &s->timeout_event_source, CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + DNS_STREAM_TIMEOUT_USEC, 0, on_stream_timeout, s);
+        r = sd_event_add_time(
+                        m->event,
+                        &s->timeout_event_source,
+                        clock_boottime_or_monotonic(),
+                        now(clock_boottime_or_monotonic()) + DNS_STREAM_TIMEOUT_USEC, 0,
+                        on_stream_timeout, s);
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
index 92f7e4c5b1f118fbbd8bfe14385c8a0fe81e9184..faa1de9143a275b525d77b0a6f5aecbbb0ab5bcc 100644 (file)
@@ -515,7 +515,12 @@ int dns_transaction_go(DnsTransaction *t) {
                 return dns_transaction_go(t);
         }
 
                 return dns_transaction_go(t);
         }
 
-        r = sd_event_add_time(t->scope->manager->event, &t->timeout_event_source, CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + TRANSACTION_TIMEOUT_USEC(t->scope->protocol), 0, on_transaction_timeout, t);
+        r = sd_event_add_time(
+                        t->scope->manager->event,
+                        &t->timeout_event_source,
+                        clock_boottime_or_monotonic(),
+                        now(clock_boottime_or_monotonic()) + TRANSACTION_TIMEOUT_USEC(t->scope->protocol), 0,
+                        on_transaction_timeout, t);
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;