tweak_t *func;
const char *expl;
const char *def;
+ const char *units;
};
/*--------------------------------------------------------------------*/
}
*dst = u;
} else
- cli_out(cli, "%u [seconds]\n", *dst);
+ cli_out(cli, "%u", *dst);
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+tweak_generic_bool(struct cli *cli, unsigned *dest, const char *arg)
+{
+ if (arg != NULL) {
+ if (!strcasecmp(arg, "off"))
+ *dest = 0;
+ else if (!strcasecmp(arg, "disable"))
+ *dest = 0;
+ else if (!strcasecmp(arg, "no"))
+ *dest = 0;
+ else if (!strcasecmp(arg, "on"))
+ *dest = 1;
+ else if (!strcasecmp(arg, "enable"))
+ *dest = 1;
+ else if (!strcasecmp(arg, "yes"))
+ *dest = 1;
+ else {
+ cli_out(cli, "use \"on\" or \"off\"\n");
+ cli_result(cli, CLIS_PARAM);
+ return;
+ }
+ } else
+ cli_out(cli, *dest ? "on" : "off");
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+tweak_generic_uint(struct cli *cli, unsigned *dest, const char *arg, unsigned min, unsigned max)
+{
+ unsigned u;
+
+ if (arg != NULL) {
+ if (!strcasecmp(arg, "unlimited"))
+ u = UINT_MAX;
+ else
+ u = strtoul(arg, NULL, 0);
+ if (u < min) {
+ cli_out(cli, "Must be at least %u", min);
+ cli_result(cli, CLIS_PARAM);
+ return;
+ }
+ if (u > max) {
+ cli_out(cli, "Must be no more than %u", max);
+ cli_result(cli, CLIS_PARAM);
+ return;
+ }
+ *dest = u;
+ } else if (*dest == UINT_MAX) {
+ cli_out(cli, "unlimited", *dest);
+ } else {
+ cli_out(cli, "%u", *dest);
+ }
}
/*--------------------------------------------------------------------*/
{
(void)par;
- if (arg != NULL)
- params->default_ttl = strtoul(arg, NULL, 0);
- else
- cli_out(cli, "%u [seconds]\n", params->default_ttl);
+ tweak_generic_uint(cli, ¶ms->default_ttl, arg, 0, UINT_MAX);
}
/*--------------------------------------------------------------------*/
static void
tweak_thread_pool_min(struct cli *cli, struct parspec *par, const char *arg)
{
- unsigned u;
(void)par;
- if (arg != NULL) {
- u = strtoul(arg, NULL, 0);
- if (u >= params->wthread_max) {
- cli_out(cli, "Minimum must be less than maximum\n");
- cli_result(cli, CLIS_PARAM);
- return;
- }
- params->wthread_min = u;
- } else
- cli_out(cli, "%u [threads]\n", params->wthread_min);
+ tweak_generic_uint(cli, ¶ms->wthread_min, arg,
+ 0, params->wthread_max);
}
/*--------------------------------------------------------------------*/
static void
tweak_thread_pool_max(struct cli *cli, struct parspec *par, const char *arg)
{
- unsigned u;
(void)par;
- if (arg != NULL) {
- u = strtoul(arg, NULL, 0);
- if (u <= params->wthread_min) {
- cli_out(cli, "Maximum must be greater than minimum\n");
- cli_result(cli, CLIS_PARAM);
- return;
- }
- params->wthread_max = u;
- }
- if (params->wthread_max == UINT_MAX)
- cli_out(cli, "unlimited\n");
- else
- cli_out(cli, "%u [threads]\n", params->wthread_max);
+ tweak_generic_uint(cli, ¶ms->wthread_max, arg,
+ params->wthread_min, UINT_MAX);
}
/*--------------------------------------------------------------------*/
static void
tweak_http_workspace(struct cli *cli, struct parspec *par, const char *arg)
{
- unsigned u;
(void)par;
- if (arg != NULL) {
- u = strtoul(arg, NULL, 0);
- if (u <= 1024) {
- cli_out(cli, "Workspace must be at least 1024 bytes\n");
- cli_result(cli, CLIS_PARAM);
- return;
- }
- params->mem_workspace = u;
- } else
- cli_out(cli, "%u [bytes]\n", params->mem_workspace);
+ tweak_generic_uint(cli, ¶ms->mem_workspace, arg,
+ 1024, UINT_MAX);
}
/*--------------------------------------------------------------------*/
static void
tweak_auto_restart(struct cli *cli, struct parspec *par, const char *arg)
{
- unsigned u;
(void)par;
- if (arg != NULL) {
- u = strtoul(arg, NULL, 0);
- if (u != 0 && u != 1) {
- cli_out(cli, "Only zero and one allowed.\n");
- cli_result(cli, CLIS_PARAM);
- return;
- }
- params->auto_restart = u;
- } else
- cli_out(cli, "%u {1 = yes, 0 = no}\n", params->auto_restart);
+ tweak_generic_bool(cli, ¶ms->auto_restart, arg);
}
/*--------------------------------------------------------------------*/
static void
tweak_fetch_chunksize(struct cli *cli, struct parspec *par, const char *arg)
{
- unsigned u;
(void)par;
- if (arg != NULL) {
- u = strtoul(arg, NULL, 0);
- params->fetch_chunksize = u * 1024;
- } else
- cli_out(cli, "%u [kb]\n", params->fetch_chunksize * 1024);
+ tweak_generic_uint(cli, ¶ms->fetch_chunksize, arg,
+ 4, UINT_MAX / 1024);
}
#ifdef HAVE_SENDFILE
static void
tweak_sendfile_threshold(struct cli *cli, struct parspec *par, const char *arg)
{
- unsigned u;
(void)par;
- if (arg != NULL) {
- u = strtoul(arg, NULL, 0);
- params->sendfile_threshold = u;
- } else
- cli_out(cli, "%u [bytes]\n", params->sendfile_threshold);
+ tweak_generic_uint(cli, ¶ms->sendfile_threshold, arg, 0, UINT_MAX);
}
#endif /* HAVE_SENDFILE */
tweak_vcl_trace(struct cli *cli, struct parspec *par, const char *arg)
{
(void)par;
- if (arg != NULL) {
- if (!strcasecmp(arg, "off"))
- params->vcl_trace = 0;
- else if (!strcasecmp(arg, "disable"))
- params->vcl_trace = 0;
- else if (!strcasecmp(arg, "no"))
- params->vcl_trace = 0;
- else if (!strcasecmp(arg, "on"))
- params->vcl_trace = 1;
- else if (!strcasecmp(arg, "enable"))
- params->vcl_trace = 1;
- else if (!strcasecmp(arg, "yes"))
- params->vcl_trace = 1;
- else {
- cli_out(cli, "use \"on\" or \"off\"\n");
- cli_result(cli, CLIS_PARAM);
- return;
- }
- } else
- cli_out(cli, params->vcl_trace ? "on\n" : "off\n");
+ tweak_generic_bool(cli, ¶ms->vcl_trace, arg);
}
/*--------------------------------------------------------------------*/
params->listen_host = a;
params->listen_port = p;
} else
- cli_out(cli, "%s\n", params->listen_address);
+ cli_out(cli, "%s", params->listen_address);
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+tweak_listen_depth(struct cli *cli, struct parspec *par, const char *arg)
+{
+ (void)par;
+ tweak_generic_uint(cli, ¶ms->listen_depth, arg, 0, UINT_MAX);
}
+
/*--------------------------------------------------------------------*/
/*
"Objects already cached will not be affected by changes "
"made until they are fetched from the backend again.\n"
"To force an immediate effect at the expense of a total "
- "flush of the cache use \"url.purge .\"\n"
- "Default is 120 seconds. ", "120" },
+ "flush of the cache use \"url.purge .\"",
+ "120", "seconds" },
{ "thread_pool_max", tweak_thread_pool_max,
"The maximum number of threads in the worker pool.\n"
- DELAYED_EFFECT
- "Default is no limit.", "-1" },
+ "-1 is unlimited.\n"
+ DELAYED_EFFECT,
+ "-1", "threads" },
{ "thread_pool_min", tweak_thread_pool_min,
"The minimum number of threads in the worker pool.\n"
DELAYED_EFFECT
- "Default is 1 thread. "
- "Minimum is 1 thread. ", "1" },
+ "Minimum is 1 thread. ",
+ "1", "threads" },
{ "thread_pool_timeout", tweak_thread_pool_timeout,
"Thread dies after this many seconds of inactivity.\n"
- "Default is 120 seconds. "
- "Minimum is 1 second. ", "120" },
+ "Minimum is 1 second. ",
+ "120", "seconds" },
{ "http_workspace", tweak_http_workspace,
"Bytes of HTTP protocol workspace allocated. "
"This space must be big enough for the entire HTTP protocol "
"header and any edits done to it in the VCL code.\n"
SHOULD_RESTART
- "Default is 8192 bytes. "
- "Minimum is 1024 bytes. ", "8192" },
+ "Minimum is 1024 bytes. ",
+ "8192", "bytes" },
{ "sess_timeout", tweak_sess_timeout,
"Idle timeout for persistent sessions. "
"If a HTTP request has not been received in this many "
- "seconds, the session is closed.\n"
- "Default is 5 seconds. ", "5" },
+ "seconds, the session is closed.\n",
+ "5", "seconds" },
{ "pipe_timeout", tweak_pipe_timeout,
"Idle timeout for PIPE sessions. "
"If nothing have been received in either directoin for "
- "this many seconds, the session is closed.\n"
- "Default is 60 seconds. ", "60" },
+ "this many seconds, the session is closed.\n",
+ "60", "seconds" },
{ "send_timeout", tweak_send_timeout,
"Send timeout for client connections. "
"If no data has been sent to the client in this many seconds, "
"the session is closed.\n"
DELAYED_EFFECT
- "See getopt(3) under SO_SNDTIMEO for more information.\n"
- "Default is 600 seconds. ", "600" },
+ "See getopt(3) under SO_SNDTIMEO for more information.\n",
+ "600", "seconds" },
{ "auto_restart", tweak_auto_restart,
- "Restart child process automatically if it dies. "
- "1 = yes, 0 = no.\n"
- "Default is 1. ", "1" },
+ "Restart child process automatically if it dies.\n"
+ "Minimum is 4 kilobytes.\n",
+ "on", "bool" },
{ "fetch_chunksize", tweak_fetch_chunksize,
- "The default chunksize used by fetcher.\n"
- "Default is 128 kilobytes. ", "128" },
+ "The default chunksize used by fetcher.\n",
+ "128", "kilobytes" },
#ifdef HAVE_SENDFILE
{ "sendfile_threshold", tweak_sendfile_threshold,
- "The minimum size of objects transmitted with sendfile.\n"
- "Default is 8192 bytes.", "8192" },
+ "The minimum size of objects transmitted with sendfile.\n",
+ "8192", "bytes" },
#endif /* HAVE_SENDFILE */
{ "vcl_trace", tweak_vcl_trace,
- "Trace VCL execution in the shmlog\n"
- "Default is off", "off" },
+ "Trace VCL execution in the shmlog\n",
+ "off", "bool" },
{ "listen_address", tweak_listen_address,
"The network address/port where Varnish services requests.\n"
- MUST_RESTART
- "Default is \"0.0.0.0:80\"", "0.0.0.0:80" },
+ MUST_RESTART,
+ "0.0.0.0:80" },
+ { "listen_depth", tweak_listen_depth,
+ "Listen(2) queue depth.\n"
+ MUST_RESTART,
+ "1024", "connections" },
{ NULL, NULL, NULL }
};
continue;
}
pp->func(cli, pp, NULL);
+ if (pp->units != NULL)
+ cli_out(cli, " [%s]\n", pp->units);
+ else
+ cli_out(cli, "\n");
if (av[2] != NULL) {
+ cli_out(cli, "%-20s Default is %s\n", "", pp->def);
/* Format text to 72 col width */
for (p = pp->expl; *p != '\0'; ) {
q = strchr(p, '\n');
{
struct parspec *pp;
- for (pp = parspec; pp->name != NULL; pp++)
+ for (pp = parspec; pp->name != NULL; pp++) {
+ cli_out(cli, "Set Default for %s = %s\n", pp->name, pp->def);
pp->func(cli, pp, pp->def);
+ if (cli->result != CLIS_OK)
+ return;
+ }
}