client: add -e option to indicate end of response
In a non-tty session with chronyc it is not possible to detect the end of the response without relying on timeouts, or separate responses to a repeated command if using the -c option. Add -e option to end each response with a line containing a single dot.
This commit is contained in:
parent
221e5fb501
commit
1eb8994c00
3 changed files with 27 additions and 1 deletions
12
client.c
12
client.c
|
@ -71,6 +71,8 @@ static int source_names = 0;
|
||||||
|
|
||||||
static int csv_mode = 0;
|
static int csv_mode = 0;
|
||||||
|
|
||||||
|
static int end_dot = 0;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Log a message. This is a minimalistic replacement of the logging.c
|
/* Log a message. This is a minimalistic replacement of the logging.c
|
||||||
implementation to avoid linking with it and other modules. */
|
implementation to avoid linking with it and other modules. */
|
||||||
|
@ -3303,6 +3305,10 @@ process_line(char *line)
|
||||||
ret = request_reply(&tx_message, &rx_message, RPY_NULL, 1);
|
ret = request_reply(&tx_message, &rx_message, RPY_NULL, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (end_dot) {
|
||||||
|
printf(".\n");
|
||||||
|
}
|
||||||
|
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
|
||||||
if (fflush(stdout) != 0 || ferror(stdout) != 0) {
|
if (fflush(stdout) != 0 || ferror(stdout) != 0) {
|
||||||
|
@ -3379,6 +3385,7 @@ print_help(const char *progname)
|
||||||
" -n\t\tDon't resolve hostnames\n"
|
" -n\t\tDon't resolve hostnames\n"
|
||||||
" -N\t\tPrint original source names\n"
|
" -N\t\tPrint original source names\n"
|
||||||
" -c\t\tEnable CSV format\n"
|
" -c\t\tEnable CSV format\n"
|
||||||
|
" -e\t\tEnd responses with dot\n"
|
||||||
#if DEBUG > 0
|
#if DEBUG > 0
|
||||||
" -d\t\tEnable debug messages\n"
|
" -d\t\tEnable debug messages\n"
|
||||||
#endif
|
#endif
|
||||||
|
@ -3423,7 +3430,7 @@ main(int argc, char **argv)
|
||||||
optind = 1;
|
optind = 1;
|
||||||
|
|
||||||
/* Parse short command-line options */
|
/* Parse short command-line options */
|
||||||
while ((opt = getopt(argc, argv, "+46acdf:h:mnNp:v")) != -1) {
|
while ((opt = getopt(argc, argv, "+46acdef:h:mnNp:v")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case '4':
|
case '4':
|
||||||
case '6':
|
case '6':
|
||||||
|
@ -3441,6 +3448,9 @@ main(int argc, char **argv)
|
||||||
log_min_severity = LOGS_DEBUG;
|
log_min_severity = LOGS_DEBUG;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
case 'e':
|
||||||
|
end_dot = 1;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
hostnames = optarg;
|
hostnames = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -89,6 +89,10 @@ format. Reverse DNS lookups will be disabled, time will be printed as number of
|
||||||
seconds since the epoch, and values in seconds will not be converted to other
|
seconds since the epoch, and values in seconds will not be converted to other
|
||||||
units.
|
units.
|
||||||
|
|
||||||
|
*-e*::
|
||||||
|
With this option each *chronyc* response will end with a line containing a
|
||||||
|
single dot.
|
||||||
|
|
||||||
*-d*::
|
*-d*::
|
||||||
This option enables printing of debugging messages if *chronyc* was compiled
|
This option enables printing of debugging messages if *chronyc* was compiled
|
||||||
with debugging support.
|
with debugging support.
|
||||||
|
|
|
@ -91,6 +91,18 @@ check_chronyd_exit || test_fail
|
||||||
check_chronyc_output "^C0A87B01,192\.168\.123\.1,2,12623049..\..........,-?0\.0000.....,-?0\.000......,0\.000......,(99|100)\....,-?[0-9]\....,[0-9]\....,0\.000......,0\.000......,[0-9]+\..,Normal$" \
|
check_chronyc_output "^C0A87B01,192\.168\.123\.1,2,12623049..\..........,-?0\.0000.....,-?0\.000......,0\.000......,(99|100)\....,-?[0-9]\....,[0-9]\....,0\.000......,0\.000......,[0-9]+\..,Normal$" \
|
||||||
|| test_fail
|
|| test_fail
|
||||||
|
|
||||||
|
chronyc_options="-c -e"
|
||||||
|
chronyc_conf="sources"
|
||||||
|
|
||||||
|
run_test || test_fail
|
||||||
|
check_chronyd_exit || test_fail
|
||||||
|
|
||||||
|
check_chronyc_output "^#,.,SHM0.*
|
||||||
|
\^,.,192\.168\.123\.1.*
|
||||||
|
\^,.,192\.168\.123\.2.*
|
||||||
|
\.$" \
|
||||||
|
|| test_fail
|
||||||
|
|
||||||
chronyc_options=""
|
chronyc_options=""
|
||||||
server_strata=0
|
server_strata=0
|
||||||
chronyc_start=0.5
|
chronyc_start=0.5
|
||||||
|
|
Loading…
Reference in a new issue