aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-05-22 18:16:34 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2013-05-22 18:16:34 +0200
commit5ffdd1d981d4faf751ed79f31896a62e7c0db0a0 (patch)
treea4a86d24e7d758cebaef6c43528a15decea31553
parentd99ef636f6e41acda164fc94c6bf87d1c14f9794 (diff)
downloadbusybox-w32-5ffdd1d981d4faf751ed79f31896a62e7c0db0a0.tar.gz
busybox-w32-5ffdd1d981d4faf751ed79f31896a62e7c0db0a0.tar.bz2
busybox-w32-5ffdd1d981d4faf751ed79f31896a62e7c0db0a0.zip
ntpd: make "unsync" code actually work.
While at it: don't run "periodic" if interrupted by a signal. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/ntpd.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 9ec255814..bff2c0d4c 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -805,6 +805,14 @@ send_query_to_peer(peer_t *p)
805 p->p_xmt_msg.m_xmttime.fractionl = random(); 805 p->p_xmt_msg.m_xmttime.fractionl = random();
806 p->p_xmttime = gettime1900d(); 806 p->p_xmttime = gettime1900d();
807 807
808 /* Was doing it only if sendto worked, but
809 * loss of sync detection needs reachable_bits updated
810 * even if sending fails *locally*:
811 * "network is unreachable" because cable was pulled?
812 * We still need to declare "unsync" if this condition persists.
813 */
814 p->reachable_bits <<= 1;
815
808 if (do_sendto(p->p_fd, /*from:*/ NULL, /*to:*/ &p->p_lsa->u.sa, /*addrlen:*/ p->p_lsa->len, 816 if (do_sendto(p->p_fd, /*from:*/ NULL, /*to:*/ &p->p_lsa->u.sa, /*addrlen:*/ p->p_lsa->len,
809 &p->p_xmt_msg, NTP_MSGSIZE_NOAUTH) == -1 817 &p->p_xmt_msg, NTP_MSGSIZE_NOAUTH) == -1
810 ) { 818 ) {
@@ -814,7 +822,6 @@ send_query_to_peer(peer_t *p)
814 return; 822 return;
815 } 823 }
816 824
817 p->reachable_bits <<= 1;
818 set_next(p, RESPONSE_INTERVAL); 825 set_next(p, RESPONSE_INTERVAL);
819} 826}
820 827
@@ -2171,12 +2178,14 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv)
2171 did_poll: 2178 did_poll:
2172 gettime1900d(); /* sets G.cur_time */ 2179 gettime1900d(); /* sets G.cur_time */
2173 if (nfds <= 0) { 2180 if (nfds <= 0) {
2174 if (G.script_name && G.cur_time - G.last_script_run > 11*60) { 2181 if (!bb_got_signal /* poll wasn't interrupted by a signal */
2182 && G.cur_time - G.last_script_run > 11*60
2183 ) {
2175 /* Useful for updating battery-backed RTC and such */ 2184 /* Useful for updating battery-backed RTC and such */
2176 run_script("periodic", G.last_update_offset); 2185 run_script("periodic", G.last_update_offset);
2177 gettime1900d(); /* sets G.cur_time */ 2186 gettime1900d(); /* sets G.cur_time */
2178 } 2187 }
2179 continue; 2188 goto check_unsync;
2180 } 2189 }
2181 2190
2182 /* Process any received packets */ 2191 /* Process any received packets */
@@ -2208,6 +2217,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv)
2208 } 2217 }
2209 } 2218 }
2210 2219
2220 check_unsync:
2211 if (G.ntp_peers && G.stratum != MAXSTRAT) { 2221 if (G.ntp_peers && G.stratum != MAXSTRAT) {
2212 for (item = G.ntp_peers; item != NULL; item = item->link) { 2222 for (item = G.ntp_peers; item != NULL; item = item->link) {
2213 peer_t *p = (peer_t *) item->data; 2223 peer_t *p = (peer_t *) item->data;