Support a flag to indicate that a config var is disabled

Like "obsolete" variables, these variables produce a warning when
you try to set them, but the warning says that the relevant module
doesn't have support.

The confdecl macros now have a CONF_CONTEXT that you can define to
make all the modules in a given table disabled.
This commit is contained in:
Nick Mathewson 2019-12-15 18:40:12 -05:00
parent 5e2318165d
commit 9082a6db3f
3 changed files with 37 additions and 0 deletions

View File

@ -135,6 +135,28 @@
.initvalue = initval \
},
/**@}*/
/* @defgroup STUB_TABLE_MACROS Internal macros: stub table declarations,
* for use when a module is disabled.
* Implementation helpers: the regular confdecl macros expand to these
* when CONF_CONTEXT is defined to LL_TABLE. Don't use them directly.
* @{*/
#define BEGIN_CONF_STRUCT__STUB_TABLE(structname) \
static const config_var_t structname##_vars[] = {
#define END_CONF_STRUCT__STUB_TABLE(structname) \
{ .member = { .name = NULL } } \
};
#define CONF_VAR__STUB_TABLE(varname, vartype, varflags, initval) \
{ \
.member = \
{ .name = #varname, \
.type = CONFIG_TYPE_IGNORE, \
.offset = -1, \
}, \
.flags = CFLG_GROUP_DISABLED, \
},
/**@}*/
#endif /* !defined(COCCI) */
/** Type aliases for the "commonly used" configuration types.

View File

@ -199,6 +199,11 @@ typedef struct struct_magic_decl_t {
* whenever the user tries to use it.
**/
#define CFLG_WARN_OBSOLETE (1u<<7)
/**
* Flag to indicate that we should warn that an option applies only to
* a disabled module, whenever the user tries to use it.
**/
#define CFLG_WARN_DISABLED (1u<<8)
/**
* A group of flags that should be set on all obsolete options and types.
@ -207,6 +212,13 @@ typedef struct struct_magic_decl_t {
(CFLG_NOCOPY|CFLG_NOCMP|CFLG_NODUMP|CFLG_NOSET|CFLG_NOLIST|\
CFLG_WARN_OBSOLETE)
/**
* A group of fflags that should be set on all disabled options.
**/
#define CFLG_GROUP_DISABLED \
(CFLG_NOCOPY|CFLG_NOCMP|CFLG_NODUMP|CFLG_NOSET|CFLG_NOLIST|\
CFLG_WARN_DISABLED)
/** A variable allowed in the configuration file or on the command line. */
typedef struct config_var_t {
struct_member_t member; /** A struct member corresponding to this

View File

@ -660,6 +660,9 @@ config_assign_value(const config_mgr_t *mgr, void *options,
if (config_var_has_flag(var->cvar, CFLG_WARN_OBSOLETE)) {
log_warn(LD_GENERAL, "Skipping obsolete configuration option \"%s\".",
var->cvar->member.name);
} else if (config_var_has_flag(var->cvar, CFLG_WARN_DISABLED)) {
log_warn(LD_GENERAL, "This copy of Tor was built without support for "
"the option \"%s\". Skipping.", var->cvar->member.name);
}
return struct_var_kvassign(object, c, msg, &var->cvar->member);