77 lines
2.3 KiB
Diff
77 lines
2.3 KiB
Diff
When reading hostname from NM keyfile, if no hostname is set, read from the
|
|
system file at /etc/conf.d/hostname to set hostname. This patch is not meant to
|
|
be ever upstreamed. Proper fix is to write a gentoo-specific ifcfg plugin.
|
|
|
|
To change hostname, touch nm-system-settings.conf, which will reload the keyfile
|
|
and cause /etc/conf.d/hostname to be reloaded.
|
|
|
|
This horrible hack fixes http://bugs.gentoo.org/176873
|
|
|
|
Author: Nirbheek Chauhan <nirbheek@gentoo.org>
|
|
Reviewed-by: Arun Raghavan <ford_prefect@gentoo.org>
|
|
|
|
---
|
|
--- system-settings/plugins/keyfile/plugin.c
|
|
+++ system-settings/plugins/keyfile/plugin.c
|
|
@@ -43,6 +43,9 @@
|
|
#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2008 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
|
|
|
|
#define CONF_FILE SYSCONFDIR "/NetworkManager/nm-system-settings.conf"
|
|
+#ifdef TARGET_GENTOO
|
|
+#define HOSTNAME_FILE SYSCONFDIR "/conf.d/hostname"
|
|
+#endif
|
|
|
|
static char *plugin_get_hostname (SCPluginKeyfile *plugin);
|
|
static void system_config_interface_init (NMSystemConfigInterface *system_config_interface_class);
|
|
@@ -381,6 +384,12 @@
|
|
GKeyFile *key_file;
|
|
char *hostname = NULL;
|
|
GError *error = NULL;
|
|
+#ifdef TARGET_GENTOO
|
|
+ char *contents = NULL;
|
|
+ char **lines = NULL, **line;
|
|
+ GError *contents_err = NULL;
|
|
+ gsize contents_len = 0;
|
|
+#endif
|
|
|
|
key_file = g_key_file_new ();
|
|
if (g_key_file_load_from_file (key_file, CONF_FILE, G_KEY_FILE_NONE, &error))
|
|
@@ -392,7 +401,37 @@
|
|
|
|
g_key_file_free (key_file);
|
|
|
|
+ if (hostname)
|
|
+ goto out;
|
|
+#ifdef TARGET_GENTOO
|
|
+ /* If hostname is unset in keyfile, read system file to get hostname */
|
|
+ if (!g_file_get_contents (HOSTNAME_FILE, &contents,
|
|
+ &contents_len, &contents_err))
|
|
+ goto out;
|
|
+
|
|
+ lines = g_strsplit_set (contents, "\n\r", 0);
|
|
+ if (!lines)
|
|
+ goto out;
|
|
+
|
|
+ for (line = lines; *line; line++) {
|
|
+ if (!g_str_has_prefix (*line, "hostname="))
|
|
+ continue;
|
|
+ hostname = g_strsplit_set (g_strsplit_set (*line, "=", 0)[1], "#", 0)[0];
|
|
+ g_strstrip (hostname);
|
|
+ if (!hostname)
|
|
+ goto out;
|
|
+ /* Remove quotes surrounding hostname */
|
|
+ if (hostname[0] == '"' && hostname[strlen(hostname)-1] == '"')
|
|
+ contents = g_strndup(&hostname[1], strlen(hostname)-2);
|
|
+ /* Un-escape before using to imitate librc behaviour */
|
|
+ hostname = g_strcompress (contents);
|
|
+ }
|
|
+
|
|
+out:
|
|
+ g_error_free(contents_err);
|
|
+
|
|
return hostname;
|
|
+#endif
|
|
}
|
|
|
|
static gboolean
|