On Slackware, the expectation is for output of "hostname" without options
to be the same as "hostname --short" whereas "hostname --fqdn" would be
used if the full hostname+domain is desired.

With NM-1.2.x, using persistent hostname setting and pulling it from
/etc/HOSTNAME, it gets set to the fqdn and this breaks some of our
expectations. It's not technically a bug, I suppose, but we like it
the way we expect it, so: see attached patch from Volkerding to fix
it.

This doesn't affect anything unless HOSTNAME_PERSIST_SLACKWARE is
defined, so nobody else should be affected at all.

Please apply to both master and 1.2 branch.

-RW
>From 66b29e0c4afb141134a6d9e959b749f024369e6a Mon Sep 17 00:00:00 2001
From: "Patrick J. Volkerding" <volke...@slackware.com>
Date: Fri, 22 Apr 2016 20:30:56 -0500
Subject: [PATCH] nm-settings.c: Fixup Slackware hostname setting

---
 src/settings/nm-settings.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index ee6e4f8..f68c5f4 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -500,6 +500,41 @@ read_hostname_gentoo (const char *path)
 }
 #endif
 
+#if defined(HOSTNAME_PERSIST_SLACKWARE)
+static gchar *
+read_hostname_slackware (const char *path)
+{
+	gchar *contents = NULL, *result = NULL, *tmp;
+	gchar **all_lines = NULL;
+	guint line_num, i, j = 0;
+
+	if (!g_file_get_contents (path, &contents, NULL, NULL))
+		return NULL;
+	all_lines = g_strsplit (contents, "\n", 0);
+	line_num = g_strv_length (all_lines);
+	for (i = 0; i < line_num; i++) {
+		g_strstrip (all_lines[i]);
+		if (all_lines[i][0] == '#' || all_lines[i][0] == '\0')
+			continue;
+		tmp = &all_lines[i][0];
+		/* We only want up to the first '.' -- the rest of the */
+		/* fqdn is defined in /etc/hosts */
+		while (tmp[j] != '\0') {
+			if (tmp[j] == '.') {
+				tmp[j] = '\0';
+				break;    
+			}
+			j++;
+		}
+		result = g_shell_unquote (tmp, NULL);
+		break;
+	}
+	g_strfreev (all_lines);
+	g_free (contents);
+	return result;
+}
+#endif
+
 #if defined(HOSTNAME_PERSIST_SUSE)
 static gboolean
 hostname_is_dynamic (void)
@@ -547,6 +582,10 @@ nm_settings_get_hostname (NMSettings *self)
 	hostname = read_hostname_gentoo (priv->hostname.file);
 #else
 
+#if defined(HOSTNAME_PERSIST_SLACKWARE)
+	hostname = read_hostname_slackware (priv->hostname.file);
+#else
+
 #if defined(HOSTNAME_PERSIST_SUSE)
 	if (priv->hostname.dhcp_monitor_id && hostname_is_dynamic ())
 		return NULL;
@@ -555,6 +594,7 @@ nm_settings_get_hostname (NMSettings *self)
 		g_strchomp (hostname);
 
 #endif /* HOSTNAME_PERSIST_GENTOO */
+#endif /* HOSTNAME_PERSIST_SLACKWARE */
 
 out:
 	if (hostname && !hostname[0]) {
-- 
2.8.1

_______________________________________________
networkmanager-list mailing list
networkmanager-list@gnome.org
https://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to