};
static struct params master;
+static int nparspec;
+static struct parspec const ** parspec;
/*--------------------------------------------------------------------*/
free(ta);
}
FreeArgv(av);
- if (cli->result != CLIS_OK) {
+ if (cli != NULL && cli->result != CLIS_OK) {
clean_listen_sock_head(&lsh);
return;
}
* change its default value.
* XXX: we should generate the relevant section of varnishd.1 from here.
*/
-static const struct parspec parspec[] = {
+static const struct parspec input_parspec[] = {
{ "user", tweak_user, NULL, 0, 0,
"The unprivileged user to run as. Setting this will "
"also set \"group\" to the specified user's primary group.",
void
mcf_param_show(struct cli *cli, const char * const *av, void *priv)
{
+ int i;
const struct parspec *pp;
int lfmt;
lfmt = 0;
else
lfmt = 1;
- for (pp = parspec; pp->name != NULL; pp++) {
+ for (i = 0; i < nparspec; i++) {
+ pp = parspec[i];
if (av[2] != NULL && !lfmt && strcmp(pp->name, av[2]))
continue;
cli_out(cli, "%-*s ", margin, pp->name);
void
MCF_ParamSet(struct cli *cli, const char *param, const char *val)
{
+ int i;
const struct parspec *pp;
- for (pp = parspec; pp->name != NULL; pp++) {
+ for (i = 0; i < nparspec; i++) {
+ pp = parspec[i];
if (!strcmp(pp->name, param)) {
pp->func(cli, pp, val);
if (cli->result != CLIS_OK) {
MCF_ParamSet(cli, av[2], av[3]);
}
-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * Add a group of parameters to the global set and sort by name.
+ */
-void
-MCF_ParamInit(struct cli *cli)
+static int
+parspec_cmp(const void *a, const void *b)
+{
+ struct parspec * const * pa = a;
+ struct parspec * const * pb = b;
+ return (strcmp((*pa)->name, (*pb)->name));
+}
+
+static void
+MCF_AddParams(const struct parspec *ps)
{
const struct parspec *pp;
+ int n;
- for (pp = parspec; pp->name != NULL; pp++) {
- cli_out(cli, "Set Default for %s = %s\n", pp->name, pp->def);
+ n = 0;
+ for (pp = ps; pp->name != NULL; pp++) {
if (strlen(pp->name) + 1 > margin)
margin = strlen(pp->name) + 1;
+ n++;
+ }
+ parspec = realloc(parspec, (nparspec + n + 1) * sizeof *parspec);
+ for (pp = ps; pp->name != NULL; pp++)
+ parspec[nparspec++] = pp;
+ parspec[nparspec] = NULL;
+ qsort (parspec, nparspec, sizeof parspec[0], parspec_cmp);
+}
+
+/*--------------------------------------------------------------------
+ * Set defaults for all parameters
+ */
+
+static void
+MCF_SetDefaults(struct cli *cli)
+{
+ const struct parspec *pp;
+ int i;
+
+ for (i = 0; i < nparspec; i++) {
+ pp = parspec[i];
+ if (cli != NULL)
+ cli_out(cli,
+ "Set Default for %s = %s\n", pp->name, pp->def);
pp->func(cli, pp, pp->def);
- if (cli->result != CLIS_OK)
+ if (cli != NULL && cli->result != CLIS_OK)
return;
}
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+MCF_ParamInit(struct cli *cli)
+{
+
+ MCF_AddParams(input_parspec);
+
+ /* XXX: We do this twice, to get past any interdependencies */
+ MCF_SetDefaults(NULL);
+ MCF_SetDefaults(cli);
+
params = &master;
}