From: Michal Schmidt <mschmidt@redhat.com>
Date: Wed, 10 Sep 2014 19:44:24 +0200
Subject: timesyncd: wait before reconnecting to first server

Upstream commit:
commit 63463bf091949e0178b749016828ec400c106582
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date:   Wed Aug 27 16:47:24 2014 +0200

    timesyncd: wait before reconnecting to first server

    When all servers are exhausted, wait for one poll interval before trying
    to connect again to the first server in the list. Also, keep increasing
    the polling interval to make sure a client not getting any valid replies
    will not send requests to any server more frequently than is allowed by
    the maximum polling interval.

Conflicts:
	src/timesync/timesyncd-manager.c
---
 src/timesync/timesyncd.c | 22 +++++++++++++++++++++-
 src/timesync/timesyncd.h |  1 +
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c
index 5187df5..589c5ec 100644
--- a/src/timesync/timesyncd.c
+++ b/src/timesync/timesyncd.c
@@ -935,12 +935,32 @@ static int manager_connect(Manager *m) {
                 if (m->current_server_name && m->current_server_name->names_next)
                         m->current_server_name = m->current_server_name->names_next;
                 else {
+
                         if (!m->servers) {
                                 m->current_server_name = NULL;
                                 log_debug("No server found.");
                                 return 0;
                         }
 
+                        if (!m->exhausted_servers && m->poll_interval_usec) {
+                                log_debug("Waiting after exhausting servers.");
+                                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, m);
+                                if (r < 0) {
+                                        log_error("Failed to create retry timer: %s", strerror(-r));
+                                        return r;
+                                }
+
+                                m->exhausted_servers = true;
+
+                                /* Increase the polling interval */
+                                if (m->poll_interval_usec < NTP_POLL_INTERVAL_MAX_SEC * USEC_PER_SEC)
+                                        m->poll_interval_usec *= 2;
+
+                                return 0;
+                        }
+
+                        m->exhausted_servers = false;
+
                         m->current_server_name = m->servers;
                 }
 
@@ -1150,7 +1170,7 @@ static int manager_network_event_handler(sd_event_source *s, int fd, uint32_t re
         online = network_is_online();
 
         /* check if the client is currently connected */
-        connected = (m->server_socket != -1);
+        connected = (m->server_socket != -1) || m->exhausted_servers;
 
         if (connected && !online) {
                 log_info("No network connectivity, watching for changes.");
diff --git a/src/timesync/timesyncd.h b/src/timesync/timesyncd.h
index 4afe4b9..04d83f0 100644
--- a/src/timesync/timesyncd.h
+++ b/src/timesync/timesyncd.h
@@ -49,6 +49,7 @@ struct Manager {
         LIST_HEAD(ServerName, servers);
 
         RateLimit ratelimit;
+        bool exhausted_servers;
 
         /* network */
         sd_event_source *network_event_source;
