[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox-cvs
Subject:    [git commit] ntpd: make "unsync" code actually work.
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2013-05-22 16:16:34
Message-ID: 20130522161827.503AB9A1D4 () busybox ! osuosl ! org
[Download RAW message or body]

commit: http://git.busybox.net/busybox/commit/?id=5ffdd1d981d4faf751ed79f31896a62e7c0db0a0
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

While at it: don't run "periodic" if interrupted by a signal.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
 networking/ntpd.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/networking/ntpd.c b/networking/ntpd.c
index 9ec2558..bff2c0d 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -805,6 +805,14 @@ send_query_to_peer(peer_t *p)
 	p->p_xmt_msg.m_xmttime.fractionl = random();
 	p->p_xmttime = gettime1900d();
 
+	/* Was doing it only if sendto worked, but
+	 * loss of sync detection needs reachable_bits updated
+	 * even if sending fails *locally*:
+	 * "network is unreachable" because cable was pulled?
+	 * We still need to declare "unsync" if this condition persists.
+	 */
+	p->reachable_bits <<= 1;
+
 	if (do_sendto(p->p_fd, /*from:*/ NULL, /*to:*/ &p->p_lsa->u.sa, /*addrlen:*/ p->p_lsa->len,
 			&p->p_xmt_msg, NTP_MSGSIZE_NOAUTH) == -1
 	) {
@@ -814,7 +822,6 @@ send_query_to_peer(peer_t *p)
 		return;
 	}
 
-	p->reachable_bits <<= 1;
 	set_next(p, RESPONSE_INTERVAL);
 }
 
@@ -2171,12 +2178,14 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv)
  did_poll:
 		gettime1900d(); /* sets G.cur_time */
 		if (nfds <= 0) {
-			if (G.script_name && G.cur_time - G.last_script_run > 11*60) {
+			if (!bb_got_signal /* poll wasn't interrupted by a signal */
+			 && G.cur_time - G.last_script_run > 11*60
+			) {
 				/* Useful for updating battery-backed RTC and such */
 				run_script("periodic", G.last_update_offset);
 				gettime1900d(); /* sets G.cur_time */
 			}
-			continue;
+			goto check_unsync;
 		}
 
 		/* Process any received packets */
@@ -2208,6 +2217,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv)
 			}
 		}
 
+ check_unsync:
 		if (G.ntp_peers && G.stratum != MAXSTRAT) {
 			for (item = G.ntp_peers; item != NULL; item = item->link) {
 				peer_t *p = (peer_t *) item->data;
_______________________________________________
busybox-cvs mailing list
busybox-cvs@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic