[master] a0436a439 Use the Turbo encabulator for backend.list
Poul-Henning Kamp
phk at FreeBSD.org
Wed Feb 20 21:48:07 UTC 2019
commit a0436a439f078902812a5adb1f2d2f979ca315bc
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Feb 20 20:28:37 2019 +0000
Use the Turbo encabulator for backend.list
Lines starting with a space are interpreted as a "block quote" and
not ecabulated, this is used for probe details.
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index f5b867335..3ff3c9ac7 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -465,7 +465,7 @@ vbe_list(VRT_CTX, const struct director *d, struct vsb *vsb, int pflag,
else if (pflag)
return;
else
- VSB_printf(vsb, "%-*s", VDI_LIST_W_PROBE,
+ VSB_printf(vsb, "%s",
d->sick ? "sick" : "healthy");
}
diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index 19719fca3..8e0d22036 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -515,19 +515,19 @@ void
VBP_Status(struct vsb *vsb, const struct backend *be, int details, int json)
{
struct vbp_target *vt;
- char buf[VDI_LIST_W_PROBE + 2];
CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
vt = be->probe;
CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC);
if (!details) {
- bprintf(buf, "%u/%u %s", vt->good, vt->window,
- vt->backend->director->sick ? "bad" : "good");
if (json)
- VSB_printf(vsb, "\"%s\"", buf);
+ VSB_printf(vsb, "[%u, %u, \"%s\"]",
+ vt->good, vt->window,
+ vt->backend->director->sick ? "bad" : "good");
else
- VSB_printf(vsb, "%-*s", VDI_LIST_W_PROBE, buf);
+ VSB_printf(vsb, "%u/%u %s", vt->good, vt->window,
+ vt->backend->director->sick ? "bad" : "good");
return;
}
@@ -547,7 +547,7 @@ VBP_Status(struct vsb *vsb, const struct backend *be, int details, int json)
}
VSB_printf(vsb,
- "\nCurrent states good: %2u threshold: %2u window: %2u\n",
+ "\n Current states good: %2u threshold: %2u window: %2u\n",
vt->good, vt->threshold, vt->window);
VSB_printf(vsb,
" Average response time of good probes: %.6f\n", vt->avg);
diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index c8a4d863c..5161be684 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -274,6 +274,7 @@ struct list_args {
int p;
int j;
const char *jsep;
+ struct vsb *vsb;
};
static const char *
@@ -291,7 +292,9 @@ do_list(struct cli *cli, struct director *d, void *priv)
struct list_args *la;
struct vrt_ctx *ctx;
+ AN(cli);
CAST_OBJ_NOTNULL(la, priv, LIST_ARGS_MAGIC);
+ AN(la->vsb);
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
if (d->vdir->admin_health == VDI_AH_DELETED)
@@ -300,20 +303,19 @@ do_list(struct cli *cli, struct director *d, void *priv)
ctx = VCL_Get_CliCtx(0);
// XXX admin health "probe" for the no-probe case is confusing
- VCLI_Out(cli, "\n%-*s %-*s ",
- VDI_LIST_W_NAME, d->vdir->cli_name,
- VDI_LIST_W_ADMIN, VDI_Ahealth(d));
+ VSB_printf(la->vsb, "%s\t%s\t", d->vdir->cli_name, VDI_Ahealth(d));
if (d->vdir->methods->list != NULL)
- d->vdir->methods->list(ctx, d, cli->sb, 0, 0);
+ d->vdir->methods->list(ctx, d, la->vsb, 0, 0);
else
- VCLI_Out(cli, "%-*s", VDI_LIST_W_PROBE, cli_health(ctx, d));
+ VSB_printf(la->vsb, "%s", cli_health(ctx, d));
VTIM_format(d->vdir->health_changed, time_str);
- VCLI_Out(cli, " %s", time_str);
+ VSB_printf(la->vsb, "\t%s", time_str);
if (la->p && d->vdir->methods->list != NULL)
- d->vdir->methods->list(ctx, d, cli->sb, la->p, 0);
+ d->vdir->methods->list(ctx, d, la->vsb, la->p, 0);
+ VSB_printf(la->vsb, "\n");
VCL_Rel_CliCtx(&ctx);
AZ(ctx);
@@ -392,7 +394,7 @@ cli_backend_list(struct cli *cli, const char * const *av, void *priv)
return;
}
if (la->j) {
- VCLI_JSON_begin(cli, 2, av);
+ VCLI_JSON_begin(cli, 3, av);
VCLI_Out(cli, ",\n");
VCLI_Out(cli, "{\n");
VSB_indent(cli->sb, 2);
@@ -402,12 +404,12 @@ cli_backend_list(struct cli *cli, const char * const *av, void *priv)
VCLI_Out(cli, "}");
VCLI_JSON_end(cli);
} else {
- VCLI_Out(cli, "%-*s %-*s %-*s %s",
- VDI_LIST_W_NAME, "Backend name",
- VDI_LIST_W_ADMIN, "Admin",
- VDI_LIST_W_PROBE, "Probe",
- "Last change");
+ la->vsb = VSB_new_auto();
+ AN(la->vsb);
+ VSB_printf(la->vsb, "%s\t%s\t%s\t%s\n",
+ "Backend name", "Admin", "Probe", "Last change");
(void)VCL_IterDirector(cli, av[i], do_list, la);
+ VCLI_VTE(cli, &la->vsb, 80);
}
}
diff --git a/include/vrt.h b/include/vrt.h
index 11c4eb2c2..f6fc9ca26 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -496,11 +496,6 @@ struct vdi_methods {
vdi_list_f *list;
};
-/* width of fields in "backend.list" */
-#define VDI_LIST_W_NAME 30
-#define VDI_LIST_W_ADMIN 7
-#define VDI_LIST_W_PROBE 14
-
struct vcldir;
struct director {
diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c
index 3063d4b90..c2f49ec51 100644
--- a/lib/libvarnish/vte.c
+++ b/lib/libvarnish/vte.c
@@ -66,6 +66,11 @@ VCLI_VTE(struct cli *cli, struct vsb **src, int width)
AN(s);
memset(w_col, 0, sizeof w_col);
for (p = s; *p ; p++) {
+ if (wl == 0 && *p == ' ') {
+ while (p[1] != '\0' && *p != '\n')
+ p++;
+ continue;
+ }
if (*p == '\t' || *p == '\n') {
if (wc > w_col[cc])
w_col[cc] = wc;
@@ -81,9 +86,10 @@ VCLI_VTE(struct cli *cli, struct vsb **src, int width)
if (wl > w_ln)
w_ln = wl;
wl = 0;
+ } else {
+ wc++;
+ wl++;
}
- wc++;
- wl++;
}
if (n_col == 0)
@@ -97,6 +103,15 @@ VCLI_VTE(struct cli *cli, struct vsb **src, int width)
cc = 0;
wc = 0;
for (p = s; *p ; p++) {
+ if (wc == 0 && cc == 0 && *p == ' ') {
+ while (p[1] != '\0') {
+ VCLI_Out(cli, "%c", *p);
+ if (*p == '\n')
+ break;
+ p++;
+ }
+ continue;
+ }
if (*p == '\t') {
while (wc++ < w_col[cc] + nsp)
VCLI_Out(cli, " ");
More information about the varnish-commit
mailing list