[master] 45edc4d Move vlu to the private cli struct and turn ->cmd into a VSB.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Nov 7 19:21:07 UTC 2017
commit 45edc4df31fd8cababfcae52d9c5c01164c593cd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Nov 7 09:06:45 2017 +0000
Move vlu to the private cli struct and turn ->cmd into a VSB.
diff --git a/bin/varnishd/cache/cache_cli.c b/bin/varnishd/cache/cache_cli.c
index d597f42..ee542ec 100644
--- a/bin/varnishd/cache/cache_cli.c
+++ b/bin/varnishd/cache/cache_cli.c
@@ -73,7 +73,7 @@ cli_cb_before(const struct cli *cli)
{
ASSERT_CLI();
- VSL(SLT_CLI, 0, "Rd %s", cli->cmd);
+ VSL(SLT_CLI, 0, "Rd %s", VSB_data(cli->cmd));
VCL_Poll();
VBE_Poll();
Lck_Lock(&cli_mtx);
diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index e9c214a..0d5f777 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -340,8 +340,8 @@ mgt_cli_cb_before(const struct cli *cli)
{
if (cli->priv == stderr)
- fprintf(stderr, "> %s\n", cli->cmd);
- MGT_Complain(C_CLI, "CLI %s Rd %s", cli->ident, cli->cmd);
+ fprintf(stderr, "> %s\n", VSB_data(cli->cmd));
+ MGT_Complain(C_CLI, "CLI %s Rd %s", cli->ident, VSB_data(cli->cmd));
}
static void
@@ -351,7 +351,7 @@ mgt_cli_cb_after(const struct cli *cli)
MGT_Complain(C_CLI, "CLI %s Wr %03u %s",
cli->ident, cli->result, VSB_data(cli->sb));
if (cli->priv == stderr &&
- cli->result != CLIS_OK && cli->cmd[0] != '-') {
+ cli->result != CLIS_OK && *VSB_data(cli->cmd) != '-') {
MGT_Complain(C_ERR, "-I file CLI command failed (%d)\n%s\n",
cli->result, VSB_data(cli->sb));
exit(2);
diff --git a/include/vcli_serve.h b/include/vcli_serve.h
index 941551d..a7b3471 100644
--- a/include/vcli_serve.h
+++ b/include/vcli_serve.h
@@ -34,7 +34,6 @@
#include "vcli.h"
struct cli; /* NB: struct cli is opaque at this level. */
-struct vlu;
struct VCLS;
typedef void cli_func_t(struct cli*, const char * const *av, void *priv);
@@ -68,18 +67,17 @@ struct cli_proto {
/* a CLI session */
struct cli {
- unsigned magic;
+ unsigned magic;
#define CLI_MAGIC 0x4038d570
void *priv;
- struct vsb *sb;
- enum VCLI_status_e result;
- char *cmd;
- unsigned auth;
- char challenge[34];
- char *ident;
- struct vlu *vlu;
- struct VCLS *cls;
- volatile unsigned *limit;
+ struct vsb *sb;
+ enum VCLI_status_e result;
+ struct vsb *cmd;
+ unsigned auth;
+ char challenge[34];
+ char *ident;
+ struct VCLS *cls;
+ volatile unsigned *limit;
};
/* The implementation must provide these functions */
diff --git a/lib/libvarnish/vcli_serve.c b/lib/libvarnish/vcli_serve.c
index ea6ea8d..0f68ec3 100644
--- a/lib/libvarnish/vcli_serve.c
+++ b/lib/libvarnish/vcli_serve.c
@@ -64,6 +64,7 @@ struct VCLS_fd {
struct vsb *last_arg;
int last_idx;
char **argv;
+ struct vlu *vlu;
};
struct VCLS {
@@ -342,9 +343,13 @@ cls_vlu(void *priv, const char *p)
continue;
if (*p == '\0')
return (0);
- REPLACE(cli->cmd, p);
AN(p); /* for FlexeLint */
+ cli->cmd = VSB_new(NULL, NULL, strlen(p) + 1, 0);
+ AN(cli->cmd);
+ VSB_cat(cli->cmd, p);
+ AZ(VSB_finish(cli->cmd));
+
/* We ignore a single leading '-' (for -I cli_file) */
if (p[0] == '-')
av = VAV_Parse(p + 1, NULL, 0);
@@ -354,8 +359,7 @@ cls_vlu(void *priv, const char *p)
if (av[0] != NULL) {
i = cls_vlu2(priv, av);
VAV_Free(av);
- free(cli->cmd);
- cli->cmd = NULL;
+ VSB_destroy(&cli->cmd);
return (i);
}
for (i = 1; av[i] != NULL; i++)
@@ -363,8 +367,7 @@ cls_vlu(void *priv, const char *p)
if (i < 3 || cli->auth == 0 || strcmp(av[i - 2], "<<")) {
i = cls_vlu2(priv, av);
VAV_Free(av);
- free(cli->cmd);
- cli->cmd = NULL;
+ VSB_destroy(&cli->cmd);
return (i);
}
cfd->argv = av;
@@ -391,8 +394,7 @@ cls_vlu(void *priv, const char *p)
cfd->argv[cfd->last_idx] = NULL;
VAV_Free(cfd->argv);
cfd->argv = NULL;
- free(cli->cmd);
- cli->cmd = NULL;
+ VSB_destroy(&cli->cmd);
VSB_destroy(&cfd->last_arg);
cfd->last_idx = 0;
return (i);
@@ -437,8 +439,8 @@ VCLS_AddFd(struct VCLS *cs, int fdi, int fdo, cls_cb_f *closefunc, void *priv)
cfd->fdo = fdo;
cfd->cli = &cfd->clis;
cfd->cli->magic = CLI_MAGIC;
- cfd->cli->vlu = VLU_New(cls_vlu, cfd, *cs->maxlen);
- AN(cfd->cli->vlu);
+ cfd->vlu = VLU_New(cls_vlu, cfd, *cs->maxlen);
+ AN(cfd->vlu);
cfd->cli->sb = VSB_new_auto();
AN(cfd->cli->sb);
cfd->cli->limit = cs->limit;
@@ -459,7 +461,7 @@ cls_close_fd(struct VCLS *cs, struct VCLS_fd *cfd)
VTAILQ_REMOVE(&cs->fds, cfd, list);
cs->nfd--;
- VLU_Destroy(&cfd->cli->vlu);
+ VLU_Destroy(&cfd->vlu);
VSB_destroy(&cfd->cli->sb);
if (cfd->closefunc == NULL) {
(void)close(cfd->fdi);
@@ -538,7 +540,7 @@ VCLS_Poll(struct VCLS *cs, const struct cli *cli, int timeout)
if (pfd[0].revents & POLLHUP)
k = 1;
else
- k = VLU_Fd(cfd->cli->vlu, cfd->fdi);
+ k = VLU_Fd(cfd->vlu, cfd->fdi);
if (k)
cls_close_fd(cs, cfd);
return (k);
More information about the varnish-commit
mailing list