]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: cli: move "shutdown sessions server" to stream.c
authorWilly Tarreau <w@1wt.eu>
Wed, 23 Nov 2016 15:50:48 +0000 (16:50 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 15:59:28 +0000 (16:59 +0100)
It could be argued that it's between server, stream and session but
at least due to the fact that it operates on streams, its best place
is in stream.c.

src/cli.c
src/stream.c

index 3e560c3e3fe57bf631d282251394066d334d8cae..8a5bf7fca4d14429e09babf7bbeb4d7b3945f4be 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -881,28 +881,6 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                        stream_shutdown(sess, SF_ERR_KILLED);
                        return 1;
                }
-               else if (strcmp(args[1], "sessions") == 0) {
-                       if (strcmp(args[2], "server") == 0) {
-                               struct server *sv;
-                               struct stream *sess, *sess_bck;
-
-                               sv = expect_server_admin(s, si, args[3]);
-                               if (!sv)
-                                       return 1;
-
-                               /* kill all the stream that are on this server */
-                               list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
-                                       if (sess->srv_conn == sv)
-                                               stream_shutdown(sess, SF_ERR_KILLED);
-
-                               return 1;
-                       }
-                       else {
-                               appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n";
-                               appctx->st0 = STAT_CLI_PRINT;
-                               return 1;
-                       }
-               }
                else { /* unknown "disable" parameter */
                        appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n";
                        appctx->st0 = STAT_CLI_PRINT;
index 0d987452b4f9d1b2f44982b312923fa9b111a90f..721736cec2b24c3c13c774f5e0bfeee404f7aa30 100644 (file)
@@ -3914,9 +3914,30 @@ static void cli_release_show_sess(struct appctx *appctx)
        }
 }
 
+/* Parses the "shutdown session server" directive, it always returns 1 */
+static int cli_parse_shutdown_sessions_server(char **args, struct appctx *appctx, void *private)
+{
+       struct server *sv;
+       struct stream *strm, *strm_bck;
+
+       if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
+               return 1;
+
+       sv = cli_find_server(appctx, args[3]);
+       if (!sv)
+               return 1;
+
+       /* kill all the stream that are on this server */
+       list_for_each_entry_safe(strm, strm_bck, &sv->actconns, by_srv)
+               if (strm->srv_conn == sv)
+                       stream_shutdown(strm, SF_ERR_KILLED);
+       return 1;
+}
+
 /* 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", "sessions",  "server" }, "shutdown sessions server : kill sessions on a server", cli_parse_shutdown_sessions_server, NULL, NULL },
        {{},}
 }};