policy: check for active devices before triggering dns update on hostname change

When hostname changes, resolv.conf should be rewritten to update the
"search" option with the new domain parameters. If no device is
active nor going to activate, skip triggering resolv.conf update.
This commit is contained in:
Francesco Giudici
2017-03-10 15:17:02 +01:00
parent 81cd300108
commit b07f6712e9
3 changed files with 28 additions and 3 deletions

View File

@@ -1434,7 +1434,8 @@ nm_dns_manager_set_initial_hostname (NMDnsManager *self,
void
nm_dns_manager_set_hostname (NMDnsManager *self,
const char *hostname)
const char *hostname,
gboolean skip_update)
{
NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self);
GError *error = NULL;
@@ -1455,6 +1456,8 @@ nm_dns_manager_set_hostname (NMDnsManager *self,
g_free (priv->hostname);
priv->hostname = g_strdup (filtered);
if (skip_update)
return;
if (!priv->updates_queue && !update_dns (self, FALSE, &error)) {
_LOGW ("could not commit DNS changes: %s", error->message);
g_clear_error (&error);

View File

@@ -87,7 +87,8 @@ gboolean nm_dns_manager_remove_ip6_config (NMDnsManager *self, NMIP6Config *conf
void nm_dns_manager_set_initial_hostname (NMDnsManager *self,
const char *hostname);
void nm_dns_manager_set_hostname (NMDnsManager *self,
const char *hostname);
const char *hostname,
gboolean skip_update);
/**
* NMDnsManagerResolvConfManager

View File

@@ -386,6 +386,26 @@ get_best_ip6_device (NMPolicy *self, gboolean fully_activated)
priv->default_device6);
}
static gboolean
all_devices_not_active (NMPolicy *self)
{
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
const GSList *iter = nm_manager_get_devices (priv->manager);
while (iter != NULL) {
NMDeviceState state;
state = nm_device_get_state (NM_DEVICE (iter->data));
if ( state <= NM_DEVICE_STATE_DISCONNECTED
|| state >= NM_DEVICE_STATE_DEACTIVATING) {
iter = g_slist_next (iter);
continue;
}
return FALSE;
}
return TRUE;
}
#define FALLBACK_HOSTNAME4 "localhost.localdomain"
static void
@@ -451,7 +471,8 @@ _set_hostname (NMPolicy *self,
/* Notify the DNS manager of the hostname change so that the domain part, if
* present, can be added to the search list.
*/
nm_dns_manager_set_hostname (priv->dns_manager, priv->cur_hostname);
nm_dns_manager_set_hostname (priv->dns_manager, priv->cur_hostname,
all_devices_not_active (self));
}
/* Finally, set kernel hostname */