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>
This commit is contained in:
@ -3223,7 +3223,7 @@
|
|||||||
"Address: 127.0.0.1\n"
|
"Address: 127.0.0.1\n"
|
||||||
|
|
||||||
#define ntpd_trivial_usage \
|
#define ntpd_trivial_usage \
|
||||||
"[-dngql] [-p PEER]..."
|
"[-dnqwl] [-p PEER]..."
|
||||||
#define ntpd_full_usage "\n\n" \
|
#define ntpd_full_usage "\n\n" \
|
||||||
"NTP client/server\n" \
|
"NTP client/server\n" \
|
||||||
"\nOptions:" \
|
"\nOptions:" \
|
||||||
@ -3233,6 +3233,7 @@
|
|||||||
/* -N exists for mostly compat reasons, thus not essential to inform */ \
|
/* -N exists for mostly compat reasons, thus not essential to inform */ \
|
||||||
/* the user that it exists: user may use nice as well */ \
|
/* the user that it exists: user may use nice as well */ \
|
||||||
/* "\n -N Run at high priority" */ \
|
/* "\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 -l Run as server on port 123" \
|
||||||
"\n -p PEER Obtain time from PEER (may be repeated)" \
|
"\n -p PEER Obtain time from PEER (may be repeated)" \
|
||||||
|
|
||||||
|
@ -192,8 +192,9 @@ enum {
|
|||||||
OPT_x = (1 << 3),
|
OPT_x = (1 << 3),
|
||||||
/* Insert new options above this line. */
|
/* Insert new options above this line. */
|
||||||
/* Non-compat options: */
|
/* Non-compat options: */
|
||||||
OPT_p = (1 << 4),
|
OPT_w = (1 << 4),
|
||||||
OPT_l = (1 << 5) * ENABLE_FEATURE_NTPD_SERVER,
|
OPT_p = (1 << 5),
|
||||||
|
OPT_l = (1 << 6) * ENABLE_FEATURE_NTPD_SERVER,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct globals {
|
struct globals {
|
||||||
@ -940,7 +941,7 @@ select_and_cluster(void)
|
|||||||
double min_jitter = min_jitter;
|
double min_jitter = min_jitter;
|
||||||
|
|
||||||
if (num_survivors <= MIN_CLUSTERED) {
|
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);
|
num_survivors, MIN_CLUSTERED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1381,8 +1382,8 @@ recv_and_process_peer_pkt(peer_t *p)
|
|||||||
|| errno == EAGAIN
|
|| errno == EAGAIN
|
||||||
) {
|
) {
|
||||||
//TODO: always do this?
|
//TODO: always do this?
|
||||||
set_next(p, retry_interval());
|
interval = retry_interval();
|
||||||
goto close_sock;
|
goto set_next_and_close_sock;
|
||||||
}
|
}
|
||||||
xfunc_die();
|
xfunc_die();
|
||||||
}
|
}
|
||||||
@ -1407,7 +1408,7 @@ recv_and_process_peer_pkt(peer_t *p)
|
|||||||
// "RATE" - peer is overloaded, reduce polling freq
|
// "RATE" - peer is overloaded, reduce polling freq
|
||||||
interval = poll_interval(0);
|
interval = poll_interval(0);
|
||||||
bb_error_msg("reply from %s: not synced, next query in %us", p->p_dotted, interval);
|
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 */
|
// /* Verify valid root distance */
|
||||||
@ -1466,18 +1467,30 @@ recv_and_process_peer_pkt(peer_t *p)
|
|||||||
|
|
||||||
p->reachable_bits |= 1;
|
p->reachable_bits |= 1;
|
||||||
VERB1 {
|
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->p_dotted,
|
||||||
p->reachable_bits,
|
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 */
|
/* Muck with statictics and update the clock */
|
||||||
filter_datapoints(p);
|
filter_datapoints(p);
|
||||||
q = select_and_cluster();
|
q = select_and_cluster();
|
||||||
rc = -1;
|
rc = -1;
|
||||||
if (q)
|
if (q) {
|
||||||
rc = update_local_clock(q);
|
rc = 0;
|
||||||
|
if (!(option_mask32 & OPT_w))
|
||||||
|
rc = update_local_clock(q);
|
||||||
|
}
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
/* Adjust the poll interval by comparing the current offset
|
/* 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 */
|
/* Decide when to send new query for this peer */
|
||||||
interval = poll_interval(0);
|
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.
|
/* We do not expect any more packets from this peer for now.
|
||||||
* Closing the socket informs kernel about it.
|
* Closing the socket informs kernel about it.
|
||||||
* We open a new socket when we send a new query.
|
* 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 */
|
opt_complementary = "dd:p::"; /* d: counter, p: list */
|
||||||
opts = getopt32(argv,
|
opts = getopt32(argv,
|
||||||
"nqNx" /* compat */
|
"nqNx" /* compat */
|
||||||
"p:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */
|
"wp:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */
|
||||||
"d" /* compat */
|
"d" /* compat */
|
||||||
"46aAbgL", /* compat, ignored */
|
"46aAbgL", /* compat, ignored */
|
||||||
&peers, &G.verbose);
|
&peers, &G.verbose);
|
||||||
|
Reference in New Issue
Block a user