MXS-1929: Add config dump helper functions

The functions dump of parameters only if they differ from the
defaults. The check for equality is rather coarse but it should work as
long as all core objects use C++ types correctly e.g. integer are not used
to store boolean values (I'm looking at you, enable_root and
localhost_match_wildcard_host). The boolean type has a specialization to
convert the value to the string format used for all defaults in the core.

This also adds the missing return value checks to the dprintf calls and
reports errors if any are encountered.
This commit is contained in:
Markus Mäkelä
2018-08-13 23:27:35 +03:00
parent 419aefb173
commit 0c2bec9fba
2 changed files with 82 additions and 0 deletions

View File

@ -4666,4 +4666,32 @@ MXS_CONFIG_PARAMETER* ParamList::params()
return m_ctx.parameters;
}
void dump_if_changed(const MXS_MODULE_PARAM* params, int file,
const std::string& key, const std::string& value)
{
for (int i = 0; params[i].name; i++)
{
if (params[i].name == key)
{
/**
* This detects only exact matches, not ones that are logically equivalent
* but lexicographically different e.g. 1 and true. This might not
* be a bad thing: it'll distinct user defined values from defaults.
*/
if (!params[i].default_value || value != params[i].default_value)
{
if (dprintf(file, "%s=%s\n", key.c_str(), value.c_str()) == -1)
{
MXS_ERROR("Failed to serialize service value: %d, %s",
errno, mxs_strerror(errno));
}
}
break;
}
}
}
}