[tor-commits] [tor/master] Support a flag to indicate that a config var is disabled

nickm at torproject.org nickm at torproject.org
Thu Dec 19 12:55:15 UTC 2019


commit 9082a6db3f31c768ba862ed22f0824e99b4e0e22
Author: Nick Mathewson <nickm at torproject.org>
Date:   Sun Dec 15 18:40:12 2019 -0500

    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.
---
 src/lib/conf/confdecl.h   | 22 ++++++++++++++++++++++
 src/lib/conf/conftypes.h  | 12 ++++++++++++
 src/lib/confmgt/confmgt.c |  3 +++
 3 files changed, 37 insertions(+)

diff --git a/src/lib/conf/confdecl.h b/src/lib/conf/confdecl.h
index 064ab324f..723aea187 100644
--- a/src/lib/conf/confdecl.h
+++ b/src/lib/conf/confdecl.h
@@ -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.
diff --git a/src/lib/conf/conftypes.h b/src/lib/conf/conftypes.h
index 19ea99731..44171068a 100644
--- a/src/lib/conf/conftypes.h
+++ b/src/lib/conf/conftypes.h
@@ -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
diff --git a/src/lib/confmgt/confmgt.c b/src/lib/confmgt/confmgt.c
index c72efa847..eaa4468d5 100644
--- a/src/lib/confmgt/confmgt.c
+++ b/src/lib/confmgt/confmgt.c
@@ -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);





More information about the tor-commits mailing list