Merge pull request #1891 from pi-hole/fix/migration_message
Improve config migration logging
This commit is contained in:
commit
93d01d9c5d
|
@ -30,8 +30,8 @@
|
|||
static toml_table_t *parseTOML(const unsigned int version);
|
||||
static void reportDebugFlags(void);
|
||||
|
||||
// Migrate config from old to new, returns true if a restart is required
|
||||
static bool migrate_config(toml_table_t *toml, struct config *newconf)
|
||||
// Migrate dns.revServer -> dns.revServers[0]
|
||||
static bool migrate_dns_revServer(toml_table_t *toml, struct config *newconf)
|
||||
{
|
||||
bool restart = false;
|
||||
toml_table_t *dns = toml_table_in(toml, "dns");
|
||||
|
@ -55,19 +55,48 @@ static bool migrate_config(toml_table_t *toml, struct config *newconf)
|
|||
{
|
||||
// Add to new config
|
||||
sprintf(old, "%s,%s,%s,%s", active.u.s ? "true" : "false", cidr.u.s, target.u.s, domain.u.s);
|
||||
log_debug(DEBUG_CONFIG, "Config setting dns.revServer MIGRATED: %s", old);
|
||||
log_debug(DEBUG_CONFIG, "Config setting dns.revServer MIGRATED to dns.revServers[0]: %s", old);
|
||||
cJSON_AddItemToArray(newconf->dns.revServers.v.json, cJSON_CreateString(old));
|
||||
restart = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
log_warn("Config setting dns.revServer INVALID - ignoring: %s %s %s %s", active.ok ? active.u.s : "NULL", cidr.ok ? cidr.u.s : "NULL", target.ok ? target.u.s : "NULL", domain.ok ? domain.u.s : "NULL");
|
||||
{
|
||||
// Invalid config - ignored but logged in case
|
||||
// the user wants to know and restore it later
|
||||
// manually after fixing whatever the problem is
|
||||
log_warn("Config setting dns.revServer INVALID - ignoring: %s %s %s %s",
|
||||
active.ok ? active.u.s : "NULL",
|
||||
cidr.ok ? cidr.u.s : "NULL",
|
||||
target.ok ? target.u.s : "NULL",
|
||||
domain.ok ? domain.u.s : "NULL");
|
||||
}
|
||||
}
|
||||
else
|
||||
log_info("dns.revServer DOES NOT EXIST");
|
||||
{
|
||||
// Perfectly fine - it just means this old option does
|
||||
// not exist and, hence, does not need to be migrated
|
||||
log_debug(DEBUG_CONFIG, "dns.revServer does not exist - nothing to migrate");
|
||||
}
|
||||
}
|
||||
else
|
||||
log_info("dns DOES NOT EXIST");
|
||||
{
|
||||
// This is actually a problem as the old config file
|
||||
// should always contain a "dns" section
|
||||
log_warn("dns config tab does not exist - config file corrupt or incomplete");
|
||||
}
|
||||
|
||||
return restart;
|
||||
}
|
||||
|
||||
// Migrate config from old to new, returns true if a restart is required to
|
||||
// apply the changes
|
||||
static bool migrate_config(toml_table_t *toml, struct config *newconf)
|
||||
{
|
||||
bool restart = false;
|
||||
|
||||
// Migrate dns.revServer -> dns.revServers[0]
|
||||
restart |= migrate_dns_revServer(toml, newconf);
|
||||
|
||||
return restart;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue