mirror of
https://gitlab.labs.nic.cz/labs/bird.git
synced 2024-05-11 16:54:54 +00:00
CLI: Dropping the mechanism of echoing log messages
This is better done by running tail -f on a logfile.
This commit is contained in:
109
nest/cli.c
109
nest/cli.c
@@ -160,43 +160,6 @@ cli_printf(cli *c, int code, char *msg, ...)
|
||||
memcpy(cli_alloc_out(c, size), buf, size);
|
||||
}
|
||||
|
||||
static void
|
||||
cli_copy_message(cli *c)
|
||||
{
|
||||
byte *p, *q;
|
||||
uint cnt = 2;
|
||||
|
||||
if (c->ring_overflow)
|
||||
{
|
||||
byte buf[64];
|
||||
int n = bsprintf(buf, "<%d messages lost>\n", c->ring_overflow);
|
||||
c->ring_overflow = 0;
|
||||
memcpy(cli_alloc_out(c, n), buf, n);
|
||||
}
|
||||
p = c->ring_read;
|
||||
while (*p)
|
||||
{
|
||||
cnt++;
|
||||
p++;
|
||||
if (p == c->ring_end)
|
||||
p = c->ring_buf;
|
||||
ASSERT(p != c->ring_write);
|
||||
}
|
||||
c->async_msg_size += cnt;
|
||||
q = cli_alloc_out(c, cnt);
|
||||
*q++ = '+';
|
||||
p = c->ring_read;
|
||||
do
|
||||
{
|
||||
*q = *p++;
|
||||
if (p == c->ring_end)
|
||||
p = c->ring_buf;
|
||||
}
|
||||
while (*q++);
|
||||
c->ring_read = p;
|
||||
q[-1] = '\n';
|
||||
}
|
||||
|
||||
static void
|
||||
cli_hello(cli *c)
|
||||
{
|
||||
@@ -283,10 +246,6 @@ cli_event(void *data)
|
||||
cli *c = data;
|
||||
int err;
|
||||
|
||||
while (c->ring_read != c->ring_write &&
|
||||
c->async_msg_size < CLI_MAX_ASYNC_QUEUE)
|
||||
cli_copy_message(c);
|
||||
|
||||
if (c->tx_pos)
|
||||
;
|
||||
else if (c->cont)
|
||||
@@ -335,80 +294,12 @@ cli_kick(cli *c)
|
||||
static list cli_log_hooks;
|
||||
static int cli_log_inited;
|
||||
|
||||
void
|
||||
cli_set_log_echo(cli *c, uint mask, uint size)
|
||||
{
|
||||
if (c->ring_buf)
|
||||
{
|
||||
mb_free(c->ring_buf);
|
||||
c->ring_buf = c->ring_end = c->ring_read = c->ring_write = NULL;
|
||||
rem_node(&c->n);
|
||||
}
|
||||
c->log_mask = mask;
|
||||
if (mask && size)
|
||||
{
|
||||
c->ring_buf = mb_alloc(c->pool, size);
|
||||
c->ring_end = c->ring_buf + size;
|
||||
c->ring_read = c->ring_write = c->ring_buf;
|
||||
add_tail(&cli_log_hooks, &c->n);
|
||||
c->log_threshold = size / 8;
|
||||
}
|
||||
c->ring_overflow = 0;
|
||||
}
|
||||
|
||||
void
|
||||
cli_echo(uint class, byte *msg)
|
||||
{
|
||||
unsigned len, free, i, l;
|
||||
cli *c;
|
||||
byte *m;
|
||||
|
||||
if (!cli_log_inited || EMPTY_LIST(cli_log_hooks))
|
||||
return;
|
||||
len = strlen(msg) + 1;
|
||||
WALK_LIST(c, cli_log_hooks)
|
||||
{
|
||||
if (!(c->log_mask & (1 << class)))
|
||||
continue;
|
||||
if (c->ring_read <= c->ring_write)
|
||||
free = (c->ring_end - c->ring_buf) - (c->ring_write - c->ring_read + 1);
|
||||
else
|
||||
free = c->ring_read - c->ring_write - 1;
|
||||
if ((len > free) ||
|
||||
(free < c->log_threshold && class < (unsigned) L_INFO[0]))
|
||||
{
|
||||
c->ring_overflow++;
|
||||
continue;
|
||||
}
|
||||
if (c->ring_read == c->ring_write)
|
||||
ev_schedule(c->event);
|
||||
m = msg;
|
||||
l = len;
|
||||
while (l)
|
||||
{
|
||||
if (c->ring_read <= c->ring_write)
|
||||
i = c->ring_end - c->ring_write;
|
||||
else
|
||||
i = c->ring_read - c->ring_write;
|
||||
if (i > l)
|
||||
i = l;
|
||||
memcpy(c->ring_write, m, i);
|
||||
m += i;
|
||||
l -= i;
|
||||
c->ring_write += i;
|
||||
if (c->ring_write == c->ring_end)
|
||||
c->ring_write = c->ring_buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Hack for scheduled undo notification */
|
||||
extern cli *cmd_reconfig_stored_cli;
|
||||
|
||||
void
|
||||
cli_free(cli *c)
|
||||
{
|
||||
cli_set_log_echo(c, 0, 0);
|
||||
int defer = 0;
|
||||
if (c->cleanup)
|
||||
defer = c->cleanup(c);
|
||||
|
||||
Reference in New Issue
Block a user