dns: minor refactoring in _collect_resolv_conf_data()

The code was correct previously, but it was confusing to me,
because

  - once @skip gets set to TRUE, it stays TRUE for the rest
    of the loop.
  - in each additional skipped iteration, it would still set
    plugin_confs[i] to NULL. Which is not wrong, but confusing.
  - it would set "prev_prio = prio;" in each iteration.
    After @skip is set to TRUE, that doesn't matter anymore,
    but is confusing. Before @skip is set to TRUE it also
    doesn't really matter to set it more then once, because
    we only care about the very first priority.
  - @skip sounded to me like the current iteration would
    be skipped. But really all remaining will be skipped too.
This commit is contained in:
Thomas Haller 2017-06-13 23:58:57 +02:00
parent f71195b102
commit aa347182bb

View file

@ -994,7 +994,7 @@ _collect_resolv_conf_data (NMDnsManager *self, /* only for logging context, no o
NMDnsIPConfigData ***out_plugin_confs)
{
NMDnsIPConfigData **plugin_confs = NULL;
guint i, num, len;
guint i, j, num, len;
NMResolvConfData rc = {
.nameservers = g_ptr_array_new (),
.searches = g_ptr_array_new (),
@ -1007,26 +1007,26 @@ _collect_resolv_conf_data (NMDnsManager *self, /* only for logging context, no o
merge_global_dns_config (&rc, global_config);
else {
nm_auto_free_gstring GString *tmp_gstring = NULL;
int prio, prev_prio = 0;
int prio, first_prio = 0;
NMDnsIPConfigData *current;
gboolean skip = FALSE, v4;
gboolean v4;
plugin_confs = g_new (NMDnsIPConfigData *, configs->len + 1);
for (i = 0; i < configs->len; i++) {
for (i = 0, j = 0; i < configs->len; i++) {
gboolean skip = FALSE;
current = configs->pdata[i];
v4 = NM_IS_IP4_CONFIG (current->config);
prio = v4 ?
nm_ip4_config_get_dns_priority ((NMIP4Config *) current->config) :
nm_ip6_config_get_dns_priority ((NMIP6Config *) current->config);
prio = v4
? nm_ip4_config_get_dns_priority ((NMIP4Config *) current->config)
: nm_ip6_config_get_dns_priority ((NMIP6Config *) current->config);
if (prev_prio < 0 && prio != prev_prio) {
if (i == 0)
first_prio = prio;
else if (first_prio < 0 && first_prio != prio)
skip = TRUE;
plugin_confs[i] = NULL;
}
prev_prio = prio;
if ( ( v4 && nm_ip4_config_get_num_nameservers ((NMIP4Config *) current->config))
|| (!v4 && nm_ip6_config_get_num_nameservers ((NMIP6Config *) current->config))) {
@ -1041,10 +1041,10 @@ _collect_resolv_conf_data (NMDnsManager *self, /* only for logging context, no o
if (!skip) {
merge_one_ip_config_data (&rc, current);
plugin_confs[i] = current;
plugin_confs[j++] = current;
}
}
plugin_confs[i] = NULL;
plugin_confs[j++] = NULL;
}
/* If the hostname is a FQDN ("dcbw.example.com"), then add the domain part of it