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
(cherry picked from commit 51b2cef04f
)
This commit is contained in:
@@ -180,38 +180,35 @@ _set_hostname (NMPolicy *self,
|
|||||||
if (new_hostname)
|
if (new_hostname)
|
||||||
g_clear_object (&priv->lookup_addr);
|
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
|
if ( priv->orig_hostname
|
||||||
&& (priv->hostname_changed == FALSE)
|
&& (priv->hostname_changed == FALSE)
|
||||||
&& g_strcmp0 (priv->orig_hostname, new_hostname) == 0)
|
&& g_strcmp0 (priv->orig_hostname, new_hostname) == 0) {
|
||||||
return;
|
/* 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;
|
||||||
|
|
||||||
/* Don't change the hostname or update DNS if the hostname isn't actually
|
/* Notify the DNS manager of the hostname change so that the domain part, if
|
||||||
* going to change.
|
* present, can be added to the search list.
|
||||||
*/
|
*/
|
||||||
if (g_strcmp0 (priv->cur_hostname, new_hostname) == 0)
|
nm_dns_manager_set_hostname (priv->dns_manager, priv->cur_hostname);
|
||||||
return;
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
/* Finally, set kernel hostname */
|
/* Finally, set kernel hostname */
|
||||||
|
if (!new_hostname)
|
||||||
if (!priv->cur_hostname)
|
|
||||||
name = FALLBACK_HOSTNAME4;
|
name = FALLBACK_HOSTNAME4;
|
||||||
else if (!priv->cur_hostname[0]) {
|
else if (!new_hostname[0]) {
|
||||||
g_warn_if_reached ();
|
g_warn_if_reached ();
|
||||||
name = FALLBACK_HOSTNAME4;
|
name = FALLBACK_HOSTNAME4;
|
||||||
} else
|
} else
|
||||||
name = priv->cur_hostname;
|
name = new_hostname;
|
||||||
|
|
||||||
old_hostname[HOST_NAME_MAX] = '\0';
|
old_hostname[HOST_NAME_MAX] = '\0';
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
Reference in New Issue
Block a user