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

@@ -138,6 +138,7 @@ static const char permissions[] = {
PERMIT_AUTH, /* ADD_PEER2 */
PERMIT_AUTH, /* ADD_SERVER3 */
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));
}
/* ================================================== */
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 */
@@ -1630,6 +1640,10 @@ read_from_cmd_socket(int sock_fd, int event, void *anything)
handle_ntp_data(&rx_message, &tx_message);
break;
case REQ_SHUTDOWN:
handle_shutdown(&rx_message, &tx_message);
break;
default:
DEBUG_LOG("Unhandled command %d", rx_command);
tx_message.status = htons(STT_FAILED);