From b53ec372864cea412505327012cc46dc06dec366 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Mon, 3 Mar 2014 12:34:11 +0100 Subject: config: add CFG_DEFAULT_RUN_TIME for config options with runtime defaults Previously, we declared a default value as undefined ("NULL") for settings which require runtime context to be set first (e.g. settings for paths that rely on SYSTEM_DIR environment variable or they depend on any other setting in some way). If we want to output default values as they are really used in runtime, we should make it possible to define a default value as function which is evaluated, not just providing a firm constant value as it was before. This patch defines simple prototypes for such functions. Also, there's new helper macros "cfg_runtime" and "cfg_array_runtime" - they provide exactly the same functionality as the original "cfg" and "cfg_array" macros when defining the configuration settings in config_settings.h, but they don't set the constant default value. Instead, they automatically link the configuration setting definition with one of these functions: typedef int (*t_fn_CFG_TYPE_BOOL) (struct cmd_context *cmd, struct profile *profile); typedef int (*t_fn_CFG_TYPE_INT) (struct cmd_context *cmd, struct profile *profile); typedef float (*t_fn_CFG_TYPE_FLOAT) (struct cmd_context *cmd, struct profile *profile); typedef const char* (*t_fn_CFG_TYPE_STRING) (struct cmd_context *cmd, struct profile *profile); typedef const char* (*t_fn_CFG_TYPE_ARRAY) (struct cmd_context *cmd, struct profile *profile); (The new macros actually set the CFG_DEFAULT_RUNTIME flag properly and set the default value link to the function accordingly). Then such configuration setting requires a function of selected type to be defined. This function has a predefined name: get_default_ ...where the is the id of the setting as defined in config_settings.h. For example "backup_archive_dir_CFG" if defined as a setting with default value evaluated in runtime with "cfg_runtime" will automatically have "get_default_backup_archive_dir_CFG" function linked to this setting to get the default value. --- tools/dumpconfig.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tools') diff --git a/tools/dumpconfig.c b/tools/dumpconfig.c index cb88bc646..dd8673389 100644 --- a/tools/dumpconfig.c +++ b/tools/dumpconfig.c @@ -97,6 +97,8 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv) struct cft_check_handle *cft_check_handle = NULL; int r = ECMD_PROCESSED; + tree_spec.cmd = cmd; + if (arg_count(cmd, configtype_ARG) && arg_count(cmd, validate_ARG)) { log_error("Only one of --type and --validate permitted."); return EINVALID_CMD_LINE; -- cgit v1.2.1