Add waitsync command
This commit is contained in:
parent
c6e9065498
commit
d6a91057ae
2 changed files with 81 additions and 0 deletions
27
chrony.texi
27
chrony.texi
|
@ -2898,6 +2898,7 @@ password:
|
||||||
@item @code{sources}
|
@item @code{sources}
|
||||||
@item @code{sourcestats}
|
@item @code{sourcestats}
|
||||||
@item @code{tracking}
|
@item @code{tracking}
|
||||||
|
@item @code{waitsync}
|
||||||
@end itemize
|
@end itemize
|
||||||
|
|
||||||
All other commands require a password to have been specified previously,
|
All other commands require a password to have been specified previously,
|
||||||
|
@ -2958,6 +2959,7 @@ interface.
|
||||||
* timeout command:: Set initial response timeout
|
* timeout command:: Set initial response timeout
|
||||||
* tracking command:: Display system clock performance
|
* tracking command:: Display system clock performance
|
||||||
* trimrtc command:: Correct the RTC time to the current system time
|
* trimrtc command:: Correct the RTC time to the current system time
|
||||||
|
* waitsync command:: Wait until synchronised
|
||||||
* writertc command:: Write the RTC parameters to file.
|
* writertc command:: Write the RTC parameters to file.
|
||||||
@end menu
|
@end menu
|
||||||
@c }}}
|
@c }}}
|
||||||
|
@ -4188,6 +4190,31 @@ across machine reboots even if the @code{trimrtc} command is never used
|
||||||
corrected, in a manner compatible with @code{chronyd} using it to
|
corrected, in a manner compatible with @code{chronyd} using it to
|
||||||
maintain accurate time across machine reboots.
|
maintain accurate time across machine reboots.
|
||||||
@c }}}
|
@c }}}
|
||||||
|
@c {{{ waitsync
|
||||||
|
@node waitsync command
|
||||||
|
@subsubsection waitsync
|
||||||
|
The @code{waitsync} command waits for @code{chronyd} to synchronise.
|
||||||
|
|
||||||
|
Up to three optional arguments can be specified, the first is the maximum
|
||||||
|
number of tries in 10 second intervals before giving up and returning a
|
||||||
|
non-zero error code. When 0 is specified, or there are no arguments, the
|
||||||
|
number of tries will not be limited.
|
||||||
|
|
||||||
|
The second and third arguments are the maximum allowed remaining correction of
|
||||||
|
the system clock and the maximum allowed skew (in ppm) as reported by the
|
||||||
|
@code{tracking} command (@pxref{tracking command}) in the @code{System time}
|
||||||
|
and @code{Skew} fields. If not specified or zero, the value will not be
|
||||||
|
checked.
|
||||||
|
|
||||||
|
An example is
|
||||||
|
|
||||||
|
@example
|
||||||
|
waitsync 60 0.01
|
||||||
|
@end example
|
||||||
|
|
||||||
|
which will wait up to about 10 minutes for @code{chronyd} to synchronise to a
|
||||||
|
source and the remaining correction to be less than 10 milliseconds.
|
||||||
|
@c }}}
|
||||||
@c {{{ writertc
|
@c {{{ writertc
|
||||||
@node writertc command
|
@node writertc command
|
||||||
@subsubsection writertc
|
@subsubsection writertc
|
||||||
|
|
54
client.c
54
client.c
|
@ -1234,6 +1234,7 @@ give_help(void)
|
||||||
printf("sourcestats [-v] : Display estimation information about current sources\n");
|
printf("sourcestats [-v] : Display estimation information about current sources\n");
|
||||||
printf("tracking : Display system time information\n");
|
printf("tracking : Display system time information\n");
|
||||||
printf("trimrtc : Correct RTC relative to system clock\n");
|
printf("trimrtc : Correct RTC relative to system clock\n");
|
||||||
|
printf("waitsync [max-tries [max-correction [max-skew]]] : Wait until synchronised\n");
|
||||||
printf("writertc : Save RTC parameters to file\n");
|
printf("writertc : Save RTC parameters to file\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("dns -n|+n : Disable/enable resolving IP addresses to hostnames\n");
|
printf("dns -n|+n : Disable/enable resolving IP addresses to hostnames\n");
|
||||||
|
@ -2402,6 +2403,56 @@ process_cmd_reselect(CMD_Request *msg, char *line)
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
process_cmd_waitsync(char *line)
|
||||||
|
{
|
||||||
|
CMD_Request request;
|
||||||
|
CMD_Reply reply;
|
||||||
|
uint32_t ref_id, a, b, c, d;
|
||||||
|
double correction, skew_ppm, max_correction, max_skew_ppm;
|
||||||
|
int ret = 0, max_tries, i;
|
||||||
|
|
||||||
|
max_tries = 0;
|
||||||
|
max_correction = 0.0;
|
||||||
|
max_skew_ppm = 0.0;
|
||||||
|
|
||||||
|
sscanf(line, "%d %lf %lf", &max_tries, &max_correction, &max_skew_ppm);
|
||||||
|
|
||||||
|
request.command = htons(REQ_TRACKING);
|
||||||
|
|
||||||
|
for (i = 1; ; i++) {
|
||||||
|
if (request_reply(&request, &reply, RPY_TRACKING, 0)) {
|
||||||
|
ref_id = ntohl(reply.data.tracking.ref_id);
|
||||||
|
a = (ref_id >> 24);
|
||||||
|
b = (ref_id >> 16) & 0xff;
|
||||||
|
c = (ref_id >> 8) & 0xff;
|
||||||
|
d = (ref_id) & 0xff;
|
||||||
|
|
||||||
|
correction = UTI_FloatNetworkToHost(reply.data.tracking.current_correction);
|
||||||
|
correction = fabs(correction);
|
||||||
|
skew_ppm = UTI_FloatNetworkToHost(reply.data.tracking.skew_ppm);
|
||||||
|
|
||||||
|
printf("try: %d, refid: %d.%d.%d.%d, correction: %.9f, skew: %.3f\n",
|
||||||
|
i, a, b, c, d, correction, skew_ppm);
|
||||||
|
|
||||||
|
if (ref_id != 0 && ref_id != 0x7f7f0101L /* LOCAL refid */ &&
|
||||||
|
(max_correction == 0.0 || correction <= max_correction) &&
|
||||||
|
(max_skew_ppm == 0.0 || skew_ppm <= max_skew_ppm)) {
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret && (!max_tries || i < max_tries)) {
|
||||||
|
sleep(10);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
process_cmd_dns(const char *line)
|
process_cmd_dns(const char *line)
|
||||||
{
|
{
|
||||||
|
@ -2579,6 +2630,9 @@ process_line(char *line, int *quit)
|
||||||
do_normal_submit = process_cmd_reselectdist(&tx_message, p+12);
|
do_normal_submit = process_cmd_reselectdist(&tx_message, p+12);
|
||||||
} else if (!strncmp(p, "reselect", 8)) {
|
} else if (!strncmp(p, "reselect", 8)) {
|
||||||
process_cmd_reselect(&tx_message, p+8);
|
process_cmd_reselect(&tx_message, p+8);
|
||||||
|
} else if (!strncmp(p, "waitsync", 8)) {
|
||||||
|
ret = process_cmd_waitsync(p+8);
|
||||||
|
do_normal_submit = 0;
|
||||||
} else if (!strncmp(p, "dns ", 4)) {
|
} else if (!strncmp(p, "dns ", 4)) {
|
||||||
ret = process_cmd_dns(p+4);
|
ret = process_cmd_dns(p+4);
|
||||||
do_normal_submit = 0;
|
do_normal_submit = 0;
|
||||||
|
|
Loading…
Reference in a new issue