cmdmon: add shutdown command

The command is functionally equivalent to sending the process the
SIGTERM signal.
This commit is contained in:
Miroslav Lichvar 2018-03-02 12:51:52 +01:00
parent 8b1f68b1b4
commit 499f513d40
5 changed files with 35 additions and 4 deletions

View file

@ -99,7 +99,8 @@
#define REQ_ADD_PEER2 59 #define REQ_ADD_PEER2 59
#define REQ_ADD_SERVER3 60 #define REQ_ADD_SERVER3 60
#define REQ_ADD_PEER3 61 #define REQ_ADD_PEER3 61
#define N_REQUEST_TYPES 62 #define REQ_SHUTDOWN 62
#define N_REQUEST_TYPES 63
/* Structure used to exchange timespecs independent of time_t size */ /* Structure used to exchange timespecs independent of time_t size */
typedef struct { typedef struct {

View file

@ -1246,6 +1246,7 @@ give_help(void)
"cyclelogs\0Close and re-open log files\0" "cyclelogs\0Close and re-open log files\0"
"dump\0Dump all measurements to save files\0" "dump\0Dump all measurements to save files\0"
"rekey\0Re-read keys from key file\0" "rekey\0Re-read keys from key file\0"
"shutdown\0Stop daemon\0"
"\0\0" "\0\0"
"Client commands:\0\0" "Client commands:\0\0"
"dns -n|+n\0Disable/enable resolving IP addresses to hostnames\0" "dns -n|+n\0Disable/enable resolving IP addresses to hostnames\0"
@ -1280,9 +1281,9 @@ command_name_generator(const char *text, int state)
"maxdelay", "maxdelaydevratio", "maxdelayratio", "maxpoll", "maxdelay", "maxdelaydevratio", "maxdelayratio", "maxpoll",
"maxupdateskew", "minpoll", "minstratum", "ntpdata", "offline", "online", "maxupdateskew", "minpoll", "minstratum", "ntpdata", "offline", "online",
"polltarget", "quit", "refresh", "rekey", "reselect", "reselectdist", "polltarget", "quit", "refresh", "rekey", "reselect", "reselectdist",
"retries", "rtcdata", "serverstats", "settime", "smoothing", "smoothtime", "retries", "rtcdata", "serverstats", "settime", "shutdown", "smoothing",
"sources", "sources -v", "sourcestats", "sourcestats -v", "timeout", "smoothtime", "sources", "sources -v", "sourcestats", "sourcestats -v",
"tracking", "trimrtc", "waitsync", "writertc", "timeout", "tracking", "trimrtc", "waitsync", "writertc",
NULL NULL
}; };
static int list_index, len; static int list_index, len;
@ -2707,6 +2708,14 @@ process_cmd_refresh(CMD_Request *msg, char *line)
/* ================================================== */ /* ================================================== */
static void
process_cmd_shutdown(CMD_Request *msg, char *line)
{
msg->command = htons(REQ_SHUTDOWN);
}
/* ================================================== */
static int static int
process_cmd_waitsync(char *line) process_cmd_waitsync(char *line)
{ {
@ -3002,6 +3011,8 @@ process_line(char *line)
} else if (!strcmp(command, "settime")) { } else if (!strcmp(command, "settime")) {
do_normal_submit = 0; do_normal_submit = 0;
ret = process_cmd_settime(line); ret = process_cmd_settime(line);
} else if (!strcmp(command, "shutdown")) {
process_cmd_shutdown(&tx_message, line);
} else if (!strcmp(command, "smoothing")) { } else if (!strcmp(command, "smoothing")) {
do_normal_submit = 0; do_normal_submit = 0;
ret = process_cmd_smoothing(line); ret = process_cmd_smoothing(line);

View file

@ -138,6 +138,7 @@ static const char permissions[] = {
PERMIT_AUTH, /* ADD_PEER2 */ PERMIT_AUTH, /* ADD_PEER2 */
PERMIT_AUTH, /* ADD_SERVER3 */ PERMIT_AUTH, /* ADD_SERVER3 */
PERMIT_AUTH, /* ADD_PEER3 */ PERMIT_AUTH, /* ADD_PEER3 */
PERMIT_AUTH, /* SHUTDOWN */
}; };
/* ================================================== */ /* ================================================== */
@ -1239,6 +1240,15 @@ handle_ntp_data(CMD_Request *rx_message, CMD_Reply *tx_message)
memset(tx_message->data.ntp_data.reserved, 0xff, sizeof (tx_message->data.ntp_data.reserved)); memset(tx_message->data.ntp_data.reserved, 0xff, sizeof (tx_message->data.ntp_data.reserved));
} }
/* ================================================== */
static void
handle_shutdown(CMD_Request *rx_message, CMD_Reply *tx_message)
{
LOG(LOGS_INFO, "Received shutdown command");
SCH_QuitProgram();
}
/* ================================================== */ /* ================================================== */
/* Read a packet and process it */ /* Read a packet and process it */
@ -1630,6 +1640,10 @@ read_from_cmd_socket(int sock_fd, int event, void *anything)
handle_ntp_data(&rx_message, &tx_message); handle_ntp_data(&rx_message, &tx_message);
break; break;
case REQ_SHUTDOWN:
handle_shutdown(&rx_message, &tx_message);
break;
default: default:
DEBUG_LOG("Unhandled command %d", rx_command); DEBUG_LOG("Unhandled command %d", rx_command);
tx_message.status = htons(STT_FAILED); tx_message.status = htons(STT_FAILED);

View file

@ -1128,6 +1128,10 @@ running.
The *rekey* command causes *chronyd* to re-read the key file specified in the The *rekey* command causes *chronyd* to re-read the key file specified in the
configuration file by the <<chrony.conf.adoc#keyfile,*keyfile*>> directive. configuration file by the <<chrony.conf.adoc#keyfile,*keyfile*>> directive.
[[rekey]]*shutdown*::
The *shutdown* command causes *chronyd* to exit. This is equivalent to sending
the process the SIGTERM signal.
=== Client commands === Client commands
[[dns]]*dns* _option_:: [[dns]]*dns* _option_::

View file

@ -118,6 +118,7 @@ static const struct request_length request_lengths[] = {
{ 0, 0 }, /* ADD_PEER2 */ { 0, 0 }, /* ADD_PEER2 */
REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_SERVER3 */ REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_SERVER3 */
REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_PEER3 */ REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_PEER3 */
REQ_LENGTH_ENTRY(null, null), /* SHUTDOWN */
}; };
static const uint16_t reply_lengths[] = { static const uint16_t reply_lengths[] = {