From 61b6521cbfecad4204c1748f058f0260adde1911 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 24 Nov 2016 11:09:25 +0100 Subject: [PATCH] REORG: cli: move "shutdown session" to stream.c It really kills streams in fact, but we can't change the name now. --- src/cli.c | 33 --------------------------------- src/stream.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/cli.c b/src/cli.c index 8a5bf7fca..ea9765c89 100644 --- a/src/cli.c +++ b/src/cli.c @@ -848,39 +848,6 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line) stop_proxy(px); return 1; } - else if (strcmp(args[1], "session") == 0) { - struct stream *sess, *ptr; - - if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { - appctx->ctx.cli.msg = stats_permission_denied_msg; - appctx->st0 = STAT_CLI_PRINT; - return 1; - } - - if (!*args[2]) { - appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; - appctx->st0 = STAT_CLI_PRINT; - return 1; - } - - ptr = (void *)strtoul(args[2], NULL, 0); - - /* first, look for the requested stream in the stream table */ - list_for_each_entry(sess, &streams, list) { - if (sess == ptr) - break; - } - - /* do we have the stream ? */ - if (sess != ptr) { - appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; - appctx->st0 = STAT_CLI_PRINT; - return 1; - } - - stream_shutdown(sess, SF_ERR_KILLED); - return 1; - } else { /* unknown "disable" parameter */ appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; appctx->st0 = STAT_CLI_PRINT; diff --git a/src/stream.c b/src/stream.c index 721736cec..0c0a34f84 100644 --- a/src/stream.c +++ b/src/stream.c @@ -3914,6 +3914,39 @@ static void cli_release_show_sess(struct appctx *appctx) } } +/* Parses the "shutdown session" directive, it always returns 1 */ +static int cli_parse_shutdown_session(char **args, struct appctx *appctx, void *private) +{ + struct stream *strm, *ptr; + + if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) + return 1; + + if (!*args[2]) { + appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; + appctx->st0 = STAT_CLI_PRINT; + return 1; + } + + ptr = (void *)strtoul(args[2], NULL, 0); + + /* first, look for the requested stream in the stream table */ + list_for_each_entry(strm, &streams, list) { + if (strm == ptr) + break; + } + + /* do we have the stream ? */ + if (strm != ptr) { + appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; + appctx->st0 = STAT_CLI_PRINT; + return 1; + } + + stream_shutdown(strm, SF_ERR_KILLED); + return 1; +} + /* Parses the "shutdown session server" directive, it always returns 1 */ static int cli_parse_shutdown_sessions_server(char **args, struct appctx *appctx, void *private) { @@ -3937,6 +3970,7 @@ static int cli_parse_shutdown_sessions_server(char **args, struct appctx *appctx /* register cli keywords */ static struct cli_kw_list cli_kws = {{ },{ { { "show", "sess", NULL }, "show sess [id] : report the list of current sessions or dump this session", cli_parse_show_sess, cli_io_handler_dump_sess, cli_release_show_sess }, + { { "shutdown", "session", NULL }, "shutdown session : kill a specific session", cli_parse_shutdown_session, NULL, NULL }, { { "shutdown", "sessions", "server" }, "shutdown sessions server : kill sessions on a server", cli_parse_shutdown_sessions_server, NULL, NULL }, {{},} }};