summaryrefslogtreecommitdiff
path: root/libnm-glib
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2017-02-14 12:44:10 +0000
committerThomas Haller <thaller@redhat.com>2017-02-15 16:30:16 +0100
commit5a38b5c88b14e0d05df301a5a54d7c2cc4cb676a (patch)
treecfbee0036c79f281a6bea97fa056a8ee9b98ddbf /libnm-glib
parent78058f780904d38359165cec11d7ee0735b7addb (diff)
libnm-glib/nm-object: defer assignment of default D-Bus connection
If no D-Bus connection is provided to the constructor of an NMObject, a default one will be assigned in set_property(). However, construction of that default D-Bus connection might fail (if our connection to the system bus is refused, for example), so priv->connection might still be NULL. This will cause the constructor to fail construction of the NMObject, which is correct, but hard to debug. Instead, move the default D-Bus connection handling into the constructor, so all the (priv->connection == NULL) handling is in the same place. Print out any error message. Signed-off-by: Philip Withnall <withnall@endlessm.com> https://bugzilla.gnome.org/show_bug.cgi?id=778610
Diffstat (limited to 'libnm-glib')
-rw-r--r--libnm-glib/nm-object.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/libnm-glib/nm-object.c b/libnm-glib/nm-object.c
index c7201cda2..4d77a86cf 100644
--- a/libnm-glib/nm-object.c
+++ b/libnm-glib/nm-object.c
@@ -175,7 +175,22 @@ constructor (GType type,
priv = NM_OBJECT_GET_PRIVATE (object);
- if (priv->connection == NULL || priv->path == NULL) {
+ if (priv->connection == NULL) {
+ GError *error = NULL;
+
+ priv->connection = _nm_dbus_new_connection (&error);
+
+ if (priv->connection == NULL) {
+ g_warning ("Error connecting to system bus: %s", error->message);
+ g_clear_error (&error);
+ g_object_unref (object);
+ return NULL;
+ }
+ }
+
+ g_assert (priv->connection != NULL);
+
+ if (priv->path == NULL) {
g_warn_if_reached ();
g_object_unref (object);
return NULL;
@@ -356,8 +371,6 @@ set_property (GObject *object, guint prop_id,
case PROP_DBUS_CONNECTION:
/* Construct only */
priv->connection = g_value_dup_boxed (value);
- if (!priv->connection)
- priv->connection = _nm_dbus_new_connection (NULL);
break;
case PROP_DBUS_PATH:
/* Construct only */