cmdmon: rename reset command to reset sources

Add a sources option for the reset command in case there are other
components that would need to be reset.
This commit is contained in:
Miroslav Lichvar 2020-05-12 10:52:46 +02:00
parent 195ff5c51b
commit 43dc0b3295
6 changed files with 29 additions and 17 deletions

View file

@ -103,7 +103,7 @@
#define REQ_ONOFFLINE 63
#define REQ_ADD_SOURCE 64
#define REQ_NTP_SOURCE_NAME 65
#define REQ_RESET 66
#define REQ_RESET_SOURCES 66
#define N_REQUEST_TYPES 67
/* Structure used to exchange timespecs independent of time_t size */

View file

@ -1269,7 +1269,7 @@ give_help(void)
"cyclelogs\0Close and re-open log files\0"
"dump\0Dump measurements and NTS keys/cookies\0"
"rekey\0Re-read keys\0"
"reset\0Drop all measurements\0"
"reset sources\0Drop all measurements\0"
"shutdown\0Stop daemon\0"
"\0\0"
"Client commands:\0\0"
@ -1299,6 +1299,7 @@ enum {
TAB_COMPLETE_BASE_CMDS,
TAB_COMPLETE_ADD_OPTS,
TAB_COMPLETE_MANUAL_OPTS,
TAB_COMPLETE_RESET_OPTS,
TAB_COMPLETE_SOURCES_OPTS,
TAB_COMPLETE_SOURCESTATS_OPTS,
TAB_COMPLETE_MAX_INDEX
@ -1324,6 +1325,7 @@ command_name_generator(const char *text, int state)
};
const char *add_options[] = { "peer", "pool", "server", NULL };
const char *manual_options[] = { "on", "off", "delete", "list", "reset", NULL };
const char *reset_options[] = { "sources", NULL };
const char *sources_options[] = { "-a", "-v", NULL };
const char *sourcestats_options[] = { "-a", "-v", NULL };
static int list_index, len;
@ -1331,6 +1333,7 @@ command_name_generator(const char *text, int state)
names[TAB_COMPLETE_BASE_CMDS] = base_commands;
names[TAB_COMPLETE_ADD_OPTS] = add_options;
names[TAB_COMPLETE_MANUAL_OPTS] = manual_options;
names[TAB_COMPLETE_RESET_OPTS] = reset_options;
names[TAB_COMPLETE_SOURCES_OPTS] = sources_options;
names[TAB_COMPLETE_SOURCESTATS_OPTS] = sourcestats_options;
@ -1362,6 +1365,8 @@ command_name_completion(const char *text, int start, int end)
tab_complete_index = TAB_COMPLETE_ADD_OPTS;
} else if (!strcmp(first, "manual ")) {
tab_complete_index = TAB_COMPLETE_MANUAL_OPTS;
} else if (!strcmp(first, "reset ")) {
tab_complete_index = TAB_COMPLETE_RESET_OPTS;
} else if (!strcmp(first, "sources ")) {
tab_complete_index = TAB_COMPLETE_SOURCES_OPTS;
} else if (!strcmp(first, "sourcestats ")) {
@ -2836,10 +2841,17 @@ process_cmd_shutdown(CMD_Request *msg, char *line)
/* ================================================== */
static void
static int
process_cmd_reset(CMD_Request *msg, char *line)
{
msg->command = htons(REQ_RESET);
if (!strcmp(line, "sources")) {
msg->command = htons(REQ_RESET_SOURCES);
} else {
LOG(LOGS_ERR, "Invalid syntax for reset command");
return 0;
}
return 1;
}
/* ================================================== */
@ -3139,7 +3151,7 @@ process_line(char *line)
} else if (!strcmp(command, "reselectdist")) {
do_normal_submit = process_cmd_reselectdist(&tx_message, line);
} else if (!strcmp(command, "reset")) {
process_cmd_reset(&tx_message, line);
do_normal_submit = process_cmd_reset(&tx_message, line);
} else if (!strcmp(command, "retries")) {
ret = process_cmd_retries(line);
do_normal_submit = 0;

View file

@ -135,7 +135,7 @@ static const char permissions[] = {
PERMIT_AUTH, /* ONOFFLINE */
PERMIT_AUTH, /* ADD_SOURCE */
PERMIT_OPEN, /* NTP_SOURCE_NAME */
PERMIT_AUTH, /* RESET */
PERMIT_AUTH, /* RESET_SOURCES */
};
/* ================================================== */
@ -1226,7 +1226,7 @@ handle_ntp_source_name(CMD_Request *rx_message, CMD_Reply *tx_message)
/* ================================================== */
static void
handle_reset(CMD_Request *rx_message, CMD_Reply *tx_message)
handle_reset_sources(CMD_Request *rx_message, CMD_Reply *tx_message)
{
struct timespec cooked_now, now;
@ -1613,8 +1613,8 @@ read_from_cmd_socket(int sock_fd, int event, void *anything)
handle_ntp_source_name(&rx_message, &tx_message);
break;
case REQ_RESET:
handle_reset(&rx_message, &tx_message);
case REQ_RESET_SOURCES:
handle_reset_sources(&rx_message, &tx_message);
break;
default:

View file

@ -1177,12 +1177,12 @@ also re-reads the server NTS keys if
<<chrony.conf.adoc#ntsrotate,automatic rotation>> is disabled in the
configuration file.
[[reset]]*reset*::
The *reset* command causes *chronyd* to drop all measurements and switch to the
unsynchronised state. This command can help *chronyd* with recovery when the
measurements are known to be no longer valid or accurate, e.g. due to moving
the computer to a different network, or resuming the computer from a low-power
state (which resets the system clock).
[[reset]]*reset* *sources*::
The *reset sources* command causes *chronyd* to drop all measurements and
switch to the unsynchronised state. This command can help *chronyd* with
recovery when the measurements are known to be no longer valid or accurate,
e.g. due to moving the computer to a different network, or resuming the
computer from a low-power state (which resets the system clock).
[[shutdown]]*shutdown*::
The *shutdown* command causes *chronyd* to exit. This is equivalent to sending

View file

@ -123,7 +123,7 @@ static const struct request_length request_lengths[] = {
REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_SOURCE */
REQ_LENGTH_ENTRY(ntp_source_name,
ntp_source_name), /* NTP_SOURCE_NAME */
REQ_LENGTH_ENTRY(null, null), /* RESET */
REQ_LENGTH_ENTRY(null, null), /* RESET_SOURCES */
};
static const uint16_t reply_lengths[] = {

View file

@ -138,7 +138,7 @@ for chronyc_conf in \
"rekey" \
"reselect" \
"reselectdist 1e-3" \
"reset" \
"reset sources" \
"settime 16:30" \
"settime 16:30:05" \
"settime Nov 21, 2015 16:30:05" \