summaryrefslogtreecommitdiff
path: root/proto_text.c
diff options
context:
space:
mode:
authorKevin Lin <developer@kevinlin.info>2020-11-16 15:26:49 -0800
committerdormando <dormando@rydia.net>2020-11-20 12:30:33 -0800
commit1332f52df4dc9084325d348ac12a8fdc44811d17 (patch)
tree70ee6328088a4a42fdf3df736d000d1ff867854a /proto_text.c
parent2d118d43d4607d86f2312f0dd44815833da39a59 (diff)
downloadmemcached-1332f52df4dc9084325d348ac12a8fdc44811d17.tar.gz
'shutdown graceful' command for raising SIGUSR1
Diffstat (limited to 'proto_text.c')
-rw-r--r--proto_text.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/proto_text.c b/proto_text.c
index 1101c4e..ecc6f92 100644
--- a/proto_text.c
+++ b/proto_text.c
@@ -2348,12 +2348,20 @@ static void process_quit_command(conn *c) {
c->close_after_write = true;
}
-static void process_shutdown_command(conn *c) {
- if (settings.shutdown_command) {
+static void process_shutdown_command(conn *c, token_t *tokens, const size_t ntokens) {
+ if (!settings.shutdown_command) {
+ out_string(c, "ERROR: shutdown not enabled");
+ return;
+ }
+
+ if (ntokens == 2) {
conn_set_state(c, conn_closing);
raise(SIGINT);
+ } else if (ntokens == 3 && strcmp(tokens[SUBCOMMAND_TOKEN].value, "graceful") == 0) {
+ conn_set_state(c, conn_closing);
+ raise(SIGUSR1);
} else {
- out_string(c, "ERROR: shutdown not enabled");
+ out_string(c, "CLIENT_ERROR invalid shutdown mode");
}
}
@@ -2620,7 +2628,7 @@ static void process_command(conn *c, char *command) {
process_stat(c, tokens, ntokens);
} else if (strcmp(tokens[COMMAND_TOKEN].value, "shutdown") == 0) {
- process_shutdown_command(c);
+ process_shutdown_command(c, tokens, ntokens);
} else if (strcmp(tokens[COMMAND_TOKEN].value, "slabs") == 0) {
process_slabs_command(c, tokens, ntokens);