aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-12-18 18:50:29 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-12-18 18:50:29 +0100
commit6879a7ae4393e4a94490e297dbe8b836c6c7dd15 (patch)
tree4f055c64dba63d0642e01e9e5de60dc362993309
parent4b6abf6655ce664e25be2bc977b2d5e3f1946bbb (diff)
downloadbusybox-w32-6879a7ae4393e4a94490e297dbe8b836c6c7dd15.tar.gz
busybox-w32-6879a7ae4393e4a94490e297dbe8b836c6c7dd15.tar.bz2
busybox-w32-6879a7ae4393e4a94490e297dbe8b836c6c7dd15.zip
ntpd: fx incorrect offset display when stepping
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/ntpd.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 719b00550..1c53e3152 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -98,7 +98,7 @@ typedef struct {
98 double d_offset; 98 double d_offset;
99 double d_delay; 99 double d_delay;
100 //UNUSED: double d_error; 100 //UNUSED: double d_error;
101 time_t d_rcvd; 101 time_t d_rcv_time;
102 uint32_t d_refid4; 102 uint32_t d_refid4;
103 uint8_t d_leap; 103 uint8_t d_leap;
104 uint8_t d_stratum; 104 uint8_t d_stratum;
@@ -147,8 +147,8 @@ struct globals {
147 uint32_t refid4; 147 uint32_t refid4;
148 uint8_t synced; 148 uint8_t synced;
149 uint8_t leap; 149 uint8_t leap;
150#define G_precision -6 150#define G_precision_exp -6
151// int8_t precision; 151// int8_t precision_exp;
152 uint8_t stratum; 152 uint8_t stratum;
153 uint8_t time_was_stepped; 153 uint8_t time_was_stepped;
154 uint8_t first_adj_done; 154 uint8_t first_adj_done;
@@ -352,6 +352,7 @@ send_query_to_peer(ntp_peer_t *p)
352static void 352static void
353step_time_once(double offset) 353step_time_once(double offset)
354{ 354{
355 double dtime;
355 llist_t *item; 356 llist_t *item;
356 struct timeval tv; 357 struct timeval tv;
357 char buf[80]; 358 char buf[80];
@@ -366,9 +367,9 @@ step_time_once(double offset)
366 goto bail; 367 goto bail;
367 368
368 gettimeofday(&tv, NULL); /* never fails */ 369 gettimeofday(&tv, NULL); /* never fails */
369 offset += tv.tv_sec; 370 dtime = offset + tv.tv_sec;
370 offset += 1.0e-6 * tv.tv_usec; 371 dtime += 1.0e-6 * tv.tv_usec;
371 d_to_tv(offset, &tv); 372 d_to_tv(dtime, &tv);
372 373
373 if (settimeofday(&tv, NULL) == -1) 374 if (settimeofday(&tv, NULL) == -1)
374 bb_perror_msg_and_die("settimeofday"); 375 bb_perror_msg_and_die("settimeofday");
@@ -380,7 +381,7 @@ step_time_once(double offset)
380 381
381 for (item = G.ntp_peers; item != NULL; item = item->link) { 382 for (item = G.ntp_peers; item != NULL; item = item->link) {
382 ntp_peer_t *p = (ntp_peer_t *) item->data; 383 ntp_peer_t *p = (ntp_peer_t *) item->data;
383 p->next_action_time -= offset; 384 p->next_action_time -= (time_t)offset;
384 } 385 }
385 386
386 bail: 387 bail:
@@ -517,11 +518,11 @@ update_peer_data(ntp_peer_t *p)
517 if (good < 8) //FIXME: was it meant to be NUM_DATAPOINTS, not 8? 518 if (good < 8) //FIXME: was it meant to be NUM_DATAPOINTS, not 8?
518 return; 519 return;
519 520
520 memcpy(&p->update, &p->p_datapoint[best], sizeof(p->update)); 521 p->update = p->p_datapoint[best]; /* struct copy */
521 slew_time(); 522 slew_time();
522 523
523 for (i = 0; i < NUM_DATAPOINTS; i++) 524 for (i = 0; i < NUM_DATAPOINTS; i++)
524 if (p->p_datapoint[i].d_rcvd <= p->p_datapoint[best].d_rcvd) 525 if (p->p_datapoint[i].d_rcv_time <= p->p_datapoint[best].d_rcv_time)
525 p->p_datapoint[i].d_good = 0; 526 p->p_datapoint[i].d_good = 0;
526} 527}
527 528
@@ -614,7 +615,7 @@ recv_and_process_peer_pkt(ntp_peer_t *p)
614 goto close_sock; 615 goto close_sock;
615 } 616 }
616 //UNUSED: datapoint->d_error = (T2 - T1) - (T3 - T4); 617 //UNUSED: datapoint->d_error = (T2 - T1) - (T3 - T4);
617 datapoint->d_rcvd = (time_t)(T4 - OFFSET_1900_1970); /* = time(NULL); */ 618 datapoint->d_rcv_time = (time_t)(T4 - OFFSET_1900_1970); /* = time(NULL); */
618 datapoint->d_good = 1; 619 datapoint->d_good = 1;
619 620
620 datapoint->d_leap = (msg.m_status & LI_MASK); 621 datapoint->d_leap = (msg.m_status & LI_MASK);
@@ -709,7 +710,7 @@ recv_and_process_client_pkt(void /*int fd*/)
709 MODE_SERVER : MODE_SYM_PAS; 710 MODE_SERVER : MODE_SYM_PAS;
710 msg.m_stratum = G.stratum; 711 msg.m_stratum = G.stratum;
711 msg.m_ppoll = query_ppoll; 712 msg.m_ppoll = query_ppoll;
712 msg.m_precision = G_precision; 713 msg.m_precision = G_precision_exp;
713 rectime = gettime1900d(); 714 rectime = gettime1900d();
714 msg.m_xmttime = msg.m_rectime = d_to_lfp(rectime); 715 msg.m_xmttime = msg.m_rectime = d_to_lfp(rectime);
715 msg.m_reftime = d_to_lfp(G.reftime); 716 msg.m_reftime = d_to_lfp(G.reftime);
@@ -861,7 +862,7 @@ static NOINLINE void ntp_init(char **argv)
861 862
862 /* Set some globals */ 863 /* Set some globals */
863#if 0 864#if 0
864 /* With constant b = 100, G.precision is also constant -6. 865 /* With constant b = 100, G.precision_exp is also constant -6.
865 * Uncomment this and you'll see */ 866 * Uncomment this and you'll see */
866 { 867 {
867 int prec = 0; 868 int prec = 0;
@@ -878,8 +879,8 @@ static NOINLINE void ntp_init(char **argv)
878# endif 879# endif
879 while (b > 1) 880 while (b > 1)
880 prec--, b >>= 1; 881 prec--, b >>= 1;
881 //G.precision = prec; 882 //G.precision_exp = prec;
882 bb_error_msg("G.precision:%d", prec); /* -6 */ 883 bb_error_msg("G.precision_exp:%d", prec); /* -6 */
883 } 884 }
884#endif 885#endif
885 G.scale = 1; 886 G.scale = 1;