ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
Michal Schmidt d962ba
From 6aa136216f2f78a840215e53ababeea7b65fc061 Mon Sep 17 00:00:00 2001
Michal Schmidt d962ba
From: Miroslav Lichvar <mlichvar@redhat.com>
Michal Schmidt d962ba
Date: Wed, 27 Aug 2014 16:47:24 +0200
Michal Schmidt d962ba
Subject: [PATCH 07/12] timesyncd: wait before reconnecting to first server
Michal Schmidt d962ba
Michal Schmidt d962ba
When all servers are exhausted, wait for one poll interval before trying
Michal Schmidt d962ba
to connect again to the first server in the list. Also, keep increasing
Michal Schmidt d962ba
the polling interval to make sure a client not getting any valid replies
Michal Schmidt d962ba
will not send requests to any server more frequently than is allowed by
Michal Schmidt d962ba
the maximum polling interval.
Michal Schmidt d962ba
Michal Schmidt d962ba
(cherry picked from commit 63463bf091949e0178b749016828ec400c106582)
Michal Schmidt d962ba
---
Michal Schmidt d962ba
 src/timesync/timesyncd-manager.c | 24 +++++++++++++++++++++++-
Michal Schmidt d962ba
 src/timesync/timesyncd-manager.h |  1 +
Michal Schmidt d962ba
 2 files changed, 24 insertions(+), 1 deletion(-)
Michal Schmidt d962ba
Michal Schmidt d962ba
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
Michal Schmidt d962ba
index 696dd10..b7b39ef 100644
Michal Schmidt d962ba
--- a/src/timesync/timesyncd-manager.c
Michal Schmidt d962ba
+++ b/src/timesync/timesyncd-manager.c
Michal Schmidt d962ba
@@ -875,6 +875,7 @@ int manager_connect(Manager *m) {
Michal Schmidt d962ba
                         manager_set_server_name(m, m->current_server_name->names_next);
Michal Schmidt d962ba
                 else {
Michal Schmidt d962ba
                         ServerName *f;
Michal Schmidt d962ba
+                        bool restart = true;
Michal Schmidt d962ba
 
Michal Schmidt d962ba
                         /* Our current server name list is exhausted,
Michal Schmidt d962ba
                          * let's find the next one to iterate. First
Michal Schmidt d962ba
@@ -891,6 +892,8 @@ int manager_connect(Manager *m) {
Michal Schmidt d962ba
                                 f = m->link_servers;
Michal Schmidt d962ba
                                 if (!f)
Michal Schmidt d962ba
                                         f = m->system_servers;
Michal Schmidt d962ba
+                                else
Michal Schmidt d962ba
+                                        restart = false;
Michal Schmidt d962ba
                         }
Michal Schmidt d962ba
 
Michal Schmidt d962ba
                         if (!f)
Michal Schmidt d962ba
@@ -902,6 +905,25 @@ int manager_connect(Manager *m) {
Michal Schmidt d962ba
                                 return 0;
Michal Schmidt d962ba
                         }
Michal Schmidt d962ba
 
Michal Schmidt d962ba
+                        if (restart && !m->exhausted_servers && m->poll_interval_usec) {
Michal Schmidt d962ba
+                                log_debug("Waiting after exhausting servers.");
Michal Schmidt d962ba
+                                r = sd_event_add_time(m->event, &m->event_retry, clock_boottime_or_monotonic(), now(clock_boottime_or_monotonic()) + m->poll_interval_usec, 0, manager_retry_connect, m);
Michal Schmidt d962ba
+                                if (r < 0) {
Michal Schmidt d962ba
+                                        log_error("Failed to create retry timer: %s", strerror(-r));
Michal Schmidt d962ba
+                                        return r;
Michal Schmidt d962ba
+                                }
Michal Schmidt d962ba
+
Michal Schmidt d962ba
+                                m->exhausted_servers = true;
Michal Schmidt d962ba
+
Michal Schmidt d962ba
+                                /* Increase the polling interval */
Michal Schmidt d962ba
+                                if (m->poll_interval_usec < NTP_POLL_INTERVAL_MAX_SEC * USEC_PER_SEC)
Michal Schmidt d962ba
+                                        m->poll_interval_usec *= 2;
Michal Schmidt d962ba
+
Michal Schmidt d962ba
+                                return 0;
Michal Schmidt d962ba
+                        }
Michal Schmidt d962ba
+
Michal Schmidt d962ba
+                        m->exhausted_servers = false;
Michal Schmidt d962ba
+
Michal Schmidt d962ba
                         manager_set_server_name(m, f);
Michal Schmidt d962ba
                 }
Michal Schmidt d962ba
 
Michal Schmidt d962ba
@@ -1042,7 +1064,7 @@ static int manager_network_event_handler(sd_event_source *s, int fd, uint32_t re
Michal Schmidt d962ba
         online = network_is_online();
Michal Schmidt d962ba
 
Michal Schmidt d962ba
         /* check if the client is currently connected */
Michal Schmidt d962ba
-        connected = m->server_socket >= 0 || m->resolve_query;
Michal Schmidt d962ba
+        connected = m->server_socket >= 0 || m->resolve_query || m->exhausted_servers;
Michal Schmidt d962ba
 
Michal Schmidt d962ba
         if (connected && !online) {
Michal Schmidt d962ba
                 log_info("No network connectivity, watching for changes.");
Michal Schmidt d962ba
diff --git a/src/timesync/timesyncd-manager.h b/src/timesync/timesyncd-manager.h
Michal Schmidt d962ba
index 2345bf8..bb3e509 100644
Michal Schmidt d962ba
--- a/src/timesync/timesyncd-manager.h
Michal Schmidt d962ba
+++ b/src/timesync/timesyncd-manager.h
Michal Schmidt d962ba
@@ -41,6 +41,7 @@ struct Manager {
Michal Schmidt d962ba
         LIST_HEAD(ServerName, fallback_servers);
Michal Schmidt d962ba
 
Michal Schmidt d962ba
         RateLimit ratelimit;
Michal Schmidt d962ba
+        bool exhausted_servers;
Michal Schmidt d962ba
 
Michal Schmidt d962ba
         /* network */
Michal Schmidt d962ba
         sd_event_source *network_event_source;
Michal Schmidt d962ba
-- 
Michal Schmidt d962ba
2.1.0
Michal Schmidt d962ba