Skip to content

Commit e44ef53

Browse files
committed
Implement the label syntax in varnishd -f
1 parent 67232b2 commit e44ef53

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

bin/varnishd/mgt/mgt_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ mgt_f_arg(struct f_arg *fa)
440440
if (p != NULL) {
441441
q = memchr(fa->farg, ',', p - fa->farg);
442442
if (q != NULL) {
443-
fa->label = strndup(q, p - q);
443+
/* Off by one to avoid the comma */
444+
fa->label = strndup(q + 1, p - q - 1);
444445
AN(fa->label);
445446
}
446447
else

bin/varnishd/mgt/mgt_vcl.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,15 @@ mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc,
370370

371371
/*--------------------------------------------------------------------*/
372372

373+
static void __match_proto__(cli_func_t)
374+
mcf_vcl_label(struct cli *cli, const char * const *av, void *priv);
375+
373376
int
374377
mgt_vcl_startup(struct cli *cli, const char *vclsrc, const char *vclname,
375378
const char *vcllabel, const char *origin, int C_flag)
376379
{
377380
char buf[20];
381+
const char *av[5];
378382
static int n = 0;
379383

380384
AN(vclsrc);
@@ -387,8 +391,15 @@ mgt_vcl_startup(struct cli *cli, const char *vclsrc, const char *vclname,
387391
return (-1);
388392
mgt_new_vcl(cli, vclname, vclsrc, origin, NULL, C_flag);
389393
active_vcl = mcf_vcl_byname(vclname);
390-
if (active_vcl != NULL && vcllabel != NULL)
391-
INCOMPL();
394+
if (active_vcl != NULL && vcllabel != NULL) {
395+
/* XXX: not sure what goes in av */
396+
av[0] = NULL;
397+
av[1] = NULL;
398+
av[2] = vcllabel;
399+
av[3] = vclname;
400+
av[4] = NULL;
401+
mcf_vcl_label(cli, av, NULL);
402+
}
392403
return (0);
393404
}
394405

bin/varnishtest/tests/a00009.vtc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,25 @@ shell -err -expect "Error: Cannot load two VCLs with the same name." {
134134
exec varnishd -n ${tmpdir}/v0 -F -a :0 -l2m,3m -f boot=${tmpdir}/ok1 \
135135
-f ${tmpdir}/ok2
136136
}
137+
138+
# Test an -f option with a VCL name and label
139+
140+
process p5 {
141+
exec varnishd -n ${tmpdir}/v0 -F -a :0 -l2m,3m -f ok1,lbl=${tmpdir}/ok1
142+
} -log -start
143+
144+
delay 1
145+
shell -match "ok1 .1 label." {varnishadm -n ${tmpdir}/v0 vcl.list}
146+
shell -match "lbl -> ok1" {varnishadm -n ${tmpdir}/v0 vcl.list}
147+
148+
process p5 -stop -wait
149+
150+
# Test an -f option with an invalid VCL name or label
151+
152+
shell -err -expect "Illegal character in VCL name ('!')" {
153+
exec varnishd -n ${tmpdir}/v0 -F -a :0 -l2m,3m -f !!!,lbl=${tmpdir}/ok1
154+
}
155+
156+
shell -err -expect "Illegal character in VCL name ('!')" {
157+
exec varnishd -n ${tmpdir}/v0 -F -a :0 -l2m,3m -f ok1,!!!=${tmpdir}/ok1
158+
}

0 commit comments

Comments
 (0)