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-17 19:15:55 +0200
commita93d8bea7d4abfcf7c7faaebd6a5a273b51f6ef9 (patch)
treef067da48335ce86da9ae9ccb351cc98cca5759d1
parent844345eddde7362318df65fa2d788e11c9fa9f0e (diff)
downloadNetworkManager-bg/hostname-fix-rh1356015.tar.gz
policy: always try to update kernel hostnamebg/hostname-fix-rh1356015
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;