Root/package/busybox/patches/610-ntpd_delayed_resolve.patch

1--- a/networking/ntpd.c
2+++ b/networking/ntpd.c
3@@ -216,6 +216,7 @@ typedef struct {
4 typedef struct {
5     len_and_sockaddr *p_lsa;
6     char *p_dotted;
7+ char *p_hostname;
8     /* when to send new query (if p_fd == -1)
9      * or when receive times out (if p_fd >= 0): */
10     int p_fd;
11@@ -646,8 +647,9 @@ add_peers(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@@ -696,6 +698,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) {
49

Archive Download this file



interactive