You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
3.0 KiB

  1. commit 1bd140ea3fab97ccd37adf9d0c106d52af9e53fa
  2. Author: William Lallemand <wlallemand@haproxy.com>
  3. Date: Mon Jul 1 10:56:15 2019 +0200
  4. BUG/MINOR: mworker/cli: don't output a \n before the response
  5. When using a level lower than admin on the master CLI, a \n is output
  6. before the response, this is caused by the response of the "operator" or
  7. "user" that are sent before the actual command.
  8. To fix this problem we introduce the flag APPCTX_CLI_ST1_NOLF which ask
  9. a command response to not be followed by the final \n.
  10. This patch made a special case with the command operator and user
  11. followed by a - so they are not followed by \n.
  12. This patch must be backported to 2.0 and 1.9.
  13. (cherry picked from commit ad03288e6b28d816abb443cf8c6d984a72bb91a6)
  14. Signed-off-by: William Lallemand <wlallemand@haproxy.org>
  15. diff --git a/include/types/applet.h b/include/types/applet.h
  16. index c9e02d17..1f3a4983 100644
  17. --- a/include/types/applet.h
  18. +++ b/include/types/applet.h
  19. @@ -50,6 +50,7 @@ struct applet {
  20. #define APPCTX_CLI_ST1_PROMPT (1 << 0)
  21. #define APPCTX_CLI_ST1_PAYLOAD (1 << 1)
  22. +#define APPCTX_CLI_ST1_NOLF (1 << 2)
  23. /* Context of a running applet. */
  24. struct appctx {
  25. diff --git a/src/cli.c b/src/cli.c
  26. index 44ddc7bf..9a9f80f9 100644
  27. --- a/src/cli.c
  28. +++ b/src/cli.c
  29. @@ -821,7 +821,7 @@ static void cli_io_handler(struct appctx *appctx)
  30. prompt = "\n> ";
  31. }
  32. else {
  33. - if (!(appctx->st1 & APPCTX_CLI_ST1_PAYLOAD))
  34. + if (!(appctx->st1 & (APPCTX_CLI_ST1_PAYLOAD|APPCTX_CLI_ST1_NOLF)))
  35. prompt = "\n";
  36. }
  37. @@ -848,6 +848,8 @@ static void cli_io_handler(struct appctx *appctx)
  38. /* switch state back to GETREQ to read next requests */
  39. appctx->st0 = CLI_ST_GETREQ;
  40. + /* reactivate the \n at the end of the response for the next command */
  41. + appctx->st1 &= ~APPCTX_CLI_ST1_NOLF;
  42. }
  43. }
  44. @@ -1442,6 +1444,10 @@ static int cli_parse_show_lvl(char **args, char *payload, struct appctx *appctx,
  45. /* parse and set the CLI level dynamically */
  46. static int cli_parse_set_lvl(char **args, char *payload, struct appctx *appctx, void *private)
  47. {
  48. + /* this will ask the applet to not output a \n after the command */
  49. + if (!strcmp(args[1], "-"))
  50. + appctx->st1 |= APPCTX_CLI_ST1_NOLF;
  51. +
  52. if (!strcmp(args[0], "operator")) {
  53. if (!cli_has_level(appctx, ACCESS_LVL_OPER)) {
  54. return 1;
  55. @@ -2097,11 +2103,11 @@ int pcli_parse_request(struct stream *s, struct channel *req, char **errmsg, int
  56. if (pcli_has_level(s, ACCESS_LVL_ADMIN)) {
  57. goto end;
  58. } else if (pcli_has_level(s, ACCESS_LVL_OPER)) {
  59. - ci_insert_line2(req, 0, "operator", strlen("operator"));
  60. - ret += strlen("operator") + 2;
  61. + ci_insert_line2(req, 0, "operator -", strlen("operator -"));
  62. + ret += strlen("operator -") + 2;
  63. } else if (pcli_has_level(s, ACCESS_LVL_USER)) {
  64. - ci_insert_line2(req, 0, "user", strlen("user"));
  65. - ret += strlen("user") + 2;
  66. + ci_insert_line2(req, 0, "user -", strlen("user -"));
  67. + ret += strlen("user -") + 2;
  68. }
  69. }
  70. end: