NetworkManager/0003-policy-move-code-from-set_system_hostname-to-_set_ho.patch
2016-03-22 10:20:24 +01:00

113 lines
3.4 KiB
Diff

From 078179c836fb39a81173ab5ce7db1ccc05eb3f7a Mon Sep 17 00:00:00 2001
From: Beniamino Galvani <bgalvani@redhat.com>
Date: Mon, 22 Feb 2016 10:10:15 +0100
Subject: [PATCH 3/3] policy: move code from set_system_hostname() to
_set_hostname()
---
src/nm-policy.c | 74 ++++++++++++++++++++++++++++-----------------------------
1 file changed, 36 insertions(+), 38 deletions(-)
diff --git a/src/nm-policy.c b/src/nm-policy.c
index fca4005..84d1e7e 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -141,48 +141,14 @@ static void settings_set_hostname_cb (const char *hostname,
}
static void
-set_system_hostname (NMPolicy *self, const char *new_hostname, const char *msg)
-{
- NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
- char old_hostname[HOST_NAME_MAX + 1];
- const char *name;
- int ret;
-
- if (!new_hostname)
- name = FALLBACK_HOSTNAME4;
- else if (!new_hostname[0]) {
- g_warn_if_reached ();
- name = FALLBACK_HOSTNAME4;
- } else
- name = new_hostname;
-
- old_hostname[HOST_NAME_MAX] = '\0';
- errno = 0;
- ret = gethostname (old_hostname, HOST_NAME_MAX);
- if (ret != 0) {
- nm_log_warn (LOGD_DNS, "couldn't get the system hostname: (%d) %s",
- errno, strerror (errno));
- } else {
- /* Don't set the hostname if it isn't actually changing */
- if (nm_streq (name, old_hostname))
- return;
- }
-
- nm_log_info (LOGD_DNS, "Setting system hostname to '%s' (%s)", name, msg);
- nm_settings_set_transient_hostname (priv->settings,
- name,
- settings_set_hostname_cb,
- NULL);
-
- return (ret == 0);
-}
-
-static void
_set_hostname (NMPolicy *policy,
const char *new_hostname,
const char *msg)
{
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (policy);
+ char old_hostname[HOST_NAME_MAX + 1];
+ const char *name;
+ int ret;
/* The incoming hostname *can* be NULL, which will get translated to
* 'localhost.localdomain' or such in the hostname policy code, but we
@@ -214,9 +180,41 @@ _set_hostname (NMPolicy *policy,
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);
- set_system_hostname (policy, priv->cur_hostname, msg);
+ /* Finally, set kernel hostname */
+
+ if (!priv->cur_hostname)
+ name = FALLBACK_HOSTNAME4;
+ else if (!priv->cur_hostname[0]) {
+ g_warn_if_reached ();
+ name = FALLBACK_HOSTNAME4;
+ } else
+ name = priv->cur_hostname;
+
+ old_hostname[HOST_NAME_MAX] = '\0';
+ errno = 0;
+ ret = gethostname (old_hostname, HOST_NAME_MAX);
+ if (ret != 0) {
+ nm_log_warn (LOGD_DNS, "couldn't get the system hostname: (%d) %s",
+ errno, strerror (errno));
+ } else {
+ /* Don't set the hostname if it isn't actually changing */
+ if (nm_streq (name, old_hostname))
+ return;
+ }
+
+ nm_log_info (LOGD_DNS, "setting system hostname to '%s' (%s)", name, msg);
+
+ /* Ask NMSettings to update the transient hostname using its
+ * systemd-hostnamed proxy */
+ nm_settings_set_transient_hostname (priv->settings,
+ name,
+ settings_set_hostname_cb,
+ NULL);
}
static void
--
2.5.0