This should us to work around the packaging issues discussed in #13935.
THe idea is that modify the parsing so that .conf files also *may* contain YAML.
The search for a config file then becomes:
1. Try read recuror.yml if it exists. If valid, done. If it is invalid punt.
2. Try read recursor.conf as YAML. If it is valid, done.
3. If it is invalid, try to read as old-style.
This means that the status of recursor.conf as a config file does not change.
This allows us to install a default YAML config into recursor.conf for new installs.
Of course we leave recursor.conf (and recursor.yml) alone for existing installs.
This is a draft. I will add docs and packaging changes after this is deemed
the way to proceed.
RecursorControlChannel g_rcc; // only active in the handler thread
bool g_regressionTestMode;
bool g_yamlSettings;
+string g_yamlSettingsSuffix;
bool g_luaSettingsInYAML;
#ifdef NOD_ENABLED
cleanSlashes(configName);
if (g_yamlSettings) {
- configName += ".yml";
+ configName += g_yamlSettingsSuffix;
string msg;
pdns::rust::settings::rec::Recursorsettings settings;
// XXX Does ::arg()["include-dir"] have the right value, i.e. potentially overriden by command line?
::arg().setSLog(startupLog);
- const string yamlconfigname = configname + ".yml";
+ string yamlconfigname;
pdns::rust::settings::rec::Recursorsettings settings;
- auto yamlstatus = pdns::settings::rec::tryReadYAML(yamlconfigname, true, g_yamlSettings, g_luaSettingsInYAML, settings, startupLog);
- if (yamlstatus == pdns::settings::rec::PresentButFailed) {
- return 1;
+ pdns::settings::rec::YamlSettingsStatus yamlstatus{};
+
+ for (const string suffix : {".yml", ".conf"}) {
+ yamlconfigname = configname + suffix;
+ yamlstatus = pdns::settings::rec::tryReadYAML(yamlconfigname, true, g_yamlSettings, g_luaSettingsInYAML, settings, startupLog);
+ if (yamlstatus == pdns::settings::rec::YamlSettingsStatus::OK) {
+ g_yamlSettingsSuffix = suffix;
+ break;
+ }
+ if (suffix == ".yml" && yamlstatus == pdns::settings::rec::PresentButFailed) {
+ return 1;
+ }
}
if (g_yamlSettings) {
auto lock = g_yamlStruct.lock();
*lock = std::move(settings);
}
- if (yamlstatus == pdns::settings::rec::YamlSettingsStatus::CannotOpen) {
+ else {
configname += ".conf";
+ startupLog->info(Logr::Warning, "Trying to read YAML from .yml or .conf failed, failing back to old-style config read", "configname", Logging::Loggable(configname));
bool mustExit = false;
std::tie(ret, mustExit) = doConfig(startupLog, configname, argc, argv);
if (ret != 0 || mustExit) {
using RemoteLoggerStats_t = std::unordered_map<std::string, RemoteLoggerInterface::Stats>;
extern bool g_yamlSettings;
+extern string g_yamlSettingsSuffix;
extern bool g_logCommonErrors;
extern size_t g_proxyProtocolMaximumSize;
extern std::atomic<bool> g_quiet;
cleanSlashes(configname);
- const string yamlconfigname = configname + ".yml";
string msg;
pdns::rust::settings::rec::Recursorsettings settings;
-
- auto yamlstatus = pdns::settings::rec::readYamlSettings(yamlconfigname, "", settings, msg, g_slog);
-
- switch (yamlstatus) {
- case pdns::settings::rec::YamlSettingsStatus::CannotOpen:
- break;
- case pdns::settings::rec::YamlSettingsStatus::PresentButFailed:
- log->error(Logr::Error, msg, "YAML config found, but error ocurred processing it", "configname", Logging::Loggable(yamlconfigname));
- exit(1); // NOLINT(concurrency-mt-unsafe)
- break;
- case pdns::settings::rec::YamlSettingsStatus::OK:
- log->info(Logr::Notice, "YAML config found and processed", "configname", Logging::Loggable(yamlconfigname));
- pdns::settings::rec::bridgeStructToOldStyleSettings(settings);
- break;
+ pdns::settings::rec::YamlSettingsStatus yamlstatus{};
+
+ for (const string suffix : {".yml", ".conf"}) {
+ const string yamlconfigname = configname + suffix;
+ yamlstatus = pdns::settings::rec::readYamlSettings(yamlconfigname, "", settings, msg, g_slog);
+
+ switch (yamlstatus) {
+ case pdns::settings::rec::YamlSettingsStatus::CannotOpen:
+ break;
+ case pdns::settings::rec::YamlSettingsStatus::PresentButFailed:
+ if (suffix == ".yml") {
+ log->error(Logr::Error, msg, "YAML config found, but error ocurred processing it", "configname", Logging::Loggable(yamlconfigname));
+ exit(1); // NOLINT(concurrency-mt-unsafe)
+ }
+ break;
+ case pdns::settings::rec::YamlSettingsStatus::OK:
+ log->info(Logr::Notice, "YAML config found and processed", "configname", Logging::Loggable(yamlconfigname));
+ pdns::settings::rec::bridgeStructToOldStyleSettings(settings);
+ break;
+ }
+ if (yamlstatus == pdns::settings::rec::YamlSettingsStatus::OK) {
+ break;
+ }
}
-
- if (yamlstatus == pdns::settings::rec::YamlSettingsStatus::CannotOpen) {
+ if (yamlstatus != pdns::settings::rec::YamlSettingsStatus::OK) {
configname += ".conf";
arg().laxFile(configname);
}
#include "settings/cxxsettings.hh"
#include "rec-system-resolve.hh"
+// XXX consider including rec-main.hh?
extern int g_argc;
extern char** g_argv;
+extern string g_yamlSettingsSuffix;
bool primeHints(time_t now)
{
log->info(Logr::Notice, "Reloading zones, purging data from cache"));
if (yaml) {
- configname += ".yml";
+ configname += g_yamlSettingsSuffix;
string msg;
pdns::rust::settings::rec::Recursorsettings settings;
// XXX Does ::arg()["include-dir"] have the right value, i.e. potentially overriden by command line?