[systemd-commits] 3 commits - src/timesync

Lennart Poettering lennart at kemper.freedesktop.org
Mon May 5 16:37:37 PDT 2014


 src/timesync/timesyncd.c |   52 ++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 47 insertions(+), 5 deletions(-)

New commits:
commit 881c74201d42d84f076e11d4ed765bd8421a6ff0
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue May 6 01:37:29 2014 +0200

    timesyncd: add a more servers by default

diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c
index 26d26b0..4f4c3ba 100644
--- a/src/timesync/timesyncd.c
+++ b/src/timesync/timesyncd.c
@@ -40,6 +40,7 @@
 #include "socket-util.h"
 #include "list.h"
 #include "ratelimit.h"
+#include "strv.h"
 #include "sd-event.h"
 #include "sd-resolve.h"
 #include "sd-daemon.h"
@@ -1019,6 +1020,7 @@ static void manager_free(Manager *m) {
 
 int main(int argc, char *argv[]) {
         _cleanup_manager_free_ Manager *m = NULL;
+        const char *x;
         int r;
 
         log_set_target(LOG_TARGET_AUTO);
@@ -1035,10 +1037,13 @@ int main(int argc, char *argv[]) {
 
         sd_notify(false, "READY=1");
 
-        r = manager_add_server(m, "time1.google.com");
-        if (r < 0) {
-                log_error("Failed to add server: %s", strerror(-r));
-                goto out;
+        FOREACH_STRING(x, "time1.google.com", "time2.google.com", "time3.google.com", "time4.google.com", "0.fedora.pool.ntp.org") {
+
+                r = manager_add_server(m, x);
+                if (r < 0) {
+                        log_error("Failed to add server %s: %s", x, strerror(-r));
+                        goto out;
+                }
         }
 
         r = manager_connect(m);

commit becad8f1ed696433b9841cbb9c4603c303338d30
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue May 6 01:37:13 2014 +0200

    timesyncd: also try next server when sendto() fails

diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c
index bbffbbd..26d26b0 100644
--- a/src/timesync/timesyncd.c
+++ b/src/timesync/timesyncd.c
@@ -86,7 +86,7 @@
 
 #define RETRY_USEC (30*USEC_PER_SEC)
 #define RATELIMIT_INTERVAL_USEC (10*USEC_PER_SEC)
-#define RATELIMIT_BURST 5
+#define RATELIMIT_BURST 10
 
 struct ntp_ts {
         be32_t sec;
@@ -245,8 +245,10 @@ static int manager_send_request(Manager *m) {
         if (len == sizeof(ntpmsg)) {
                 m->pending = true;
                 log_debug("Sent NTP request to %s (%s)", pretty, m->current_server_name->string);
-        } else
+        } else {
                 log_debug("Sending NTP request to %s (%s) failed: %m", pretty, m->current_server_name->string);
+                return manager_connect(m);
+        }
 
         /* re-arm timer with incresing timeout, in case the packets never arrive back */
         if (m->retry_interval > 0) {

commit 7a183c4c739665b1be3033fe70933ef236686b58
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue May 6 01:29:47 2014 +0200

    timesyncd: don't busy loop when we cannot connect to any servers

diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c
index 6c88697..bbffbbd 100644
--- a/src/timesync/timesyncd.c
+++ b/src/timesync/timesyncd.c
@@ -39,6 +39,7 @@
 #include "log.h"
 #include "socket-util.h"
 #include "list.h"
+#include "ratelimit.h"
 #include "sd-event.h"
 #include "sd-resolve.h"
 #include "sd-daemon.h"
@@ -83,6 +84,10 @@
  */
 #define OFFSET_1900_1970        2208988800UL
 
+#define RETRY_USEC (30*USEC_PER_SEC)
+#define RATELIMIT_INTERVAL_USEC (10*USEC_PER_SEC)
+#define RATELIMIT_BURST 5
+
 struct ntp_ts {
         be32_t sec;
         be32_t frac;
@@ -129,6 +134,8 @@ struct Manager {
 
         LIST_HEAD(ServerName, servers);
 
+        RateLimit ratelimit;
+
         /* peer */
         sd_resolve_query *resolve_query;
         sd_event_source *event_receive;
@@ -164,6 +171,9 @@ struct Manager {
         sd_event_source *event_clock_watch;
         int clock_watch_fd;
 
+        /* Retry connections */
+        sd_event_source *event_retry;
+
         /* Handle SIGINT/SIGTERM */
         sd_event_source *sigterm, *sigint;
 };
@@ -847,6 +857,14 @@ static int manager_resolve_handler(sd_resolve_query *q, int ret, const struct ad
         return manager_begin(m);
 }
 
+static int manager_retry(sd_event_source *source, usec_t usec, void *userdata) {
+        Manager *m = userdata;
+
+        assert(m);
+
+        return manager_connect(m);
+}
+
 static int manager_connect(Manager *m) {
 
         struct addrinfo hints = {
@@ -859,6 +877,19 @@ static int manager_connect(Manager *m) {
 
         manager_disconnect(m);
 
+        m->event_retry = sd_event_source_unref(m->event_retry);
+        if (!ratelimit_test(&m->ratelimit)) {
+                log_debug("Slowing down attempts to contact servers.");
+
+                r = sd_event_add_time(m->event, &m->event_retry, CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + RETRY_USEC, 0, manager_retry, m);
+                if (r < 0) {
+                        log_error("Failed to create retry timer: %s", strerror(-r));
+                        return r;
+                }
+
+                return 0;
+        }
+
         /* If we already are operating on some address, switch to the
          * next one. */
         if (m->current_server_address && m->current_server_address->addresses_next)
@@ -939,6 +970,8 @@ static int manager_new(Manager **ret) {
 
         m->server_socket = m->clock_watch_fd = -1;
 
+        RATELIMIT_INIT(m->ratelimit, RATELIMIT_INTERVAL_USEC, RATELIMIT_BURST);
+
         r = sd_event_default(&m->event);
         if (r < 0)
                 return r;
@@ -974,6 +1007,8 @@ static void manager_free(Manager *m) {
         sd_event_source_unref(m->sigint);
         sd_event_source_unref(m->sigterm);
 
+        sd_event_source_unref(m->event_retry);
+
         sd_resolve_unref(m->resolve);
         sd_event_unref(m->event);
 



More information about the systemd-commits mailing list