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.
This commit is contained in:
teor 2019-11-11 11:59:50 +10:00
parent a920597f62
commit 2ee04fc309
No known key found for this signature in database
GPG Key ID: 10FEAA0E7075672A
5 changed files with 40 additions and 20 deletions

3
changes/bug32295 Normal file
View File

@ -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.

View File

@ -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;
}

View File

@ -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",

View File

@ -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);

View File

@ -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()