Skip to content

Commit

Permalink
Add VARNISH_DEFAULT_N environment variable as -n argument default
Browse files Browse the repository at this point in the history
  • Loading branch information
nigoroll committed May 24, 2024
1 parent f3bad42 commit 8f8d26c
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions bin/varnishadm/varnishadm.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ main(int argc, char * const *argv)
printf(OPTARG "\n");
exit(0);
}
n_arg = getenv("VARNISH_DEFAULT_N");
/*
* By default linux::getopt(3) mangles the argv order, such that
* varnishadm -n bla param.set foo -bar
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/mgt/mgt_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ main(int argc, char * const *argv)
const char *i_arg = NULL;
const char *j_arg = NULL;
const char *h_arg = "critbit";
const char *n_arg = NULL;
const char *n_arg = getenv("VARNISH_DEFAULT_N");
const char *S_arg = NULL;
const char *s_arg = "default,100m";
const char *W_arg = NULL;
Expand Down
2 changes: 2 additions & 0 deletions bin/varnishtest/tests/b00041.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,5 @@ shell -expect {Tested} \
{varnishadm -T ${s1_sock} -S ${v1_name}/_.secret test}

shell "varnishadm -n ${v1_name} help > /dev/null"

shell {VARNISH_DEFAULT_N="${v1_name}" varnishadm help > /dev/null}
4 changes: 4 additions & 0 deletions bin/varnishtest/tests/b00045.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ shell -err -expect {Error: Varnishd is already running} {
shell -err -expect {Error: Varnishd is already running} {
varnishd -b None -a:0 -n ${tmpdir}/v1 -F
}

shell -err -expect {Error: Varnishd is already running} {
VARNISH_DEFAULT_N="${tmpdir}/v1" varnishd -b None -a:0 -F
}
4 changes: 4 additions & 0 deletions bin/varnishtest/tests/u00003.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ shell -err -match "Usage: .*varnishncsa <options>" \
shell -match {^${localhost} 100
${localhost} 0$} \
{varnishncsa -n ${v1_name} -b -d -F "%{Host}i %b"}
# -b with VARNISH_DEFAULT_N
shell -match {^${localhost} 100
${localhost} 0$} \
{VARNISH_DEFAULT_N="${v1_name}" varnishncsa -b -d -F "%{Host}i %b"}
# -c
shell -match {^${localhost} 100
${localhost} \d+
Expand Down
1 change: 1 addition & 0 deletions bin/varnishtest/tests/u00004.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ client c1 {
} -run

shell -expect "fetch" "varnishtop -n ${v1_name} -1"
shell -expect "fetch" {VARNISH_DEFAULT_N="${v1_name}" varnishtop -1}

process p1 "varnishtop -n ${v1_name} -d" -start
delay 1
Expand Down
4 changes: 4 additions & 0 deletions bin/varnishtest/tests/u00005.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ shell -err -expect "-t: Invalid argument: foo" \
"varnishstat -t foo"
shell -err -expect "Could not get hold of varnishd" \
"varnishstat -n /nonexistent -t 1"
shell -err -expect "Could not get hold of varnishd" \
{VARNISH_DEFAULT_N="/nonexistent" varnishstat -t 1}
shell -expect "MAIN.uptime" \
"varnishstat -n ${v1_name} -1"
shell -expect "MAIN.uptime" \
{VARNISH_DEFAULT_N="${v1_name}" varnishstat -1}
shell -expect "<name>MAIN.uptime</name>" \
"varnishstat -n ${v1_name} -x"
shell -match {"MAIN.uptime":} \
Expand Down
3 changes: 3 additions & 0 deletions bin/varnishtest/tests/u00006.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ process p1 -stop
shell -match "0 CLI[ ]+- Wr 200 [0-9]+ PONG" \
{varnishlog -n ${v1_name} -d -g raw -X "Wr 200 [0-9]+ [^P]"}

shell -match "0 CLI[ ]+- Wr 200 [0-9]+ PONG" \
{VARNISH_DEFAULT_N="${v1_name}" varnishlog -d -g raw -X "Wr 200 [0-9]+ [^P]"}

client c1 {
txreq -url /foo
rxresp
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishtest/tests/u00009.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ varnish v1 -vcl+backend {} -start

process p1 -dump {varnishhist -n ${v1_name}} -start
process p2 -dump {varnishhist -n ${v1_name} -P b:BereqAcct::5:-1:1} -start
process p3 -dump {varnishhist -n ${v1_name} -P BerespBodytime -B 2} -start
process p3 -dump {VARNISH_DEFAULT_N="${v1_name}" varnishhist -P BerespBodytime -B 2} -start

process p1 -expect-text 24 0 {1e2}
process p2 -expect-text 24 0 {1e-1}
Expand Down
5 changes: 5 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Varnish Cache NEXT (2024-09-15)
.. PLEASE keep this roughly in commit order as shown by git-log / tig
(new to old)
* The environment variable ``VARNISH_DEFAULT_N`` now provides the
default "varnish name" / "workdir" as otherwise specified by he
``-n`` argument to ``varnishd`` and ``varnish*`` utilities except
``varnishtest``.

================================
Varnish Cache 7.5.0 (2024-03-18)
================================
Expand Down
5 changes: 4 additions & 1 deletion lib/libvarnish/vin.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ VIN_n_Arg(const char *n_arg)
void
VIN_DumpDefaults(void)
{
printf(" The default is taken from the ``VARNISH_DEFAULT_N`` "
"environment variable.\n\n");
printf(" Relative paths will be appended to ``%s``.\n\n",
VARNISH_STATE_DIR);
printf(" The default value is ``%s``.\n\n",
printf(" If neither ``VARNISH_DEFAULT_N`` nor ``-n`` are "
"present, the value is ``%s``.\n\n",
VARNISH_STATE_DIR "/" VARNISH_DEFAULT_REL_NAME);
printf(" Note: These defaults may be distribution specific.\n\n");
}
2 changes: 2 additions & 0 deletions lib/libvarnishapi/vsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ VSM_New(void)
ALLOC_OBJ(vd, VSM_MAGIC);
AN(vd);

REPLACE(vd->wdname, getenv("VARNISH_DEFAULT_N"));

vd->mgt = vsm_newset(VSM_MGT_DIRNAME);
vd->mgt->flag_running = VSM_MGT_RUNNING;
vd->mgt->flag_changed = VSM_MGT_CHANGED;
Expand Down
1 change: 1 addition & 0 deletions lib/libvarnishapi/vut.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ VUT_Init(const char *progname, int argc, char * const *argv,
AZ(vut->vsl);
vut->vsl = VSL_New();
AN(vut->vsl);
REPLACE(vut->n_arg, getenv("VARNISH_DEFAULT_N"));
return (vut);
}

Expand Down

0 comments on commit 8f8d26c

Please sign in to comment.