b0af08efb56e30bec69d7a4575195ffb0f2605fc
[openwrt/staging/chunkeey.git] / package / utils / busybox / patches / 230-ntpd_delayed_resolve.patch
1 --- a/networking/ntpd.c
2 +++ b/networking/ntpd.c
3 @@ -265,6 +265,7 @@ typedef struct {
4 typedef struct {
5 len_and_sockaddr *p_lsa;
6 char *p_dotted;
7 + char *p_hostname;
8 int p_fd;
9 int datapoint_idx;
10 uint32_t lastpkt_refid;
11 @@ -766,8 +767,9 @@ add_peers(const char *s)
12 peer_t *p;
13
14 p = xzalloc(sizeof(*p));
15 - p->p_lsa = xhost2sockaddr(s, 123);
16 - p->p_dotted = xmalloc_sockaddr2dotted_noport(&p->p_lsa->u.sa);
17 + p->p_hostname = s;
18 + p->p_lsa = NULL;
19 + p->p_dotted = NULL;
20 p->p_fd = -1;
21 p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3);
22 p->next_action_time = G.cur_time; /* = set_next(p, 0); */
23 @@ -816,6 +818,25 @@ send_query_to_peer(peer_t *p)
24 *
25 * Uncomment this and use strace to see it in action:
26 */
27 +
28 + /* See if the peer hostname already resolved yet, if not, retry to resolv and return on failure */
29 + if (!p->p_lsa)
30 + {
31 + p->p_lsa = host2sockaddr(p->p_hostname, 123);
32 +
33 + if (p->p_lsa)
34 + {
35 + p->p_dotted = xmalloc_sockaddr2dotted_noport(&p->p_lsa->u.sa);
36 + VERB1 bb_error_msg("resolved peer %s to %s", p->p_hostname, p->p_dotted);
37 + }
38 + else
39 + {
40 + set_next(p, RETRY_INTERVAL);
41 + VERB1 bb_error_msg("could not resolve peer %s, skipping", p->p_hostname);
42 + return;
43 + }
44 + }
45 +
46 #define PROBE_LOCAL_ADDR /* { len_and_sockaddr lsa; lsa.len = LSA_SIZEOF_SA; getsockname(p->query.fd, &lsa.u.sa, &lsa.len); } */
47
48 if (p->p_fd == -1) {