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-10 16:22:13 +0100
commitd10a5b313475b805207c11a9faf13422c85dea10 (patch)
treedff286bf80ad1f4c42048a734d3c9ac04bc87cc6
parent3ce22c73192255e90dd2f743b397da38bb31b87b (diff)
downloadNetworkManager-fg/hostname_overwrites_resolv_rh1344303.tar.gz
policy: check for active devices before triggering dns update on hostname changefg/hostname_overwrites_resolv_rh1344303
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 bc602db72d..91123762da 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 */