Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions bin/varnishadm/varnishadm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2015 Varnish Software AS
* Copyright (c) 2006-2026 Varnish Software AS
* All rights reserved.
*
* Author: Cecilie Fritzvold <cecilihf@linpro.no>
Expand Down Expand Up @@ -67,6 +67,7 @@
#include "vapi/vsm.h"
#include "vas.h"
#include "vcli.h"
#include "vin.h"
#include "vjsn.h"
#include "vtcp.h"

Expand Down Expand Up @@ -390,6 +391,8 @@ usage(int status)
fprintf(stderr,
"Usage: varnishadm [-h] [-n workdir] [-p] [-S secretfile] "
"[-T [address]:port] [-t timeout] [command [...]]\n");
fprintf(stderr,
" varnishadm -x workdir [name]\n");
fprintf(stderr, "\t-n is mutually exclusive with -S and -T\n");
exit(status);
}
Expand Down Expand Up @@ -452,11 +455,12 @@ t_arg_timeout(const char *t_arg)
return (1);
}

#define OPTARG "hn:pS:T:t:"
#define OPTARG "hn:pS:T:t:x:"

int
main(int argc, char * const *argv)
{
char *wd;
const char *T_arg = NULL;
const char *S_arg = NULL;
const char *n_arg = NULL;
Expand Down Expand Up @@ -495,6 +499,21 @@ main(int argc, char * const *argv)
case 't':
t_arg = optarg;
break;
case 'x':
if (argc != 3 && argc != 4) {
fprintf(stderr,
"-x must be the only option\n");
usage(1);
}
if (strcmp(optarg, "workdir")) {
fprintf(stderr, "Invalid -x argument\n");
usage(1);
}
wd = VIN_n_Arg(argc == 4 ? argv[3] : NULL);
AN(wd);
printf("%s\n", wd);
free(wd);
exit(0);
default:
usage(1);
}
Expand Down
32 changes: 32 additions & 0 deletions bin/varnishtest/tests/u00022.vtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
varnishtest "varnishadm -x workdir"

# happy paths
shell {
# -x workdir
DEFAULT_WORKDIR=$(varnishadm -x workdir)
test -n "$DEFAULT_WORKDIR"

# -x workdir foo: returns dirname(DEFAULT_WORKDIR)/foo
WORKDIR_FOO=$(varnishadm -x workdir foo)
EXPECTED_FOO=$(dirname "$DEFAULT_WORKDIR")/foo
test "$WORKDIR_FOO" = "$EXPECTED_FOO"

# -x workdir /foo: returns /foo
WORKDIR_ABSOLUTE=$(varnishadm -x workdir /foo)
test "$WORKDIR_ABSOLUTE" = "/foo"
}

# -x with other options is rejected
shell -exit 1 -match "-x must be the only option" {
varnishadm -n /tmp -x workdir
}

# -x with invalid argument fails
shell -exit 1 -match "Invalid -x argument" {
varnishadm -x invalid
}

# -x workdir with too many arguments is rejected
shell -exit 1 -match "-x must be the only option" {
varnishadm -x workdir arg1 arg2
}
3 changes: 3 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Vinyl-Cache NEXT (2026-03-15)
being retained as an alias. ``req.ttl`` is now deprecated, but no warning is
emitted yet. It will be removed in a future version of Vinyl-Cache. (`4389`_)

* ``varnishadm -x workdir`` will print the default work directory and exit. This
is useful for tools that need to discover the VSM location in most setups.

================================
Varnish-Cache 8.0.0 (2025-09-15)
================================
Expand Down