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

@@ -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;