aboutsummaryrefslogtreecommitdiff
path: root/networking/ntpd.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-12-01 02:32:01 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-12-01 02:32:01 +0100
commitfae9f499b2ab3becb8a672d982c50f318114dee9 (patch)
tree0229761c21de96d2bda7a9be864052532382a028 /networking/ntpd.c
parent8eda4a9005723be93d8f5c0adb33e457e2f54dfe (diff)
downloadbusybox-w32-fae9f499b2ab3becb8a672d982c50f318114dee9.tar.gz
busybox-w32-fae9f499b2ab3becb8a672d982c50f318114dee9.tar.bz2
busybox-w32-fae9f499b2ab3becb8a672d982c50f318114dee9.zip
ntpd: make it work w/o -g too :(
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/ntpd.c')
-rw-r--r--networking/ntpd.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index c374120e2..f10a81cee 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -180,8 +180,8 @@ struct globals {
180 llist_t *ntp_peers; 180 llist_t *ntp_peers;
181 ntp_status_t status; 181 ntp_status_t status;
182 uint32_t scale; 182 uint32_t scale;
183 uint8_t settime; 183 uint8_t time_is_set;
184 uint8_t firstadj; 184 uint8_t first_adj_done;
185}; 185};
186#define G (*ptr_to_globals) 186#define G (*ptr_to_globals)
187 187
@@ -454,23 +454,25 @@ adjtime_wrap(void)
454 G.status.leap = peers[middle]->update.status.leap; 454 G.status.leap = peers[middle]->update.status.leap;
455 455
456 bb_info_msg("adjusting local clock by %fs", offset_median); 456 bb_info_msg("adjusting local clock by %fs", offset_median);
457 457 errno = 0;
458 d_to_tv(offset_median, &tv); 458 d_to_tv(offset_median, &tv);
459 if (adjtime(&tv, &olddelta) == -1) 459 if (adjtime(&tv, &olddelta) == -1) {
460 bb_error_msg("adjtime failed"); 460 bb_perror_msg("adjtime failed"); //TODO: maybe _and_die?
461 else if (!G.firstadj 461 } else
462 if (G.first_adj_done
462 && olddelta.tv_sec == 0 463 && olddelta.tv_sec == 0
463 && olddelta.tv_usec == 0 464 && olddelta.tv_usec == 0
464 && !G.status.synced 465 && !G.status.synced
465 ) { 466 ) {
466 bb_info_msg("clock synced"); 467 bb_info_msg("clock synced");
467 G.status.synced = 1; 468 G.status.synced = 1;
468 } else if (G.status.synced) { 469 } else
470 if (G.status.synced) {
469 bb_info_msg("clock unsynced"); 471 bb_info_msg("clock unsynced");
470 G.status.synced = 0; 472 G.status.synced = 0;
471 } 473 }
472 474
473 G.firstadj = 0; 475 G.first_adj_done = 1;
474 G.status.reftime = gettime1900fp(); 476 G.status.reftime = gettime1900fp();
475 G.status.stratum++; /* one more than selected peer */ 477 G.status.stratum++; /* one more than selected peer */
476 G.scale = updated_scale(offset_median); 478 G.scale = updated_scale(offset_median);
@@ -495,7 +497,7 @@ adjtime_wrap(void)
495} 497}
496 498
497static void 499static void
498settime(double offset) 500step_time_once(double offset)
499{ 501{
500 ntp_peer_t *p; 502 ntp_peer_t *p;
501 llist_t *item; 503 llist_t *item;
@@ -503,10 +505,9 @@ settime(double offset)
503 char buf[80]; 505 char buf[80];
504 time_t tval; 506 time_t tval;
505 507
506 if (!G.settime) 508 if (G.time_is_set)
507 goto bail; 509 goto bail;
508 510 G.time_is_set = 1;
509 G.settime = 0;
510 511
511 /* if the offset is small, don't call settimeofday */ 512 /* if the offset is small, don't call settimeofday */
512 if (offset < SETTIME_MIN_OFFSET && offset > -SETTIME_MIN_OFFSET) 513 if (offset < SETTIME_MIN_OFFSET && offset > -SETTIME_MIN_OFFSET)
@@ -514,6 +515,7 @@ settime(double offset)
514 515
515 gettimeofday(&curtime, NULL); /* never fails */ 516 gettimeofday(&curtime, NULL); /* never fails */
516 517
518//isn't it simpler to: offset += curtime.tv_sec; offset += 1.0e-6 * curtime.tv_usec?
517 d_to_tv(offset, &tv); 519 d_to_tv(offset, &tv);
518 curtime.tv_usec += tv.tv_usec + 1000000; 520 curtime.tv_usec += tv.tv_usec + 1000000;
519 curtime.tv_sec += tv.tv_sec - 1 + (curtime.tv_usec / 1000000); 521 curtime.tv_sec += tv.tv_sec - 1 + (curtime.tv_usec / 1000000);
@@ -708,7 +710,7 @@ recv_and_process_peer_pkt(ntp_peer_t *p)
708 offset->offset, offset->delay, (int) interval); 710 offset->offset, offset->delay, (int) interval);
709 711
710 update_peer_data(p); 712 update_peer_data(p);
711 settime(offset->offset); 713 step_time_once(offset->offset);
712 714
713 p->shift++; 715 p->shift++;
714 if (p->shift >= OFFSET_ARRAY_SIZE) 716 if (p->shift >= OFFSET_ARRAY_SIZE)
@@ -892,8 +894,9 @@ static NOINLINE void ntp_init(char **argv)
892 &peers, &G.verbose); 894 &peers, &G.verbose);
893 if (!(opts & (OPT_p|OPT_l))) 895 if (!(opts & (OPT_p|OPT_l)))
894 bb_show_usage(); 896 bb_show_usage();
895 if (opts & OPT_g) 897//WRONG
896 G.settime = 1; 898// if (opts & OPT_g)
899// G.time_is_set = 1;
897 while (peers) 900 while (peers)
898 add_peers(llist_pop(&peers)); 901 add_peers(llist_pop(&peers));
899 if (!(opts & OPT_n)) { 902 if (!(opts & OPT_n)) {
@@ -931,7 +934,6 @@ static NOINLINE void ntp_init(char **argv)
931 G.status.precision = prec; 934 G.status.precision = prec;
932 } 935 }
933 G.scale = 1; 936 G.scale = 1;
934 G.firstadj = 1;
935 937
936 bb_signals((1 << SIGTERM) | (1 << SIGINT), record_signo); 938 bb_signals((1 << SIGTERM) | (1 << SIGINT), record_signo);
937 bb_signals((1 << SIGPIPE) | (1 << SIGHUP), SIG_IGN); 939 bb_signals((1 << SIGPIPE) | (1 << SIGHUP), SIG_IGN);
@@ -1019,7 +1021,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv)
1019 } 1021 }
1020 1022
1021 if ((trial_cnt > 0 && sent_cnt == 0) || g.peer_cnt == 0) 1023 if ((trial_cnt > 0 && sent_cnt == 0) || g.peer_cnt == 0)
1022 settime(0); /* no good peers, don't wait */ 1024 step_time_once(0); /* no good peers, don't wait */
1023 1025
1024 timeout = nextaction - cur_time; 1026 timeout = nextaction - cur_time;
1025 if (timeout < 0) 1027 if (timeout < 0)