summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Giudici <fgiudici@redhat.com>2017-03-10 15:17:02 +0100
committerFrancesco Giudici <fgiudici@redhat.com>2017-03-16 18:17:05 +0100
commitb07f6712e983d901839a785ddf42c79d7e08872a (patch)
tree83553146b60491a2f29fe8d59c231e9b3deb47a5
parent81cd300108400683b4a9126ae597e31c2f409a86 (diff)
downloadNetworkManager-b07f6712e983d901839a785ddf42c79d7e08872a.tar.gz
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.
-rw-r--r--src/dns/nm-dns-manager.c5
-rw-r--r--src/dns/nm-dns-manager.h3
-rw-r--r--src/nm-policy.c23
3 files changed, 28 insertions, 3 deletions
diff --git a/src/dns/nm-dns-manager.c b/src/dns/nm-dns-manager.c
index ab41af9496..5b83eeba65 100644
--- a/src/dns/nm-dns-manager.c
+++ b/src/dns/nm-dns-manager.c
@@ -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);
diff --git a/src/dns/nm-dns-manager.h b/src/dns/nm-dns-manager.h
index 451ca4a658..899e4bb865 100644
--- a/src/dns/nm-dns-manager.h
+++ b/src/dns/nm-dns-manager.h
@@ -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
diff --git a/src/nm-policy.c b/src/nm-policy.c
index a8682d5df6..44b921dc83 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -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 */