aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-04 00:19:13 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-04 00:19:13 +0100
commit4168fdd8e6f5ad4d41a30a2350dbd635cc0fa6e1 (patch)
tree43c1ae5aa9fd90f8500319d01a98a87cad4b3fa1
parentd6459685c1a93785d0bdf94e16834a6d4c54842f (diff)
downloadbusybox-4168fdd8e6f5ad4d41a30a2350dbd635cc0fa6e1.tar.gz
ntpd: add -w "watch" option, useful for debugging to look at our own data
Also fixed a small buglet discovered using -w function old new delta recv_and_process_peer_pkt 895 944 +49 select_and_cluster 1132 1150 +18 packed_usage 26769 26767 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/usage.h3
-rw-r--r--networking/ntpd.c39
2 files changed, 28 insertions, 14 deletions
diff --git a/include/usage.h b/include/usage.h
index 9f4c44891..5a2524112 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -3223,7 +3223,7 @@
"Address: 127.0.0.1\n"
#define ntpd_trivial_usage \
- "[-dngql] [-p PEER]..."
+ "[-dnqwl] [-p PEER]..."
#define ntpd_full_usage "\n\n" \
"NTP client/server\n" \
"\nOptions:" \
@@ -3233,6 +3233,7 @@
/* -N exists for mostly compat reasons, thus not essential to inform */ \
/* the user that it exists: user may use nice as well */ \
/* "\n -N Run at high priority" */ \
+ "\n -w Do not set time (used to look at peer data)" \
"\n -l Run as server on port 123" \
"\n -p PEER Obtain time from PEER (may be repeated)" \
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 771a75a69..84ee54307 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -192,8 +192,9 @@ enum {
OPT_x = (1 << 3),
/* Insert new options above this line. */
/* Non-compat options: */
- OPT_p = (1 << 4),
- OPT_l = (1 << 5) * ENABLE_FEATURE_NTPD_SERVER,
+ OPT_w = (1 << 4),
+ OPT_p = (1 << 5),
+ OPT_l = (1 << 6) * ENABLE_FEATURE_NTPD_SERVER,
};
struct globals {
@@ -940,7 +941,7 @@ select_and_cluster(void)
double min_jitter = min_jitter;
if (num_survivors <= MIN_CLUSTERED) {
- bb_error_msg("num_survivors %d <= %d, not discarding more",
+ VERB3 bb_error_msg("num_survivors %d <= %d, not discarding more",
num_survivors, MIN_CLUSTERED);
break;
}
@@ -1381,8 +1382,8 @@ recv_and_process_peer_pkt(peer_t *p)
|| errno == EAGAIN
) {
//TODO: always do this?
- set_next(p, retry_interval());
- goto close_sock;
+ interval = retry_interval();
+ goto set_next_and_close_sock;
}
xfunc_die();
}
@@ -1407,7 +1408,7 @@ recv_and_process_peer_pkt(peer_t *p)
// "RATE" - peer is overloaded, reduce polling freq
interval = poll_interval(0);
bb_error_msg("reply from %s: not synced, next query in %us", p->p_dotted, interval);
- goto close_sock;
+ goto set_next_and_close_sock;
}
// /* Verify valid root distance */
@@ -1466,18 +1467,30 @@ recv_and_process_peer_pkt(peer_t *p)
p->reachable_bits |= 1;
VERB1 {
- bb_error_msg("reply from %s: reach 0x%02x offset %f delay %f",
+ bb_error_msg("reply from %s: reach 0x%02x offset %f delay %f status 0x%02x strat %d refid 0x%08x rootdelay %f",
p->p_dotted,
p->reachable_bits,
- datapoint->d_offset, p->lastpkt_delay);
+ datapoint->d_offset,
+ p->lastpkt_delay,
+ p->lastpkt_status,
+ p->lastpkt_stratum,
+ p->lastpkt_refid,
+ p->lastpkt_rootdelay
+ /* not shown: m_ppoll, m_precision_exp, m_rootdisp,
+ * m_reftime, m_orgtime, m_rectime, m_xmttime
+ */
+ );
}
/* Muck with statictics and update the clock */
filter_datapoints(p);
q = select_and_cluster();
rc = -1;
- if (q)
- rc = update_local_clock(q);
+ if (q) {
+ rc = 0;
+ if (!(option_mask32 & OPT_w))
+ rc = update_local_clock(q);
+ }
if (rc != 0) {
/* Adjust the poll interval by comparing the current offset
@@ -1537,9 +1550,9 @@ recv_and_process_peer_pkt(peer_t *p)
/* Decide when to send new query for this peer */
interval = poll_interval(0);
- set_next(p, interval);
- close_sock:
+ set_next_and_close_sock:
+ set_next(p, interval);
/* We do not expect any more packets from this peer for now.
* Closing the socket informs kernel about it.
* We open a new socket when we send a new query.
@@ -1723,7 +1736,7 @@ static NOINLINE void ntp_init(char **argv)
opt_complementary = "dd:p::"; /* d: counter, p: list */
opts = getopt32(argv,
"nqNx" /* compat */
- "p:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */
+ "wp:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */
"d" /* compat */
"46aAbgL", /* compat, ignored */
&peers, &G.verbose);