mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 18:25:07 -05:00
Add waitsync command
This commit is contained in:
54
client.c
54
client.c
@@ -1234,6 +1234,7 @@ give_help(void)
|
||||
printf("sourcestats [-v] : Display estimation information about current sources\n");
|
||||
printf("tracking : Display system time information\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("\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
|
||||
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);
|
||||
} else if (!strncmp(p, "reselect", 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)) {
|
||||
ret = process_cmd_dns(p+4);
|
||||
do_normal_submit = 0;
|
||||
|
||||
Reference in New Issue
Block a user