From d83cc33a7f9a133b4d4be0cd4693fea4d7bffd3e Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 1 Oct 2008 22:59:21 +0000 Subject: [PATCH] 2008-10-01 Dan Williams * system-settings/src/dbus-settings.c - (nm_sysconfig_settings_init): cache system hostname on startup as a fallback if no plugin provides a hostname - (get_property): fall back to cached hostname if no plugin provides a hostname git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4136 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 8 ++++++++ system-settings/src/dbus-settings.c | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 79a6d8460a..3515215fa2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-10-01 Dan Williams + + * system-settings/src/dbus-settings.c + - (nm_sysconfig_settings_init): cache system hostname on startup as + a fallback if no plugin provides a hostname + - (get_property): fall back to cached hostname if no plugin provides + a hostname + 2008-10-01 Dan Williams Fix setting value comparison issue that caused some settings to look the diff --git a/system-settings/src/dbus-settings.c b/system-settings/src/dbus-settings.c index bb1e13c4df..70b3a66b67 100644 --- a/system-settings/src/dbus-settings.c +++ b/system-settings/src/dbus-settings.c @@ -24,10 +24,12 @@ * (C) Copyright 2008 Novell, Inc. */ +#include +#include + #include #include #include -#include #include #include "nm-dbus-glib-types.h" @@ -55,6 +57,7 @@ typedef struct { gboolean connections_loaded; GHashTable *connections; GHashTable *unmanaged_devices; + char *orig_hostname; } NMSysconfigSettingsPrivate; G_DEFINE_TYPE (NMSysconfigSettings, nm_sysconfig_settings, NM_TYPE_SETTINGS); @@ -149,6 +152,8 @@ settings_finalize (GObject *object) g_object_unref (priv->hal_mgr); dbus_g_connection_unref (priv->g_connection); + g_free (priv->orig_hostname); + G_OBJECT_CLASS (nm_sysconfig_settings_parent_class)->finalize (object); } @@ -249,6 +254,10 @@ get_property (GObject *object, guint prop_id, } } + /* If no plugin provided a hostname, try the original hostname of the machine */ + if (!g_value_get_string (value) && priv->orig_hostname) + g_value_set_string (value, priv->orig_hostname); + /* Don't ever pass NULL through D-Bus */ if (!g_value_get_string (value)) g_value_set_static_string (value, ""); @@ -312,11 +321,20 @@ static void nm_sysconfig_settings_init (NMSysconfigSettings *self) { NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self); + char hostname[HOST_NAME_MAX + 2]; priv->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL); priv->unmanaged_devices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); priv->pol_ctx = create_polkit_context (); + + /* Grab hostname on startup and use that if no plugins provide one */ + memset (hostname, 0, sizeof (hostname)); + if (gethostname (&hostname[0], HOST_NAME_MAX) == 0) { + /* only cache it if it's a valid hostname */ + if (strlen (hostname) && strcmp (hostname, "localhost") && strcmp (hostname, "localhost.localdomain")) + priv->orig_hostname = g_strdup (hostname); + } } NMSysconfigSettings *