* The pair created by this function should fed to #cf_pair_parse for parsing.
*
* @param[out] out Where to write the CONF_PAIR we created with the default value.
+ * @param[in] parent being populated.
* @param[in] cs to parent the CONF_PAIR from.
* @param[in] rule to use to create the default.
* @return
* - 0 on success.
* - -1 on failure.
*/
-static int cf_pair_default(CONF_PAIR **out, CONF_SECTION *cs, CONF_PARSER const *rule)
+static int cf_pair_default(CONF_PAIR **out, void *parent, CONF_SECTION *cs, CONF_PARSER const *rule)
{
int lineno = 0;
* Use the dynamic default function if set
*/
if (rule->dflt_func) {
- if (rule->dflt_func(out, cs, dflt_quote, rule) < 0) {
+ if (rule->dflt_func(out, parent, cs, dflt_quote, rule) < 0) {
cf_log_perr(cs, "Failed producing default for \"%s\"", rule->name);
return -1;
}
return 1;
}
- if (cf_pair_default(&dflt_cp, cs, rule) < 0) return -1;
+ if (cf_pair_default(&dflt_cp, base, cs, rule) < 0) return -1;
count = cf_pair_count(cs, rule->name); /* Dynamic functions can add multiple defaults */
if (!count) {
if (fr_rule_not_empty(rule)) {
return 1;
}
- if (cf_pair_default(&dflt_cp, cs, rule) < 0) return -1;
+ if (cf_pair_default(&dflt_cp, base, cs, rule) < 0) return -1;
cp = dflt_cp;
if (!cp) {
if (fr_rule_not_empty(rule)) {
* @copyright 2002,2006-2007 The FreeRADIUS server project
* @copyright 2002 Alan DeKok (aland@freeradius.org)
*/
-#include "lib/unlang/xlat.h"
+
RCSID("$Id$")
#include <freeradius-devel/server/cf_file.h>
+#include <freeradius-devel/server/cf_util.h>
#include <freeradius-devel/server/client.h>
#include <freeradius-devel/server/cond.h>
#include <freeradius-devel/server/dependency.h>
#include <freeradius-devel/server/util.h>
#include <freeradius-devel/server/virtual_servers.h>
+#include <freeradius-devel/unlang/xlat.h>
+
#include <freeradius-devel/util/conf.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/dict.h>
#include <freeradius-devel/util/hw.h>
#include <freeradius-devel/util/perm.h>
#include <freeradius-devel/util/sem.h>
+#include <freeradius-devel/util/token.h>
#include <freeradius-devel/unlang/xlat_func.h>
static int num_networks_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, CONF_PARSER const *rule);
static int num_workers_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, CONF_PARSER const *rule);
+static int num_workers_dflt(CONF_PAIR **out, void *parent, CONF_SECTION *cs, fr_token_t quote, CONF_PARSER const *rule);
+
static int lib_dir_on_read(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, CONF_PARSER const *rule);
static int talloc_pool_size_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, CONF_PARSER const *rule);
{ FR_CONF_OFFSET("num_networks", FR_TYPE_UINT32, main_config_t, max_networks), .dflt = STRINGIFY(1),
.func = num_networks_parse },
{ FR_CONF_OFFSET("num_workers", FR_TYPE_UINT32, main_config_t, max_workers), .dflt = STRINGIFY(0),
- .func = num_workers_parse },
+ .func = num_workers_parse, .dflt_func = num_workers_dflt },
{ FR_CONF_OFFSET("stats_interval", FR_TYPE_TIME_DELTA | FR_TYPE_HIDDEN, main_config_t, stats_interval), },
return 0;
}
-static int num_workers_parse(TALLOC_CTX *ctx, void *out, void *parent,
- CONF_ITEM *ci, CONF_PARSER const *rule)
+static int num_workers_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, CONF_PARSER const *rule)
{
int ret;
uint32_t value;
- main_config_t *conf = parent;
if ((ret = cf_pair_parse_value(ctx, out, parent, ci, rule)) < 0) return ret;
memcpy(&value, out, sizeof(value));
+ fr_assert_msg(value != 0, "Number of workers should never be zero, verify num_workers_dflt called");
+
/*
* If no value is specified, try and
* discover it automatically.
*/
- if (value == 0) {
- char *strvalue;
+ FR_INTEGER_BOUND_CHECK("thread.num_workers", value, >=, 1);
+ FR_INTEGER_BOUND_CHECK("thread.num_workers", value, <=, 128);
- value = fr_hw_num_cores_active();
+ memcpy(out, &value, sizeof(value));
- /*
- * If we've got more than four times
- * the number of cores as we have
- * networks, then set the number of
- * workers to the number of cores
- * minus networks.
- *
- * This ensures at a least a 4:1
- * ratio of workers to networks,
- * which seems like a sensible ratio.
- */
- if ((conf->max_networks * 4) < value) {
- value -= conf->max_networks;
- }
+ return 0;
+}
+
+static int num_workers_dflt(CONF_PAIR **out, void *parent, CONF_SECTION *cs, fr_token_t quote, CONF_PARSER const *rule)
+{
+ char *strvalue;
+ uint32_t value;
+ main_config_t *conf = parent;
- strvalue = talloc_asprintf(ci, "%u", value);
- (void) cf_pair_replace(cf_item_to_section(cf_parent(ci)), cf_item_to_pair(ci), strvalue);
- talloc_free(strvalue);
+ value = fr_hw_num_cores_active();
- /*
- * Otherwise just create as many
- * workers as we have cores.
- */
- cf_log_info(ci, "Setting thread.workers = %u", value);
- } else {
- FR_INTEGER_BOUND_CHECK("thread.num_workers", value, >=, 1);
- FR_INTEGER_BOUND_CHECK("thread.num_workers", value, <=, 128);
+ /*
+ * If we've got more than four times
+ * the number of cores as we have
+ * networks, then set the number of
+ * workers to the number of cores
+ * minus networks.
+ *
+ * This ensures at a least a 4:1
+ * ratio of workers to networks,
+ * which seems like a sensible ratio.
+ */
+ if ((conf->max_networks * 4) < value) {
+ value -= conf->max_networks;
}
+ strvalue = talloc_asprintf(NULL, "%u", value);
+ *out = cf_pair_alloc(cs, rule->name, strvalue, T_OP_EQ, T_BARE_WORD, quote);
+ talloc_free(strvalue);
- memcpy(out, &value, sizeof(value));
+ /*
+ * Otherwise just create as many
+ * workers as we have cores.
+ */
+ cf_log_info(cs, "Dynamically determined thread.workers = %u", value);
return 0;
}
-
static int xlat_config_escape(UNUSED request_t *request, fr_value_box_t *vb, UNUSED void *uctx)
{
static char const disallowed[] = "%{}\\'\"`";