dns: don't clone DNS configs list for nm_dns_plugin_update()

No need to clone the list anymore. Unfortunately, GPtrArray is not NULL
terminated (without extra effort), so we have to pass on the GPtrArray
instance for the length.

(cherry picked from commit 19a98c6f61)
This commit is contained in:
Thomas Haller 2017-06-14 11:04:38 +02:00
parent 4c81a447cc
commit 24f4caebec
6 changed files with 16 additions and 26 deletions

View file

@ -554,7 +554,7 @@ start_dnsmasq (NMDnsDnsmasq *self)
static gboolean static gboolean
update (NMDnsPlugin *plugin, update (NMDnsPlugin *plugin,
const NMDnsIPConfigData *const*configs, const GPtrArray *configs,
const NMGlobalDnsConfig *global_config, const NMGlobalDnsConfig *global_config,
const char *hostname) const char *hostname)
{ {
@ -571,13 +571,13 @@ update (NMDnsPlugin *plugin,
if (global_config) if (global_config)
add_global_config (self, &servers, global_config); add_global_config (self, &servers, global_config);
else { else {
for (i = 0; configs[i]; i++) { for (i = 0; i < configs->len; i++) {
prio = nm_dns_ip_config_data_get_dns_priority (configs[i]); prio = nm_dns_ip_config_data_get_dns_priority (configs->pdata[i]);
if (i == 0) if (i == 0)
first_prio = prio; first_prio = prio;
else if (first_prio < 0 && first_prio != prio) else if (first_prio < 0 && first_prio != prio)
break; break;
add_ip_config_data (self, &servers, configs[i]); add_ip_config_data (self, &servers, configs->pdata[i]);
} }
} }

View file

@ -994,10 +994,8 @@ _collect_resolv_conf_data (NMDnsManager *self, /* only for logging context, no o
char ***out_options, char ***out_options,
char ***out_nameservers, char ***out_nameservers,
char ***out_nis_servers, char ***out_nis_servers,
const char **out_nis_domain, const char **out_nis_domain)
NMDnsIPConfigData ***out_plugin_confs)
{ {
NMDnsIPConfigData **plugin_confs = NULL;
guint i, j, num, len; guint i, j, num, len;
NMResolvConfData rc = { NMResolvConfData rc = {
.nameservers = g_ptr_array_new (), .nameservers = g_ptr_array_new (),
@ -1015,8 +1013,6 @@ _collect_resolv_conf_data (NMDnsManager *self, /* only for logging context, no o
NMDnsIPConfigData *current; NMDnsIPConfigData *current;
gboolean v4; gboolean v4;
plugin_confs = g_new (NMDnsIPConfigData *, configs->len + 1);
for (i = 0, j = 0; i < configs->len; i++) { for (i = 0, j = 0; i < configs->len; i++) {
gboolean skip = FALSE; gboolean skip = FALSE;
@ -1043,10 +1039,7 @@ _collect_resolv_conf_data (NMDnsManager *self, /* only for logging context, no o
if (!skip) if (!skip)
merge_one_ip_config_data (&rc, current); merge_one_ip_config_data (&rc, current);
plugin_confs[j++] = current;
} }
plugin_confs[j++] = NULL;
} }
/* If the hostname is a FQDN ("dcbw.example.com"), then add the domain part of it /* If the hostname is a FQDN ("dcbw.example.com"), then add the domain part of it
@ -1080,7 +1073,6 @@ _collect_resolv_conf_data (NMDnsManager *self, /* only for logging context, no o
} }
g_ptr_array_set_size (rc.searches, i); g_ptr_array_set_size (rc.searches, i);
*out_plugin_confs = plugin_confs;
*out_searches = _ptrarray_to_strv (rc.searches); *out_searches = _ptrarray_to_strv (rc.searches);
*out_options = _ptrarray_to_strv (rc.options); *out_options = _ptrarray_to_strv (rc.options);
*out_nameservers = _ptrarray_to_strv (rc.nameservers); *out_nameservers = _ptrarray_to_strv (rc.nameservers);
@ -1104,7 +1096,6 @@ update_dns (NMDnsManager *self,
SpawnResult result = SR_ERROR; SpawnResult result = SR_ERROR;
NMConfigData *data; NMConfigData *data;
NMGlobalDnsConfig *global_config; NMGlobalDnsConfig *global_config;
gs_free NMDnsIPConfigData **plugin_confs = NULL;
g_return_val_if_fail (!error || !*error, FALSE); g_return_val_if_fail (!error || !*error, FALSE);
@ -1138,8 +1129,7 @@ update_dns (NMDnsManager *self,
compute_hash (self, global_config, priv->hash); compute_hash (self, global_config, priv->hash);
_collect_resolv_conf_data (self, global_config, priv->configs, priv->hostname, _collect_resolv_conf_data (self, global_config, priv->configs, priv->hostname,
&searches, &options, &nameservers, &nis_servers, &nis_domain, &searches, &options, &nameservers, &nis_servers, &nis_domain);
&plugin_confs);
/* Let any plugins do their thing first */ /* Let any plugins do their thing first */
if (priv->plugin) { if (priv->plugin) {
@ -1157,7 +1147,7 @@ update_dns (NMDnsManager *self,
_LOGD ("update-dns: updating plugin %s", plugin_name); _LOGD ("update-dns: updating plugin %s", plugin_name);
if (!nm_dns_plugin_update (plugin, if (!nm_dns_plugin_update (plugin,
(const NMDnsIPConfigData **) plugin_confs, priv->configs,
global_config, global_config,
priv->hostname)) { priv->hostname)) {
_LOGW ("update-dns: plugin %s update failed", plugin_name); _LOGW ("update-dns: plugin %s update failed", plugin_name);

View file

@ -77,14 +77,14 @@ G_DEFINE_TYPE_EXTENDED (NMDnsPlugin, nm_dns_plugin, G_TYPE_OBJECT, G_TYPE_FLAG_A
gboolean gboolean
nm_dns_plugin_update (NMDnsPlugin *self, nm_dns_plugin_update (NMDnsPlugin *self,
const NMDnsIPConfigData *const*configs, const GPtrArray *configs,
const NMGlobalDnsConfig *global_config, const NMGlobalDnsConfig *global_config,
const char *hostname) const char *hostname)
{ {
g_return_val_if_fail (NM_DNS_PLUGIN_GET_CLASS (self)->update != NULL, FALSE); g_return_val_if_fail (NM_DNS_PLUGIN_GET_CLASS (self)->update != NULL, FALSE);
return NM_DNS_PLUGIN_GET_CLASS (self)->update (self, return NM_DNS_PLUGIN_GET_CLASS (self)->update (self,
configs ?: NM_PTRARRAY_EMPTY (const NMDnsIPConfigData *), configs,
global_config, global_config,
hostname); hostname);
} }

View file

@ -50,7 +50,7 @@ typedef struct {
* configuration. * configuration.
*/ */
gboolean (*update) (NMDnsPlugin *self, gboolean (*update) (NMDnsPlugin *self,
const NMDnsIPConfigData *const*configs, const GPtrArray *configs,
const NMGlobalDnsConfig *global_config, const NMGlobalDnsConfig *global_config,
const char *hostname); const char *hostname);
@ -80,7 +80,7 @@ gboolean nm_dns_plugin_is_caching (NMDnsPlugin *self);
const char *nm_dns_plugin_get_name (NMDnsPlugin *self); const char *nm_dns_plugin_get_name (NMDnsPlugin *self);
gboolean nm_dns_plugin_update (NMDnsPlugin *self, gboolean nm_dns_plugin_update (NMDnsPlugin *self,
const NMDnsIPConfigData *const*configs, const GPtrArray *configs,
const NMGlobalDnsConfig *global_config, const NMGlobalDnsConfig *global_config,
const char *hostname); const char *hostname);

View file

@ -290,7 +290,7 @@ send_updates (NMDnsSystemdResolved *self)
static gboolean static gboolean
update (NMDnsPlugin *plugin, update (NMDnsPlugin *plugin,
const NMDnsIPConfigData *const*configs, const GPtrArray *configs,
const NMGlobalDnsConfig *global_config, const NMGlobalDnsConfig *global_config,
const char *hostname) const char *hostname)
{ {
@ -299,15 +299,15 @@ update (NMDnsPlugin *plugin,
guint i; guint i;
int prio, first_prio = 0; int prio, first_prio = 0;
for (i = 0; configs[i]; i++) { for (i = 0; i < configs->len; i++) {
gboolean skip = FALSE; gboolean skip = FALSE;
prio = nm_dns_ip_config_data_get_dns_priority (configs[i]); prio = nm_dns_ip_config_data_get_dns_priority (configs->pdata[i]);
if (i == 0) if (i == 0)
first_prio = prio; first_prio = prio;
else if (first_prio < 0 && first_prio != prio) else if (first_prio < 0 && first_prio != prio)
skip = TRUE; skip = TRUE;
add_interface_configuration (self, interfaces, configs[i], skip); add_interface_configuration (self, interfaces, configs->pdata[i], skip);
} }
free_pending_updates (self); free_pending_updates (self);

View file

@ -39,7 +39,7 @@ G_DEFINE_TYPE (NMDnsUnbound, nm_dns_unbound, NM_TYPE_DNS_PLUGIN)
static gboolean static gboolean
update (NMDnsPlugin *plugin, update (NMDnsPlugin *plugin,
const NMDnsIPConfigData *const*configs, const GPtrArray *configs,
const NMGlobalDnsConfig *global_config, const NMGlobalDnsConfig *global_config,
const char *hostname) const char *hostname)
{ {