[master] a535c1a Make the name 'default' truly magic for both backends and probes.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Jan 30 00:13:06 UTC 2018
commit a535c1aef6f88bce1554f72b90b84dc0817acff9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Jan 30 00:11:56 2018 +0000
Make the name 'default' truly magic for both backends and probes.
diff --git a/bin/varnishtest/tests/v00038.vtc b/bin/varnishtest/tests/v00038.vtc
index 53ba0ea..9b8cfb0 100644
--- a/bin/varnishtest/tests/v00038.vtc
+++ b/bin/varnishtest/tests/v00038.vtc
@@ -92,3 +92,8 @@ varnish v1 -errvcl "Mandatory field 'host' missing." {
.port = "NONE";
}
}
+varnish v1 -errvcl "No default probe defined" {
+ backend b1 {
+ .probe = default;
+ }
+}
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index 30e816a..64f73ac 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -35,6 +35,19 @@
#include "vcc_compile.h"
+const char *
+vcc_default_probe(struct vcc *tl)
+{
+
+ if (tl->default_probe != NULL)
+ return (tl->default_probe);
+ VSB_printf(tl->sb, "No default probe defined\n");
+ vcc_ErrToken(tl, tl->t);
+ VSB_printf(tl->sb, " at\n");
+ vcc_ErrWhere(tl, tl->t);
+ return ("");
+}
+
/*--------------------------------------------------------------------
* Struct sockaddr is not really designed to be a compile time
* initialized data structure, so we encode it as a byte-string
@@ -390,13 +403,7 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname)
ERRCHK(tl);
} else if (vcc_IdIs(t_field, "probe") && tl->t->tok == ID) {
if (vcc_IdIs(tl->t, "default")) {
- if (tl->default_probe == NULL) {
- VSB_printf(tl->sb,
- "No default probe defined\n");
- vcc_ErrToken(tl, tl->t);
- VSB_printf(tl->sb, " at\n");
- vcc_ErrWhere(tl, tl->t);
- }
+ (void)vcc_default_probe(tl);
} else {
pb = VCC_SymbolGet(tl, SYM_PROBE,
"Probe not found", XREF_REF);
@@ -467,6 +474,7 @@ vcc_ParseBackend(struct vcc *tl)
{
struct token *t_first, *t_be;
struct symbol *sym;
+ const char *dn;
tl->ndirector++;
t_first = tl->t;
@@ -476,24 +484,27 @@ vcc_ParseBackend(struct vcc *tl)
ERRCHK(tl);
t_be = tl->t;
- sym = VCC_HandleSymbol(tl, BACKEND, "vgc_backend");
-
- ERRCHK(tl);
-
- Fh(tl, 0, "\nstatic struct director *%s;\n", sym->rname);
-
- vcc_ParseHostDef(tl, t_be, sym->rname);
- ERRCHK(tl);
-
+ if (vcc_IdIs(tl->t, "default")) {
+ vcc_NextToken(tl);
+ dn = "vgc_backend_default";
+ tl->default_director = dn;
+ } else {
+ sym = VCC_HandleSymbol(tl, BACKEND, "vgc_backend");
+ ERRCHK(tl);
+ dn = sym->rname;
+ if (tl->default_director == NULL) {
+ tl->default_director = dn;
+ sym->nref++;
+ }
+ }
+ Fh(tl, 0, "\nstatic struct director *%s;\n", dn);
+ vcc_ParseHostDef(tl, t_be, dn);
if (tl->err) {
VSB_printf(tl->sb,
"\nIn %.*s specification starting at:\n", PF(t_first));
vcc_ErrWhere(tl, t_first);
return;
}
-
- if (tl->default_director == NULL || vcc_IdIs(t_be, "default"))
- tl->default_director = sym;
}
void
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 1dc52ae..ce2d151 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -415,8 +415,7 @@ EmitStruct(const struct vcc *tl)
Fc(tl, 0, "\nconst struct VCL_conf VCL_conf = {\n");
Fc(tl, 0, "\t.magic = VCL_CONF_MAGIC,\n");
Fc(tl, 0, "\t.event_vcl = VGC_Event,\n");
- Fc(tl, 0, "\t.default_director = &%s,\n",
- tl->default_director->rname);
+ Fc(tl, 0, "\t.default_director = &%s,\n", tl->default_director);
if (tl->default_probe != NULL)
Fc(tl, 0, "\t.default_probe = %s,\n", tl->default_probe);
Fc(tl, 0, "\t.ref = VGC_ref,\n");
@@ -611,9 +610,6 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
return (NULL);
}
- /* Refcount the default director & probe*/
- tl->default_director->nref++;
-
/* Check for orphans */
if (vcc_CheckReferences(tl))
return (NULL);
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index e401fec..8d5a75b 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -219,8 +219,8 @@ struct vcc {
int nprobe;
int ndirector;
- struct symbol *default_director;
- char *default_probe;
+ const char *default_director;
+ const char *default_probe;
unsigned unique;
@@ -244,6 +244,7 @@ int vcc_ParseAction(struct vcc *tl);
/* vcc_backend.c */
struct fld_spec;
+const char *vcc_default_probe(struct vcc *);
void vcc_Backend_Init(struct vcc *tl);
void vcc_ParseProbe(struct vcc *tl);
void vcc_ParseBackend(struct vcc *tl);
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 4bf3b72..0b1d7b6 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -648,6 +648,17 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
}
switch (tl->t->tok) {
case ID:
+ if (vcc_IdIs(tl->t, "default") && fmt == PROBE) {
+ vcc_NextToken(tl);
+ *e = vcc_mk_expr(PROBE, "%s", vcc_default_probe(tl));
+ return;
+ }
+ if (vcc_IdIs(tl->t, "default") && fmt == BACKEND) {
+ vcc_NextToken(tl);
+ *e = vcc_mk_expr(BACKEND,
+ "*(VCL_conf.default_director)");
+ return;
+ }
sym = VCC_SymbolGet(tl, SYM_NONE, "Symbol not found",
XREF_NONE);
ERRCHK(tl);
More information about the varnish-commit
mailing list