From e32d1867f6c4b1452c71e2920c816997d5d6f77d Mon Sep 17 00:00:00 2001 From: Andrew Hayworth Date: Fri, 2 Oct 2015 15:08:10 +0000 Subject: [PATCH] BUG/MINOR: Handle interactive mode in cli handler A previous commit broke the interactive stats cli prompt. Specifically, it was not clear that we could be in STAT_CLI_PROMPT when we get to the output functions for the cli handler, and the switch statement did not handle this case. We would then fall through to the default statement, which was recently changed to set error flags on the socket. This in turn causes the socket to be closed, which is not what we wanted in this specific case. To fix, we add a case for STAT_CLI_PROMPT, and simply break out of the switch statement. Testing: - Connected to unix stats socket, issued 'prompt', observed that I could issue multiple consecutive commands. - Connected to unix stats socket, issued 'prompt', observed that socket timed out after inactivity expired. - Connected to unix stats socket, issued 'prompt' then 'set timeout cli 5', observed that socket timed out after 5 seconds expired. - Connected to unix stats socket, issued invalid commands, received usage output. - Connected to unix stats socket, issued 'show info', received info output and socket disconnected. - Connected to unix stats socket, issued 'show stat', received stats output and socket disconnected. - Repeated above tests with TCP stats socket. [wt: no backport needed, this was introduced during the applet rework in 1.6] --- src/dumpstats.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dumpstats.c b/src/dumpstats.c index fd1d1232f..169b9acf2 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -2480,6 +2480,8 @@ static void cli_io_handler(struct appctx *appctx) } else { /* output functions */ switch (appctx->st0) { + case STAT_CLI_PROMPT: + break; case STAT_CLI_PRINT: if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) appctx->st0 = STAT_CLI_PROMPT;