[tor-commits] [tor/master] config: Log the option name when skipping an obsolete option

teor at torproject.org teor at torproject.org
Tue Nov 12 00:11:54 UTC 2019


commit 2ee04fc309b8f4fb3c34271587ab47addaff32ae
Author: teor <teor at torproject.org>
Date:   Mon Nov 11 11:59:50 2019 +1000

    config: Log the option name when skipping an obsolete option
    
    This is a basic fix for 0.4.2 only. The fix for 0.4.3 and later
    is in 32404.
    
    Fixes bug 32295; bugfix on 0.4.2.1-alpha.
---
 changes/bug32295                  |  3 +++
 src/lib/confmgt/type_defs.c       | 39 ++++++++++++++++++++++++++-------------
 src/lib/confmgt/typedvar.c        | 11 ++++++-----
 src/lib/confmgt/typedvar.h        |  2 +-
 src/lib/confmgt/var_type_def_st.h |  5 ++++-
 5 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/changes/bug32295 b/changes/bug32295
new file mode 100644
index 000000000..e5e5a4399
--- /dev/null
+++ b/changes/bug32295
@@ -0,0 +1,3 @@
+  o Minor bugfixes (configuration):
+    - Log the option name when skipping an obsolete option.
+      Fixes bug 32295; bugfix on 0.4.2.1-alpha.
diff --git a/src/lib/confmgt/type_defs.c b/src/lib/confmgt/type_defs.c
index ed930fb02..5066e1226 100644
--- a/src/lib/confmgt/type_defs.c
+++ b/src/lib/confmgt/type_defs.c
@@ -52,10 +52,11 @@
 
 static int
 string_parse(void *target, const char *value, char **errmsg,
-             const void *params)
+             const void *params, const char *key)
 {
   (void)params;
   (void)errmsg;
+  (void)key;
   char **p = (char**)target;
   *p = tor_strdup(value);
   return 0;
@@ -106,8 +107,10 @@ static const int_parse_params_t INT_PARSE_POSINT = {
 };
 
 static int
-int_parse(void *target, const char *value, char **errmsg, const void *params)
+int_parse(void *target, const char *value, char **errmsg, const void *params,
+          const char *key)
 {
+  (void)key;
   const int_parse_params_t *pp;
   if (params) {
     pp = params;
@@ -169,10 +172,11 @@ static const var_type_fns_t int_fns = {
 
 static int
 uint64_parse(void *target, const char *value, char **errmsg,
-             const void *params)
+             const void *params, const char *key)
 {
   (void)params;
   (void)errmsg;
+  (void)key;
   uint64_t *p = target;
   int ok=0;
   *p = tor_parse_uint64(value, 10, 0, UINT64_MAX, &ok, NULL);
@@ -219,8 +223,9 @@ static const var_type_fns_t uint64_fns = {
 
 static int
 units_parse_u64(void *target, const char *value, char **errmsg,
-                const void *params)
+                const void *params, const char *key)
 {
+  (void)key;
   const unit_table_t *table = params;
   tor_assert(table);
   uint64_t *v = (uint64_t*)target;
@@ -235,8 +240,9 @@ units_parse_u64(void *target, const char *value, char **errmsg,
 
 static int
 units_parse_int(void *target, const char *value, char **errmsg,
-               const void *params)
+                const void *params, const char *key)
 {
+  (void)key;
   const unit_table_t *table = params;
   tor_assert(table);
   int *v = (int*)target;
@@ -283,10 +289,11 @@ static const var_type_fns_t interval_fns = {
 
 static int
 double_parse(void *target, const char *value, char **errmsg,
-             const void *params)
+             const void *params, const char *key)
 {
   (void)params;
   (void)errmsg;
+  (void)key;
   double *v = (double*)target;
   char *endptr=NULL;
   errno = 0;
@@ -347,8 +354,9 @@ typedef struct enumeration_table_t {
 
 static int
 enum_parse(void *target, const char *value, char **errmsg,
-           const void *params)
+           const void *params, const char *key)
 {
+  (void)key;
   const enumeration_table_t *table = params;
   int *p = (int *)target;
   for (; table->name; ++table) {
@@ -422,9 +430,10 @@ static const var_type_fns_t enum_fns = {
 
 static int
 time_parse(void *target, const char *value, char **errmsg,
-           const void *params)
+           const void *params, const char *key)
 {
   (void) params;
+  (void) key;
   time_t *p = target;
   if (parse_iso_time(value, p) < 0) {
     tor_asprintf(errmsg, "Invalid time %s", escaped(value));
@@ -466,10 +475,11 @@ static const var_type_fns_t time_fns = {
 
 static int
 csv_parse(void *target, const char *value, char **errmsg,
-          const void *params)
+          const void *params, const char *key)
 {
   (void)params;
   (void)errmsg;
+  (void)key;
   smartlist_t **sl = (smartlist_t**)target;
   *sl = smartlist_new();
   smartlist_split_string(*sl, value, ",",
@@ -515,7 +525,7 @@ static const var_type_fns_t csv_fns = {
 
 static int
 legacy_csv_interval_parse(void *target, const char *value, char **errmsg,
-                          const void *params)
+                          const void *params, const char *key)
 {
   (void)params;
   /* We used to have entire smartlists here.  But now that all of our
@@ -529,7 +539,7 @@ legacy_csv_interval_parse(void *target, const char *value, char **errmsg,
     val = tmp;
   }
 
-  int rv = units_parse_int(target, val, errmsg, &time_units);
+  int rv = units_parse_int(target, val, errmsg, &time_units, key);
   tor_free(tmp);
   return rv;
 }
@@ -693,14 +703,17 @@ static const var_type_fns_t linelist_s_fns = {
 
 static int
 ignore_parse(void *target, const char *value, char **errmsg,
-             const void *params)
+             const void *params, const char *key)
 {
   (void)target;
   (void)value;
   (void)errmsg;
   (void)params;
   // XXXX move this to a higher level, once such a level exists.
-  log_warn(LD_GENERAL, "Skipping obsolete configuration option.");
+  log_warn(LD_GENERAL, "Skipping obsolete configuration option%s%s%s",
+           key && *key ? " \"" : "",
+           key && *key ? key : "",
+           key && *key ? "\"." : ".");
   return 0;
 }
 
diff --git a/src/lib/confmgt/typedvar.c b/src/lib/confmgt/typedvar.c
index 219a2d15b..ce11a6937 100644
--- a/src/lib/confmgt/typedvar.c
+++ b/src/lib/confmgt/typedvar.c
@@ -33,7 +33,8 @@
 
 /**
  * Try to parse a string in <b>value</b> that encodes an object of the type
- * defined by <b>def</b>.
+ * defined by <b>def</b>. If not NULL, <b>key</b> is the name of the option,
+ * which may be used for logging.
  *
  * On success, adjust the lvalue pointed to by <b>target</b> to hold that
  * value, and return 0.  On failure, set *<b>errmsg</b> to a newly allocated
@@ -41,7 +42,7 @@
  **/
 int
 typed_var_assign(void *target, const char *value, char **errmsg,
-                    const var_type_def_t *def)
+                 const var_type_def_t *def, const char *key)
 {
   if (BUG(!def))
     return -1; // LCOV_EXCL_LINE
@@ -49,7 +50,7 @@ typed_var_assign(void *target, const char *value, char **errmsg,
   typed_var_free(target, def);
 
   tor_assert(def->fns->parse);
-  return def->fns->parse(target, value, errmsg, def->params);
+  return def->fns->parse(target, value, errmsg, def->params, key);
 }
 
 /**
@@ -75,7 +76,7 @@ typed_var_kvassign(void *target, const config_line_t *line,
     return def->fns->kv_parse(target, line, errmsg, def->params);
   }
 
-  return typed_var_assign(target, line->value, errmsg, def);
+  return typed_var_assign(target, line->value, errmsg, def, line->key);
 }
 
 /**
@@ -158,7 +159,7 @@ typed_var_copy(void *dest, const void *src, const var_type_def_t *def)
     return 0;
   }
   char *err = NULL;
-  int rv = typed_var_assign(dest, enc, &err, def);
+  int rv = typed_var_assign(dest, enc, &err, def, NULL);
   if (BUG(rv < 0)) {
     // LCOV_EXCL_START
     log_warn(LD_BUG, "Encoded value %s was not parseable as a %s: %s",
diff --git a/src/lib/confmgt/typedvar.h b/src/lib/confmgt/typedvar.h
index 22f2e3c58..438261383 100644
--- a/src/lib/confmgt/typedvar.h
+++ b/src/lib/confmgt/typedvar.h
@@ -21,7 +21,7 @@ typedef struct var_type_fns_t var_type_fns_t;
 typedef struct var_type_def_t var_type_def_t;
 
 int typed_var_assign(void *target, const char *value, char **errmsg,
-                        const var_type_def_t *def);
+                     const var_type_def_t *def, const char *key);
 void typed_var_free(void *target, const var_type_def_t *def);
 char *typed_var_encode(const void *value, const var_type_def_t *def);
 int typed_var_copy(void *dest, const void *src, const var_type_def_t *def);
diff --git a/src/lib/confmgt/var_type_def_st.h b/src/lib/confmgt/var_type_def_st.h
index 2bf3d37ca..aa9ded39e 100644
--- a/src/lib/confmgt/var_type_def_st.h
+++ b/src/lib/confmgt/var_type_def_st.h
@@ -52,9 +52,12 @@ struct var_type_fns_t {
    * type.  On success, adjust the lvalue pointed to by <b>target</b> to hold
    * that value, and return 0.  On failure, set *<b>errmsg</b> to a newly
    * allocated string holding an error message, and return -1.
+   *
+   * If not NULL, <b>key</b> is the name of the option, which may be used for
+   * logging.
    **/
   int (*parse)(void *target, const char *value, char **errmsg,
-               const void *params);
+               const void *params, const char *key);
   /**
    * Try to parse a single line from the head of<b>line</b> that encodes
    * an object of this type.  On success and failure, behave as in the parse()





More information about the tor-commits mailing list