ntp: If the server cannot be contacted, try next one
authorJukka Rissanen <jukka.rissanen@linux.intel.com>
Mon, 16 Jul 2012 08:00:46 +0000 (11:00 +0300)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Mon, 16 Jul 2012 16:03:29 +0000 (18:03 +0200)
This could happen if the network routes are not yet setup
so the sendto() could fail. In this case try next address and
hope for the best. This is a rare issue but I have seen it
couple of times.

src/ntp.c

index 91a8832dc05fc9c6d5ce9f5aa436cd73ee9ba816..8c31fdb6749ccf6afc87428b633e7fc1603c36bd 100644 (file)
--- a/src/ntp.c
+++ b/src/ntp.c
@@ -100,7 +100,12 @@ static void send_packet(int fd, const char *server)
        len = sendto(fd, &msg, sizeof(msg), MSG_DONTWAIT,
                                                &addr, sizeof(addr));
        if (len < 0) {
-               connman_error("Time request for server %s failed", server);
+               connman_error("Time request for server %s failed (%d/%s)",
+                       server, errno, strerror(errno));
+
+               if (errno == ENETUNREACH)
+                       __connman_timeserver_sync_next();
+
                return;
        }