From 698f270b5bb5c7a3dcbf79d8e959108c791b469f Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 5 Oct 2020 11:05:37 +0200 Subject: [PATCH] cmdmon: add leap status to selectdata report --- candm.h | 3 ++- client.c | 17 +++++++++-------- cmdmon.c | 1 + doc/chronyc.adoc | 16 +++++++++++----- reports.h | 1 + sources.c | 1 + test/system/007-cmdmon | 6 +++--- 7 files changed, 28 insertions(+), 17 deletions(-) diff --git a/candm.h b/candm.h index 2390302..7c36779 100644 --- a/candm.h +++ b/candm.h @@ -764,7 +764,8 @@ typedef struct { IPAddr ip_addr; uint8_t state_char; uint8_t authentication; - uint8_t pad[2]; + uint8_t leap; + uint8_t pad; uint16_t conf_options; uint16_t eff_options; uint32_t last_sample_ago; diff --git a/client.c b/client.c index ec5f354..e136181 100644 --- a/client.c +++ b/client.c @@ -1863,19 +1863,19 @@ print_report(const char *format, ...) integer = va_arg(ap, int); switch (integer) { case LEAP_Normal: - string = "Normal"; + string = width != 1 ? "Normal" : "N"; break; case LEAP_InsertSecond: - string = "Insert second"; + string = width != 1 ? "Insert second" : "+"; break; case LEAP_DeleteSecond: - string = "Delete second"; + string = width != 1 ? "Delete second" : "-"; break; case LEAP_Unsynchronised: - string = "Not synchronised"; + string = width != 1 ? "Not synchronised" : "?"; break; default: - string = "Invalid"; + string = width != 1 ? "Invalid" : "?"; break; } printf("%s", string); @@ -2557,9 +2557,9 @@ process_cmd_selectdata(char *line) printf( "| | | | |\n"); } - print_header("S Name/IP Address Auth COpts EOpts Last Score Interval "); + print_header("S Name/IP Address Auth COpts EOpts Last Score Interval Leap"); - /* "S NNNNNNNNNNNNNNNNNNNNNNNNN A OOOO- OOOO- LLLL SSSSS LLLLLLL LLLLLLL" */ + /* "S NNNNNNNNNNNNNNNNNNNNNNNNN A OOOO- OOOO- LLLL SSSSS IIIIIII IIIIIII L" */ for (i = 0; i < n_sources; i++) { request.command = htons(REQ_SELECT_DATA); @@ -2577,7 +2577,7 @@ process_cmd_selectdata(char *line) conf_options = ntohs(reply.data.select_data.conf_options); eff_options = ntohs(reply.data.select_data.eff_options); - print_report("%c %-25s %c %c%c%c%c%c %c%c%c%c%c %I %5.1f %+S %+S\n", + print_report("%c %-25s %c %c%c%c%c%c %c%c%c%c%c %I %5.1f %+S %+S %1L\n", reply.data.select_data.state_char, name, reply.data.select_data.authentication ? 'Y' : 'N', @@ -2595,6 +2595,7 @@ process_cmd_selectdata(char *line) UTI_FloatNetworkToHost(reply.data.select_data.score), UTI_FloatNetworkToHost(reply.data.select_data.lo_limit), UTI_FloatNetworkToHost(reply.data.select_data.hi_limit), + reply.data.select_data.leap, REPORT_END); } diff --git a/cmdmon.c b/cmdmon.c index c17db0c..b8224de 100644 --- a/cmdmon.c +++ b/cmdmon.c @@ -1327,6 +1327,7 @@ handle_select_data(CMD_Request *rx_message, CMD_Reply *tx_message) UTI_IPHostToNetwork(&report.ip_addr, &tx_message->data.select_data.ip_addr); tx_message->data.select_data.state_char = report.state_char; tx_message->data.select_data.authentication = report.authentication; + tx_message->data.select_data.leap = report.leap; tx_message->data.select_data.conf_options = htons(convert_select_options(report.conf_options)); tx_message->data.select_data.eff_options = htons(convert_select_options(report.eff_options)); tx_message->data.select_data.last_sample_ago = htonl(report.last_sample_ago); diff --git a/doc/chronyc.adoc b/doc/chronyc.adoc index e416945..d12d6b3 100644 --- a/doc/chronyc.adoc +++ b/doc/chronyc.adoc @@ -432,11 +432,11 @@ lines are shown as a reminder of the meanings of the columns. An example of the output is shown below. + ---- -S Name/IP Address Auth COpts EOpts Last Score Interval -==================================================================== -D foo.example.net Y ----- --TR- 4 1.0 -61ms +62ms -* bar.example.net N ----- ----- 0 1.0 -6846us +7305us -+ baz.example.net N ----- ----- 10 1.0 -7381us +7355us +S Name/IP Address Auth COpts EOpts Last Score Interval Leap +======================================================================= +D foo.example.net Y ----- --TR- 4 1.0 -61ms +62ms N +* bar.example.net N ----- ----- 0 1.0 -6846us +7305us N ++ baz.example.net N ----- ----- 10 1.0 -7381us +7355us N ---- + The columns are as follows: @@ -508,6 +508,12 @@ be reselected and the scores will be reset to 1. This column displays the lower and upper endpoint of the interval which was expected to contain the true offset of the local clock considering the root distance at the time of the selection. +*Leap*::: +This column displays the current leap status of the source. +* _N_ indicates the normal status (no leap second). +* _+_ indicates that a leap second will be inserted at the end of the month. +* _-_ indicates that a leap second will be deleted at the end of the month. +* _?_ indicates the unknown status (i.e. no valid measurement was made). [[reselect]]*reselect*:: To avoid excessive switching between sources, *chronyd* can stay synchronised diff --git a/reports.h b/reports.h index 9776974..4508e8f 100644 --- a/reports.h +++ b/reports.h @@ -190,6 +190,7 @@ typedef struct { IPAddr ip_addr; char state_char; int authentication; + NTP_Leap leap; int conf_options; int eff_options; uint32_t last_sample_ago; diff --git a/sources.c b/sources.c index 260cd85..67bc5d8 100644 --- a/sources.c +++ b/sources.c @@ -1610,6 +1610,7 @@ SRC_GetSelectReport(int index, RPT_SelectReport *report) report->ip_addr.family = IPADDR_UNSPEC; report->state_char = get_status_char(inst->status); report->authentication = inst->authenticated; + report->leap = inst->leap; report->conf_options = inst->conf_sel_options; report->eff_options = inst->sel_options; report->last_sample_ago = inst->sel_info.last_sample_ago; diff --git a/test/system/007-cmdmon b/test/system/007-cmdmon index c0e108e..37a1d34 100755 --- a/test/system/007-cmdmon +++ b/test/system/007-cmdmon @@ -96,9 +96,9 @@ Total RX : [0-9]+ Total valid RX : [0-9]+$" || test_fail run_chronyc "selectdata" || test_fail -check_chronyc_output "^S Name/IP Address Auth COpts EOpts Last Score Interval + -==================================================================== -M 127\.0\.0\.1 N ----- ----- 0 1\.0 \+0ns \+0ns$" || test_fail +check_chronyc_output "^S Name/IP Address Auth COpts EOpts Last Score Interval Leap +======================================================================= +M 127\.0\.0\.1 N ----- ----- 0 1\.0 \+0ns \+0ns \?$" || test_fail run_chronyc "serverstats" || test_fail check_chronyc_output "^NTP packets received : [0-9]+