Skip to content

Commit

Permalink
Generate documentation of the varnishd -n option
Browse files Browse the repository at this point in the history
with greetings from the rabbit-hole opened by varnishcache#4105
  • Loading branch information
nigoroll committed May 24, 2024
1 parent 725c9d5 commit d0cd96d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
16 changes: 16 additions & 0 deletions bin/varnishd/mgt/mgt_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ static const char opt_spec[] = "?a:b:CdE:f:Fh:i:I:j:l:M:n:P:p:r:S:s:T:t:VW:x:";

/*--------------------------------------------------------------------*/

// Basic options documentation with compile time dependencies
static void
mgt_DumpOptions(void)
{
printf(".. _opt_n:\n\n");
printf("-n workdir\n\n");
printf(" Runtime directory for the shared memory, "
"compiled VCLs etc.\n\n");
printf(" In performance critical applications, this directory "
"should be on a RAM backed filesystem.\n\n");
VIN_DumpDefaults();
}

static void
usage(void)
{
Expand Down Expand Up @@ -121,6 +134,7 @@ usage(void)
printf(FMT, "-x cli", "CLI command documentation");
printf(FMT, "-x builtin", "Builtin VCL program");
printf(FMT, "-x optstring", "List of getopt options");
printf(FMT, "-x options", "Dynamic options documentation");

printf("\nOperations options:\n");

Expand Down Expand Up @@ -359,6 +373,8 @@ mgt_x_arg(const char *x_arg)
mgt_DumpBuiltin();
else if (!strcmp(x_arg, "optstring"))
(void)printf("%s\n", opt_spec);
else if (!strcmp(x_arg, "options"))
mgt_DumpOptions();
else
ARGV_ERR("Invalid -x argument\n");
}
Expand Down
5 changes: 5 additions & 0 deletions doc/sphinx/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ include/params.rst: $(top_builddir)/bin/varnishd/varnishd
mv -f ${@}_ ${@}
BUILT_SOURCES += include/params.rst

include/options.rst: $(top_builddir)/bin/varnishd/varnishd
$(top_builddir)/bin/varnishd/varnishd -x options > ${@}_
mv -f ${@}_ ${@}
BUILT_SOURCES += include/options.rst

include/counters.rst:
ln -s $(abs_top_builddir)/lib/libvsc/counters.rst $@
BUILT_SOURCES += include/counters.rst
Expand Down
14 changes: 1 addition & 13 deletions doc/sphinx/reference/varnishd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,7 @@ Basic options
could later be accessed remotely, starting `varnishd` requires
local privileges.

.. _opt_n:

-n workdir

Runtime directory for the shared memory, compiled VCLs etc.

In performance critical applications, this directory should be
on a RAM backed filesystem.

Relative paths will be appended to `/var/run/` (NB: Binary packages
of Varnish may have adjusted this to the platform.)

The default value is `/var/run/varnishd` (NB: as above.)
.. include:: ../include/options.rst

Documentation options
---------------------
Expand Down
3 changes: 2 additions & 1 deletion include/vin.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#ifndef VIN_H_INCLUDED
#define VIN_H_INCLUDED

/* This function lives in both libvarnish and libvarnishapi */
/* These functions live in both libvarnish and libvarnishapi */
char *VIN_n_Arg(const char *n_arg);
void VIN_DumpDefaults(void);
#endif
13 changes: 12 additions & 1 deletion lib/libvarnish/vin.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "vin.h"
#include "vsb.h"

#define VARNISH_DEFAULT_REL_NAME "varnishd"
char *
VIN_n_Arg(const char *n_arg)
{
Expand All @@ -52,7 +53,7 @@ VIN_n_Arg(const char *n_arg)
AN(vsb);
if (n_arg == NULL || n_arg[0] == '\0') {
VSB_cat(vsb, VARNISH_STATE_DIR);
VSB_cat(vsb, "/varnishd");
VSB_cat(vsb, "/" VARNISH_DEFAULT_REL_NAME);
} else if (n_arg[0] == '/') {
VSB_cat(vsb, n_arg);
} else {
Expand All @@ -66,3 +67,13 @@ VIN_n_Arg(const char *n_arg)
VSB_destroy(&vsb);
return (retval);
}

void
VIN_DumpDefaults(void)
{
printf(" Relative paths will be appended to ``%s``.\n\n",
VARNISH_STATE_DIR);
printf(" The default value is ``%s``.\n\n",
VARNISH_STATE_DIR "/" VARNISH_DEFAULT_REL_NAME);
printf(" Note: These defaults may be distribution specific.\n\n");
}
3 changes: 2 additions & 1 deletion man/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ varnishadm.1: $(top_builddir)/doc/sphinx/reference/varnishadm.rst

varnishd.1: \
$(top_builddir)/doc/sphinx/reference/varnishd.rst \
$(top_builddir)/doc/sphinx/include/params.rst
$(top_builddir)/doc/sphinx/include/params.rst \
$(top_builddir)/doc/sphinx/include/options.rst
$(BUILD_MAN) $(top_builddir)/doc/sphinx/reference/varnishd.rst $@

varnishncsa.1: \
Expand Down

0 comments on commit d0cd96d

Please sign in to comment.