]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Support a flag to indicate that a config var is disabled
authorNick Mathewson <nickm@torproject.org>
Sun, 15 Dec 2019 23:40:12 +0000 (18:40 -0500)
committerNick Mathewson <nickm@torproject.org>
Thu, 19 Dec 2019 12:54:56 +0000 (07:54 -0500)
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
src/lib/conf/conftypes.h
src/lib/confmgt/confmgt.c

index 064ab324f861db84a7244d2d30fe62b6a58f8bd7..723aea18781c7d828356562aa12d543ede5eeeba 100644 (file)
    .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.
index 19ea997316ca3c4e7925ca6676544a49208515ed..44171068a1cfda02f939b0a79f63e0cb21778a88 100644 (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
index c72efa847c8d3cbe2425a8ed6a3a6bce3e20cb0f..eaa4468d55f14d1933a56a0cd6d49e56da5f6497 100644 (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);