summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2016-08-17 18:40:17 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2016-08-19 09:56:13 +0200
commit51b2cef04f7e929f012ae49a6c6d94e60bc68c16 (patch)
tree3f563d5392206b042fbae0e6c7dbf89d0ed9e1a3
parentbdd0f722b8d3cceb8b4e85c26c4129759bb6931b (diff)
downloadNetworkManager-51b2cef04f7e929f012ae49a6c6d94e60bc68c16.tar.gz
policy: always try to update kernel hostname
Even if we know that the new hostname being set is equal to the cached old one, the user may have manually changed the kernel hostname in the meanwhile. For example: # hostname host123 # hostname localhost # nmcli connection up eth1 # (now NM receives 'host123' from DHCP, but # believes it's already set and doesn't update it) # hostname localhost Let's always try to update the kernel (transient) hostname, unless it is really already set (as returned by gethostname()). https://bugzilla.redhat.com/show_bug.cgi?id=1356015
-rw-r--r--src/nm-policy.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c
index eefbf1c7eb..5fa46259cd 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -180,38 +180,35 @@ _set_hostname (NMPolicy *self,
if (new_hostname)
g_clear_object (&priv->lookup_addr);
- /* Don't change the hostname or update DNS this is the first time we're
- * trying to change the hostname, and it's not actually changing.
- */
if ( priv->orig_hostname
&& (priv->hostname_changed == FALSE)
- && g_strcmp0 (priv->orig_hostname, new_hostname) == 0)
- return;
-
- /* Don't change the hostname or update DNS if the hostname isn't actually
- * going to change.
- */
- if (g_strcmp0 (priv->cur_hostname, new_hostname) == 0)
- return;
-
- g_free (priv->cur_hostname);
- priv->cur_hostname = g_strdup (new_hostname);
- priv->hostname_changed = TRUE;
+ && g_strcmp0 (priv->orig_hostname, new_hostname) == 0) {
+ /* Don't change the hostname or update DNS this is the first time we're
+ * trying to change the hostname, and it's not actually changing.
+ */
+ } else if (g_strcmp0 (priv->cur_hostname, new_hostname) == 0) {
+ /* Don't change the hostname or update DNS if the hostname isn't actually
+ * going to change.
+ */
+ } else {
+ g_free (priv->cur_hostname);
+ priv->cur_hostname = g_strdup (new_hostname);
+ priv->hostname_changed = TRUE;
- /* 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);
+ /* 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);
+ }
/* Finally, set kernel hostname */
-
- if (!priv->cur_hostname)
+ if (!new_hostname)
name = FALLBACK_HOSTNAME4;
- else if (!priv->cur_hostname[0]) {
+ else if (!new_hostname[0]) {
g_warn_if_reached ();
name = FALLBACK_HOSTNAME4;
} else
- name = priv->cur_hostname;
+ name = new_hostname;
old_hostname[HOST_NAME_MAX] = '\0';
errno = 0;