aboutsummaryrefslogtreecommitdiffstats
path: root/main/busybox/0013-ntpd-postpone-hostname-resolution-if-fails-on-startu.patch
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2016-08-04 13:20:41 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2016-08-04 15:39:25 +0200
commit6525b7aa7fbb97336a7656a5408d6505c2ac7ca3 (patch)
tree54eb98884f9d6e160768f06caa698a2b80fd8f08 /main/busybox/0013-ntpd-postpone-hostname-resolution-if-fails-on-startu.patch
parent8b04cc5199ded248ac18049e1fee5d680539c47f (diff)
main/busybox: upgrade to 1.25.0
Diffstat (limited to 'main/busybox/0013-ntpd-postpone-hostname-resolution-if-fails-on-startu.patch')
-rw-r--r--main/busybox/0013-ntpd-postpone-hostname-resolution-if-fails-on-startu.patch197
1 files changed, 197 insertions, 0 deletions
diff --git a/main/busybox/0013-ntpd-postpone-hostname-resolution-if-fails-on-startu.patch b/main/busybox/0013-ntpd-postpone-hostname-resolution-if-fails-on-startu.patch
new file mode 100644
index 00000000000..5454815680f
--- /dev/null
+++ b/main/busybox/0013-ntpd-postpone-hostname-resolution-if-fails-on-startu.patch
@@ -0,0 +1,197 @@
+From 678563e106ce8416266de16c309494a051f331f6 Mon Sep 17 00:00:00 2001
+From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
+Date: Thu, 4 Aug 2016 12:26:56 +0200
+Subject: [PATCH 13/15] ntpd: postpone hostname resolution if fails on startup
+
+Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
+---
+ networking/ntpd.c | 129 ++++++++++++++++++++++++++----------------------------
+ 1 file changed, 63 insertions(+), 66 deletions(-)
+
+diff --git a/networking/ntpd.c b/networking/ntpd.c
+index 98158a3..7f7d69e 100644
+--- a/networking/ntpd.c
++++ b/networking/ntpd.c
+@@ -267,6 +267,7 @@ typedef struct {
+
+ typedef struct {
+ len_and_sockaddr *p_lsa;
++ char *p_hostname;
+ char *p_dotted;
+ int p_fd;
+ int datapoint_idx;
+@@ -292,7 +293,6 @@ typedef struct {
+ datapoint_t filter_datapoint[NUM_DATAPOINTS];
+ /* last sent packet: */
+ msg_t p_xmt_msg;
+- char p_hostname[1];
+ } peer_t;
+
+
+@@ -765,27 +765,17 @@ reset_peer_stats(peer_t *p, double offset)
+ }
+
+ static void
+-resolve_peer_hostname(peer_t *p, int loop_on_fail)
+-{
+- len_and_sockaddr *lsa;
+-
+- again:
+- lsa = host2sockaddr(p->p_hostname, 123);
+- if (!lsa) {
+- /* error message already emitted by host2sockaddr() */
+- if (!loop_on_fail)
+- return;
+-//FIXME: do this to avoid infinite looping on typo in a hostname?
+-//well... in which case, what is a good value for loop_on_fail?
+- //if (--loop_on_fail == 0)
+- // xfunc_die();
+- sleep(5);
+- goto again;
++resolve_peer_hostname(peer_t *p) {
++ len_and_sockaddr *lsa = host2sockaddr(p->p_hostname, 123);
++ if (lsa) {
++ if (p->p_lsa) {
++ free(p->p_lsa);
++ free(p->p_dotted);
++ }
++ p->p_lsa = lsa;
++ p->p_dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa);
+ }
+- free(p->p_lsa);
+- free(p->p_dotted);
+- p->p_lsa = lsa;
+- p->p_dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa);
++ set_next(p, lsa ? 0 : RETRY_INTERVAL);
+ }
+
+ static void
+@@ -794,28 +784,29 @@ add_peers(const char *s)
+ llist_t *item;
+ peer_t *p;
+
+- p = xzalloc(sizeof(*p) + strlen(s));
+- strcpy(p->p_hostname, s);
+- resolve_peer_hostname(p, /*loop_on_fail=*/ 1);
++ p = xzalloc(sizeof(*p));
++ p->p_hostname = xstrdup(s);
++ resolve_peer_hostname(p);
+
+ /* Names like N.<country2chars>.pool.ntp.org are randomly resolved
+ * to a pool of machines. Sometimes different N's resolve to the same IP.
+ * It is not useful to have two peers with same IP. We skip duplicates.
+ */
+- for (item = G.ntp_peers; item != NULL; item = item->link) {
+- peer_t *pp = (peer_t *) item->data;
+- if (strcmp(p->p_dotted, pp->p_dotted) == 0) {
+- bb_error_msg("duplicate peer %s (%s)", s, p->p_dotted);
+- free(p->p_lsa);
+- free(p->p_dotted);
+- free(p);
+- return;
++ if (p->p_lsa)
++ for (item = G.ntp_peers; item != NULL; item = item->link) {
++ peer_t *pp = (peer_t *) item->data;
++ if (pp->p_lsa && strcmp(p->p_dotted, pp->p_dotted) == 0) {
++ bb_error_msg("duplicate peer %s (%s)", s, p->p_dotted);
++ free(p->p_hostname);
++ free(p->p_lsa);
++ free(p->p_dotted);
++ free(p);
++ return;
++ }
+ }
+- }
+
+ p->p_fd = -1;
+ p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3);
+- p->next_action_time = G.cur_time; /* = set_next(p, 0); */
+ reset_peer_stats(p, STEP_THRESHOLD);
+
+ llist_add_to(&G.ntp_peers, p);
+@@ -2340,44 +2331,50 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv)
+ for (item = G.ntp_peers; item != NULL; item = item->link) {
+ peer_t *p = (peer_t *) item->data;
+
+- if (p->next_action_time <= G.cur_time) {
+- if (p->p_fd == -1) {
+- /* Time to send new req */
+- if (--cnt == 0) {
+- VERB4 bb_error_msg("disabling burst mode");
+- G.polladj_count = 0;
+- G.poll_exp = MINPOLL;
++ if (p->p_lsa) {
++
++ if (p->next_action_time <= G.cur_time) {
++ if (p->p_fd == -1) {
++ /* Time to send new req */
++ if (--cnt == 0) {
++ VERB4 bb_error_msg("disabling burst mode");
++ G.polladj_count = 0;
++ G.poll_exp = MINPOLL;
++ }
++ send_query_to_peer(p);
++ } else {
++ /* Timed out waiting for reply */
++ close(p->p_fd);
++ p->p_fd = -1;
++ /* If poll interval is small, increase it */
++ if (G.poll_exp < BIGPOLL)
++ adjust_poll(MINPOLL);
++ timeout = poll_interval(NOREPLY_INTERVAL);
++ bb_error_msg("timed out waiting for %s, reach 0x%02x, next query in %us",
++ p->p_dotted, p->reachable_bits, timeout);
++
++ /* What if don't see it because it changed its IP? */
++ if (p->reachable_bits == 0)
++ resolve_peer_hostname(p);
++
++ set_next(p, timeout);
+ }
+- send_query_to_peer(p);
+- } else {
+- /* Timed out waiting for reply */
+- close(p->p_fd);
+- p->p_fd = -1;
+- /* If poll interval is small, increase it */
+- if (G.poll_exp < BIGPOLL)
+- adjust_poll(MINPOLL);
+- timeout = poll_interval(NOREPLY_INTERVAL);
+- bb_error_msg("timed out waiting for %s, reach 0x%02x, next query in %us",
+- p->p_dotted, p->reachable_bits, timeout);
+-
+- /* What if don't see it because it changed its IP? */
+- if (p->reachable_bits == 0)
+- resolve_peer_hostname(p, /*loop_on_fail=*/ 0);
+-
+- set_next(p, timeout);
+ }
+- }
++
++ if (p->p_fd >= 0) {
++ /* Wait for reply from this peer */
++ pfd[i].fd = p->p_fd;
++ pfd[i].events = POLLIN;
++ idx2peer[i] = p;
++ i++;
++ }
++
++ } else
++ resolve_peer_hostname(p);
+
+ if (p->next_action_time < nextaction)
+ nextaction = p->next_action_time;
+
+- if (p->p_fd >= 0) {
+- /* Wait for reply from this peer */
+- pfd[i].fd = p->p_fd;
+- pfd[i].events = POLLIN;
+- idx2peer[i] = p;
+- i++;
+- }
+ }
+
+ timeout = nextaction - G.cur_time;
+--
+2.9.1
+