Commit 75908c17 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a paramter for maximum CLI buffer size and use it both in child

and manager.  To take effect, it must be specified with -p on the
command line.

Use VLU for managers CLI handling.

Note CLI connection events on stderr.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2477 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 8446f91e
......@@ -144,7 +144,7 @@ CLI_Init(void)
cli_thread = pthread_self();
cli->sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
XXXAN(cli->sb);
vlu = VLU_New(cli, cli_vlu, 0);
vlu = VLU_New(cli, cli_vlu, params->cli_buffer);
XXXAN(vlu);
printf("Ready\n");
while (1) {
......
......@@ -138,6 +138,9 @@ struct params {
/* Cache vbe_conns */
unsigned cache_vbe_conns;
/* CLI buffer size */
unsigned cli_buffer;
};
extern volatile struct params *params;
......
......@@ -45,7 +45,7 @@ extern pid_t mgt_pid, child_pid;
/* mgt_cli.c */
void mgt_cli_init(void);
void mgt_cli_setup(int fdi, int fdo, int verbose);
void mgt_cli_setup(int fdi, int fdo, int verbose, const char *ident);
int mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...);
void mgt_cli_start_child(int fdi, int fdo);
void mgt_cli_stop_child(void);
......
......@@ -392,7 +392,7 @@ mgt_run(int dflag, const char *T_arg)
XXXAN(mgt_evb);
if (dflag)
mgt_cli_setup(0, 1, 1);
mgt_cli_setup(0, 1, 1, "debug");
if (T_arg)
mgt_cli_telnet(T_arg);
......
......@@ -57,6 +57,7 @@
#include "mgt_event.h"
#include "shmlog.h"
#include "vlu.h"
#include "vss.h"
static int cli_i = -1, cli_o = -1;
......@@ -288,19 +289,20 @@ struct cli_port {
int fdi;
int fdo;
int verbose;
char *buf;
int nbuf; /* next free position in buf */
int lbuf; /* length of buf */
struct vlu *vlu;
struct cli cli[1];
char name[30];
char *name;
};
static int
mgt_cli_close(const struct cli_port *cp)
{
CHECK_OBJ_NOTNULL(cp, CLI_PORT_MAGIC);
fprintf(stderr, "CLI closing: %s\n", cp->name);
vsb_delete(cp->cli->sb);
free(cp->buf);
VLU_Destroy(cp->vlu);
free(cp->name);
(void)close(cp->fdi);
if (cp->fdi == 0)
assert(open("/dev/null", O_RDONLY) == 0);
......@@ -313,11 +315,27 @@ mgt_cli_close(const struct cli_port *cp)
return (1);
}
static int
mgt_cli_vlu(void *priv, const char *p)
{
struct cli_port *cp;
CAST_OBJ_NOTNULL(cp, priv, CLI_PORT_MAGIC);
vsb_clear(cp->cli->sb);
cli_dispatch(cp->cli, cli_proto, p);
vsb_finish(cp->cli->sb);
AZ(vsb_overflowed(cp->cli->sb));
/* send the result back */
if (cli_writeres(cp->fdo, cp->cli))
return (mgt_cli_close(cp));
return (0);
}
static int
mgt_cli_callback(const struct ev *e, int what)
{
struct cli_port *cp;
char *p, *q;
int i;
CAST_OBJ_NOTNULL(cp, e->priv, CLI_PORT_MAGIC);
......@@ -325,66 +343,32 @@ mgt_cli_callback(const struct ev *e, int what)
if (what & (EV_ERR | EV_HUP | EV_GONE))
return (mgt_cli_close(cp));
/* grow the buffer if it is full */
if (cp->nbuf == cp->lbuf) {
cp->lbuf += cp->lbuf;
cp->buf = realloc(cp->buf, cp->lbuf);
XXXAN(cp->buf);
i = VLU_Fd(cp->fdi, cp->vlu);
if (i != 0) {
mgt_cli_close(cp);
return (1);
}
/* read more data into the buffer */
i = read(cp->fdi, cp->buf + cp->nbuf, cp->lbuf - cp->nbuf);
if (i <= 0)
return (mgt_cli_close(cp));
cp->nbuf += i;
for (p = q = cp->buf; q < cp->buf + cp->nbuf; ++q) {
if (*q != '\n')
continue;
/* got a newline == got a command */
*q = '\0';
vsb_clear(cp->cli->sb);
cli_dispatch(cp->cli, cli_proto, p);
vsb_finish(cp->cli->sb);
AZ(vsb_overflowed(cp->cli->sb));
/* send the result back */
if (cli_writeres(cp->fdo, cp->cli))
return (mgt_cli_close(cp));
/* ready for next command */
p = q + 1;
}
/* see if there's any data left in the buffer */
if (p != q) {
assert(q == cp->buf + cp->nbuf);
cp->nbuf -= (p - cp->buf);
memmove(cp->buf, p, cp->nbuf);
} else
cp->nbuf = 0;
return (0);
}
void
mgt_cli_setup(int fdi, int fdo, int verbose)
mgt_cli_setup(int fdi, int fdo, int verbose, const char *ident)
{
struct cli_port *cp;
cp = calloc(sizeof *cp, 1);
XXXAN(cp);
cp->vlu = VLU_New(cp, mgt_cli_vlu, params->cli_buffer);
sprintf(cp->name, "cli %d->%d", fdi, fdo);
asprintf(&cp->name, "cli %s fds{%d,%d}", ident, fdi, fdo);
XXXAN(cp->name);
fprintf(stderr, "CLI opened: %s\n", cp->name);
cp->magic = CLI_PORT_MAGIC;
cp->fdi = fdi;
cp->fdo = fdo;
cp->verbose = verbose;
cp->lbuf = 4096;
cp->buf = malloc(cp->lbuf);
XXXAN(cp->buf);
cp->cli->sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
XXXAN(cp->cli->sb);
......@@ -403,6 +387,9 @@ telnet_accept(const struct ev *ev, int what)
struct sockaddr_storage addr;
socklen_t addrlen;
int i;
char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE];
char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE];
char *p;
(void)what;
addrlen = sizeof addr;
......@@ -410,7 +397,14 @@ telnet_accept(const struct ev *ev, int what)
if (i < 0)
return (0);
mgt_cli_setup(i, i, 0);
TCP_myname(ev->fd, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1);
TCP_name((void*)&addr, addrlen, abuf2, sizeof abuf2,
pbuf2, sizeof pbuf2);
asprintf(&p, "telnet{%s:%s,%s:%s}", abuf2, pbuf2, abuf1, pbuf1);
XXXAN(p);
mgt_cli_setup(i, i, 0, p);
free(p);
return (0);
}
......
......@@ -613,6 +613,13 @@ static const struct parspec parspec[] = {
"Cache vbe_conn's or rely on malloc, that's the question.",
EXPERIMENTAL,
"off", "bool" },
{ "cli_buffer", tweak_uint, &master.cli_buffer, 4096, UINT_MAX,
"Size of buffer for CLI input."
"\nYou may need to increase this if you have big VCL files "
"and use the vcl.inline CLI command.\n"
"NB: Must be specified with -p to have effect.\n",
0,
"8192", "bytes" },
{ NULL, NULL, NULL }
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment