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:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user