diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-02 02:30:31 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-02 02:30:31 +0100 |
commit | f91e63cbc3aa46ed0ed39d9aa664594f418da255 (patch) | |
tree | 27a59049eefa6d457bcb5ec975029d1cc2a241e3 /networking/ntpd.c | |
parent | 386960a38e5aee4f56a04214f86709c71dff120d (diff) | |
download | busybox-w32-f91e63cbc3aa46ed0ed39d9aa664594f418da255.tar.gz busybox-w32-f91e63cbc3aa46ed0ed39d9aa664594f418da255.tar.bz2 busybox-w32-f91e63cbc3aa46ed0ed39d9aa664594f418da255.zip |
ntpd: continuing small message tweaks and the like. -29 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/ntpd.c')
-rw-r--r-- | networking/ntpd.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index 3b9e7b7ff..17748b0f1 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -171,7 +171,7 @@ struct globals { | |||
171 | uint8_t leap; | 171 | uint8_t leap; |
172 | int8_t precision; | 172 | int8_t precision; |
173 | uint8_t stratum; | 173 | uint8_t stratum; |
174 | uint8_t time_is_set; | 174 | uint8_t time_is_stepped; |
175 | uint8_t first_adj_done; | 175 | uint8_t first_adj_done; |
176 | }; | 176 | }; |
177 | #define G (*ptr_to_globals) | 177 | #define G (*ptr_to_globals) |
@@ -372,7 +372,7 @@ send_query_to_peer(ntp_peer_t *p) | |||
372 | } | 372 | } |
373 | 373 | ||
374 | if (G.verbose) | 374 | if (G.verbose) |
375 | bb_error_msg("sent request to %s", p->dotted); | 375 | bb_error_msg("sent query to %s", p->dotted); |
376 | p->state = STATE_QUERY_SENT; | 376 | p->state = STATE_QUERY_SENT; |
377 | set_deadline(p, QUERYTIME_MAX); | 377 | set_deadline(p, QUERYTIME_MAX); |
378 | 378 | ||
@@ -498,37 +498,34 @@ static void | |||
498 | step_time_once(double offset) | 498 | step_time_once(double offset) |
499 | { | 499 | { |
500 | ntp_peer_t *p; | 500 | ntp_peer_t *p; |
501 | llist_t *item; | 501 | llist_t *item; |
502 | struct timeval tv, curtime; | 502 | struct timeval tv; |
503 | char buf[80]; | 503 | char buf[80]; |
504 | time_t tval; | 504 | time_t tval; |
505 | 505 | ||
506 | if (G.time_is_set) | 506 | if (G.time_is_stepped) |
507 | goto bail; | 507 | goto bail; |
508 | G.time_is_set = 1; | 508 | G.time_is_stepped = 1; |
509 | 509 | ||
510 | /* if the offset is small, don't call settimeofday */ | 510 | /* if the offset is small, don't call settimeofday */ |
511 | if (offset < SETTIME_MIN_OFFSET && offset > -SETTIME_MIN_OFFSET) | 511 | if (offset < SETTIME_MIN_OFFSET && offset > -SETTIME_MIN_OFFSET) |
512 | goto bail; | 512 | goto bail; |
513 | 513 | ||
514 | gettimeofday(&curtime, NULL); /* never fails */ | 514 | gettimeofday(&tv, NULL); /* never fails */ |
515 | 515 | offset += tv.tv_sec; | |
516 | //isn't it simpler to: offset += curtime.tv_sec; offset += 1.0e-6 * curtime.tv_usec? | 516 | offset += 1.0e-6 * tv.tv_usec; |
517 | d_to_tv(offset, &tv); | 517 | d_to_tv(offset, &tv); |
518 | curtime.tv_usec += tv.tv_usec + 1000000; | ||
519 | curtime.tv_sec += tv.tv_sec - 1 + (curtime.tv_usec / 1000000); | ||
520 | curtime.tv_usec %= 1000000; | ||
521 | 518 | ||
522 | if (settimeofday(&curtime, NULL) == -1) { | 519 | if (settimeofday(&tv, NULL) == -1) { |
523 | bb_error_msg("settimeofday"); | 520 | bb_error_msg("settimeofday"); |
524 | goto bail; | 521 | goto bail; |
525 | } | 522 | } |
526 | 523 | ||
527 | tval = curtime.tv_sec; | 524 | tval = tv.tv_sec; |
528 | strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %Z %Y", localtime(&tval)); | 525 | strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %Z %Y", localtime(&tval)); |
529 | 526 | ||
530 | /* Do we want to print message below to system log when daemonized? */ | 527 | // Do we want to print message below to system log when daemonized? |
531 | bb_error_msg("set local clock to %s (offset %fs)", buf, offset); | 528 | bb_error_msg("setting clock to %s (offset %fs)", buf, offset); |
532 | 529 | ||
533 | for (item = G.ntp_peers; item != NULL; item = item->link) { | 530 | for (item = G.ntp_peers; item != NULL; item = item->link) { |
534 | p = (ntp_peer_t *) item->data; | 531 | p = (ntp_peer_t *) item->data; |
@@ -638,7 +635,7 @@ recv_and_process_peer_pkt(ntp_peer_t *p) | |||
638 | || msg.m_stratum > NTP_MAXSTRATUM | 635 | || msg.m_stratum > NTP_MAXSTRATUM |
639 | ) { | 636 | ) { |
640 | interval = error_interval(); | 637 | interval = error_interval(); |
641 | bb_error_msg("reply from %s: not synced, next query %us", p->dotted, interval); | 638 | bb_error_msg("reply from %s: not synced, next query in %us", p->dotted, interval); |
642 | goto close_sock; | 639 | goto close_sock; |
643 | } | 640 | } |
644 | 641 | ||
@@ -704,10 +701,11 @@ recv_and_process_peer_pkt(ntp_peer_t *p) | |||
704 | } | 701 | } |
705 | 702 | ||
706 | if (G.verbose) | 703 | if (G.verbose) |
707 | bb_error_msg("reply from %s: offset %f delay %f, next query %us", p->dotted, | 704 | bb_error_msg("reply from %s: offset %f delay %f, next query in %us", p->dotted, |
708 | offset->o_offset, offset->o_delay, interval); | 705 | offset->o_offset, offset->o_delay, interval); |
709 | 706 | ||
710 | update_peer_data(p); | 707 | update_peer_data(p); |
708 | //TODO: do it after all peers had a chance to return at least one reply? | ||
711 | step_time_once(offset->o_offset); | 709 | step_time_once(offset->o_offset); |
712 | 710 | ||
713 | p->shift++; | 711 | p->shift++; |
@@ -901,7 +899,7 @@ static NOINLINE void ntp_init(char **argv) | |||
901 | bb_show_usage(); | 899 | bb_show_usage(); |
902 | //WRONG | 900 | //WRONG |
903 | // if (opts & OPT_g) | 901 | // if (opts & OPT_g) |
904 | // G.time_is_set = 1; | 902 | // G.time_is_stepped = 1; |
905 | while (peers) | 903 | while (peers) |
906 | add_peers(llist_pop(&peers)); | 904 | add_peers(llist_pop(&peers)); |
907 | if (!(opts & OPT_n)) { | 905 | if (!(opts & OPT_n)) { |
@@ -998,7 +996,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) | |||
998 | /* Timed out waiting for reply */ | 996 | /* Timed out waiting for reply */ |
999 | timeout = error_interval(); | 997 | timeout = error_interval(); |
1000 | bb_error_msg("timed out waiting for %s, " | 998 | bb_error_msg("timed out waiting for %s, " |
1001 | "next query %us", p->dotted, timeout); | 999 | "next query in %us", p->dotted, timeout); |
1002 | if (p->trustlevel >= TRUSTLEVEL_BADPEER) { | 1000 | if (p->trustlevel >= TRUSTLEVEL_BADPEER) { |
1003 | p->trustlevel /= 2; | 1001 | p->trustlevel /= 2; |
1004 | if (p->trustlevel < TRUSTLEVEL_BADPEER) | 1002 | if (p->trustlevel < TRUSTLEVEL_BADPEER) |
@@ -1030,7 +1028,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) | |||
1030 | 1028 | ||
1031 | /* Here we may block */ | 1029 | /* Here we may block */ |
1032 | if (g.verbose >= 2) | 1030 | if (g.verbose >= 2) |
1033 | bb_error_msg("poll %u sec, waiting on %u sockets", timeout, i); | 1031 | bb_error_msg("poll %u sec, sockets:%u", timeout, i); |
1034 | nfds = poll(pfd, i, timeout * 1000); | 1032 | nfds = poll(pfd, i, timeout * 1000); |
1035 | if (nfds <= 0) | 1033 | if (nfds <= 0) |
1036 | continue; | 1034 | continue; |