Michal Schmidt d962ba
From 1d282632e027281c81a97c2bf2d7a803553651dc Mon Sep 17 00:00:00 2001
Michal Schmidt d962ba
From: Kay Sievers <kay@vrfy.org>
Michal Schmidt d962ba
Date: Tue, 2 Sep 2014 15:28:56 +0200
Michal Schmidt d962ba
Subject: [PATCH 11/12] Revert "timesyncd: remove retry_timer logic which is
Michal Schmidt d962ba
 covered by the server timeout"
Michal Schmidt d962ba
Michal Schmidt d962ba
This reverts commit 665c6a9eab46b0b253af6566ca9fc70c866b3fcd.
Michal Schmidt d962ba
Michal Schmidt d962ba
On Tue, Sep 2, 2014 at 3:17 PM, Miroslav Lichvar <mlichvar@redhat.com> wrote:
Michal Schmidt d962ba
>
Michal Schmidt d962ba
> With the other patch allowing missed replies included it's now getting
Michal Schmidt d962ba
> stuck as there is no timer to send the 2nd and 3rd request.
Michal Schmidt d962ba
Michal Schmidt d962ba
(cherry picked from commit ab4df227d466e881e4279821b5fc1563f0e7e933)
Michal Schmidt d962ba
---
Michal Schmidt d962ba
 src/timesync/timesyncd-manager.c | 14 ++++++++++++++
Michal Schmidt d962ba
 src/timesync/timesyncd-manager.h |  1 +
Michal Schmidt d962ba
 2 files changed, 15 insertions(+)
Michal Schmidt d962ba
Michal Schmidt d962ba
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
Michal Schmidt d962ba
index 3261bc1..a5678cc 100644
Michal Schmidt d962ba
--- a/src/timesync/timesyncd-manager.c
Michal Schmidt d962ba
+++ b/src/timesync/timesyncd-manager.c
Michal Schmidt d962ba
@@ -209,6 +209,19 @@ static int manager_send_request(Manager *m) {
Michal Schmidt d962ba
                 return manager_connect(m);
Michal Schmidt d962ba
         }
Michal Schmidt d962ba
 
Michal Schmidt d962ba
+        /* re-arm timer with increasing timeout, in case the packets never arrive back */
Michal Schmidt d962ba
+        if (m->retry_interval > 0) {
Michal Schmidt d962ba
+                if (m->retry_interval < NTP_POLL_INTERVAL_MAX_SEC * USEC_PER_SEC)
Michal Schmidt d962ba
+                        m->retry_interval *= 2;
Michal Schmidt d962ba
+        } else
Michal Schmidt d962ba
+                m->retry_interval = NTP_POLL_INTERVAL_MIN_SEC * USEC_PER_SEC;
Michal Schmidt d962ba
+
Michal Schmidt d962ba
+        r = manager_arm_timer(m, m->retry_interval);
Michal Schmidt d962ba
+        if (r < 0) {
Michal Schmidt d962ba
+                log_error("Failed to rearm timer: %s", strerror(-r));
Michal Schmidt d962ba
+                return r;
Michal Schmidt d962ba
+        }
Michal Schmidt d962ba
+
Michal Schmidt d962ba
         m->missed_replies++;
Michal Schmidt d962ba
         if (m->missed_replies > NTP_MAX_MISSED_REPLIES) {
Michal Schmidt d962ba
                 r = sd_event_add_time(
Michal Schmidt d962ba
@@ -596,6 +609,7 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
Michal Schmidt d962ba
 
Michal Schmidt d962ba
         /* valid packet */
Michal Schmidt d962ba
         m->pending = false;
Michal Schmidt d962ba
+        m->retry_interval = 0;
Michal Schmidt d962ba
 
Michal Schmidt d962ba
         /* announce leap seconds */
Michal Schmidt d962ba
         if (NTP_FIELD_LEAP(ntpmsg.field) & NTP_LEAP_PLUSSEC)
Michal Schmidt d962ba
diff --git a/src/timesync/timesyncd-manager.h b/src/timesync/timesyncd-manager.h
Michal Schmidt d962ba
index 8296d41..c7efdc5 100644
Michal Schmidt d962ba
--- a/src/timesync/timesyncd-manager.h
Michal Schmidt d962ba
+++ b/src/timesync/timesyncd-manager.h
Michal Schmidt d962ba
@@ -60,6 +60,7 @@ struct Manager {
Michal Schmidt d962ba
         /* last sent packet */
Michal Schmidt d962ba
         struct timespec trans_time_mon;
Michal Schmidt d962ba
         struct timespec trans_time;
Michal Schmidt d962ba
+        usec_t retry_interval;
Michal Schmidt d962ba
         bool pending;
Michal Schmidt d962ba
 
Michal Schmidt d962ba
         /* poll timer */
Michal Schmidt d962ba
-- 
Michal Schmidt d962ba
2.1.0
Michal Schmidt d962ba