Commit 635910e7 authored by Maria Matejka's avatar Maria Matejka
Browse files

Fixed CLI optimization when socket closes before command is done

parent ec2f1751
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ cleanup:
  return ret;
}

int
void
cli_parse(struct conf_order *order)
{
  DBG("Parsing command line\n");
@@ -161,20 +161,13 @@ cli_parse(struct conf_order *order)

  struct cf_context *ctx = cf_new_context(order);

  int ok = 0;
  if (setjmp(ctx->jmpbuf))
    goto done;

  cfx_parse(ctx, ctx->yyscanner);
  ok = 1;

done:
  cf_free_context(ctx);
  config_free(&cc);
  config_del_obstacle(config);
  order->new_config = NULL;
  order->ctx = NULL;
  return ok;
}

/**
+1 −5
Original line number Diff line number Diff line
@@ -104,13 +104,9 @@ int config_parse(struct conf_order *order);
 * Arguments:
 * @order provides callbacks to read command line
 *
 * Return value:
 * 1 on success
 * 0 on fail
 *
 * Parsed config is never kept, order->new_config should be zero after return.
 **/
int cli_parse(struct conf_order *order);
void cli_parse(struct conf_order *order);

/** Callback for returning error from parser hooks */
#define cf_error(...) cf_error_(ctx, __VA_ARGS__)
+4 −1
Original line number Diff line number Diff line
@@ -95,6 +95,9 @@ cli_vprintf(cli *c, int code, const char *msg, va_list args)
  int errcode;
  int size, cnt;

  if (c->tx_closed)
    return;

  if (cd < 0)
    {
      cd = -cd;
@@ -126,7 +129,7 @@ cli_vprintf(cli *c, int code, const char *msg, va_list args)
  size += cnt;
  buf[size++] = '\n';
  if (sk_send(c->sock, buf, size) < 0)
    longjmp(c->errbuf, 1);
    c->tx_closed = 1;
}

#if CLI_LOG_HOOKS
+1 −4
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ typedef struct cli {
  int restricted;			/* CLI is restricted to read-only commands */
  struct linpool *parser_pool;		/* Pool used during parsing */
  struct linpool *show_pool;		/* Pool used during route show */
  jmp_buf errbuf;			/* Longjmp buffer for CLI write errors */
  _Bool tx_closed;			/* Do not send any more messages */
#if 0
  byte *ring_buf;			/* Ring buffer for asynchronous messages */
  byte *ring_end, *ring_read, *ring_write;	/* Pointers to the ring buffer */
@@ -40,9 +40,6 @@ typedef struct cli {
#endif
} cli;

#define CLI_TRY(c) if (!setjmp((c)->errbuf)) {
#define CLI_EXCEPT(c) memset(&(c)->errbuf, 0, sizeof(jmp_buf)); } else

extern pool *cli_pool;
extern _Thread_local struct cli *this_cli;		/* Used during parsing */

+3 −7
Original line number Diff line number Diff line
@@ -439,11 +439,7 @@ rt_show(struct rt_show_data *d)

  while (loop)
/*    THE_BIRD_LOCKED(( rt_show_cleanup(d), loop = 0 )) */
    {
      CLI_TRY(this_cli) {
	loop = rt_show_cont(d);
      } CLI_EXCEPT(this_cli) {
    loop = rt_show_cont(d) && !this_cli->tx_closed;

  rt_show_cleanup(d);
}
    }
}
Loading