]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: add CLI command "debug dev write" to write an arbitrary size
authorWilly Tarreau <w@1wt.eu>
Thu, 5 Mar 2020 16:16:24 +0000 (17:16 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 5 Mar 2020 16:20:15 +0000 (17:20 +0100)
This command is used to produce an arbitrary amount of data on the
output. It can be used to test the CLI's state machine as well as
the internal parts related to applets an I/O. A typical test consists
in asking for all sizes from 0 to 16384:

  $ (echo "prompt;expert-mode on";for i in {0..16384}; do
     echo "debug dev write $i"; done) | socat - /tmp/sock1 | wc -c
  134258738

A better test would consist in first waiting for the response before
sending a new request.

This command is not restricted to the admin since it's harmless.

src/debug.c

index c01f7949485eedc7d88d1e11776c91374721dc0b..a3b208a33412f25ae6a23e671534f511bd63ce9d 100644 (file)
@@ -497,6 +497,29 @@ static int debug_parse_cli_tkill(char **args, char *payload, struct appctx *appc
        return 1;
 }
 
+/* parse a "debug dev write" command. It always returns 1. */
+static int debug_parse_cli_write(char **args, char *payload, struct appctx *appctx, void *private)
+{
+       unsigned long len;
+
+       if (!*args[3])
+               return cli_err(appctx, "Missing output size.\n");
+
+       len = strtoul(args[3], NULL, 0);
+       if (len >= trash.size)
+               return cli_err(appctx, "Output too large, must be <tune.bufsize.\n");
+
+       _HA_ATOMIC_ADD(&debug_commands_issued, 1);
+
+       chunk_reset(&trash);
+       trash.data = len;
+       memset(trash.area, '.', trash.data);
+       trash.area[trash.data] = 0;
+       for (len = 64; len < trash.data; len += 64)
+               trash.area[len] = '\n';
+       return cli_msg(appctx, LOG_INFO, trash.area);
+}
+
 /* parse a "debug dev stream" command */
 /*
  *  debug dev stream [strm=<ptr>] [strm.f[{+-=}<flags>]] [txn.f[{+-=}<flags>]] \
@@ -795,6 +818,7 @@ static struct cli_kw_list cli_kws = {{ },{
        {{ "debug", "dev", "panic", NULL }, "debug dev panic             : immediately trigger a panic",     debug_parse_cli_panic, NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "debug", "dev", "stream",NULL }, "debug dev stream ...        : show/manipulate stream flags",    debug_parse_cli_stream,NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "debug", "dev", "tkill", NULL }, "debug dev tkill [thr] [sig] : send signal to thread",           debug_parse_cli_tkill, NULL, NULL, NULL, ACCESS_EXPERT },
+       {{ "debug", "dev", "write", NULL }, "debug dev write [size]      : write that many bytes",           debug_parse_cli_write, NULL, NULL, NULL, ACCESS_EXPERT },
        {{ "show", "threads", NULL, NULL }, "show threads   : show some threads debugging information",  NULL, cli_io_handler_show_threads, NULL },
        {{},}
 }};