summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-09-05 12:55:18 -0400
committerDan Winship <danw@gnome.org>2014-09-09 12:10:13 -0400
commitb732380d1eb86d4278578559b0ec00990202e3fc (patch)
tree29b9cdfb594c2f712bc63a4dbcc05b1775b2b49f
parenta874e0beac9832b7c9df8360b16dba69122765a5 (diff)
libnm: drop NMObject:dbus-connection
The only plausible use case for the NMObject:dbus-connection property is for using the session bus in test programs. So just drop it and use an environment variable to decide which bus to use instead.
-rw-r--r--libnm/libnm.ver1
-rw-r--r--libnm/nm-dbus-helpers.c13
-rw-r--r--libnm/nm-object-private.h2
-rw-r--r--libnm/nm-object.c76
-rw-r--r--libnm/nm-object.h4
-rw-r--r--libnm/nm-remote-connection.c4
-rw-r--r--libnm/tests/test-nm-client.c47
-rw-r--r--libnm/tests/test-remote-settings-client.c12
8 files changed, 43 insertions, 116 deletions
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index 5617fb25f9..0597c493c4 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -334,7 +334,6 @@ global:
nm_ip6_route_unref;
nm_object_error_get_type;
nm_object_error_quark;
- nm_object_get_dbus_connection;
nm_object_get_path;
nm_object_get_type;
nm_remote_connection_commit_changes;
diff --git a/libnm/nm-dbus-helpers.c b/libnm/nm-dbus-helpers.c
index 64b708616c..464facef8b 100644
--- a/libnm/nm-dbus-helpers.c
+++ b/libnm/nm-dbus-helpers.c
@@ -27,15 +27,20 @@
#include "nm-dbus-interface.h"
static dbus_int32_t priv_slot = -1;
+static DBusBusType nm_bus = DBUS_BUS_SYSTEM;
static void
-_ensure_dbus_data_slot (void)
+_ensure_nm_dbus_helpers_inited (void)
{
static gsize init_value = 0;
if (g_once_init_enter (&init_value)) {
dbus_connection_allocate_data_slot (&priv_slot);
g_assert (priv_slot != -1);
+
+ if (g_getenv ("LIBNM_USE_SESSION_BUS"))
+ nm_bus = DBUS_BUS_SESSION;
+
g_once_init_leave (&init_value, 1);
}
}
@@ -45,11 +50,11 @@ _nm_dbus_new_connection (GError **error)
{
DBusGConnection *connection = NULL;
- _ensure_dbus_data_slot ();
+ _ensure_nm_dbus_helpers_inited ();
#if HAVE_DBUS_GLIB_100
/* If running as root try the private bus first */
- if (0 == geteuid ()) {
+ if (0 == geteuid () && nm_bus == DBUS_BUS_SYSTEM) {
connection = dbus_g_connection_open ("unix:path=" NMRUNDIR "/private", error);
if (connection) {
DBusConnection *dbus_connection = dbus_g_connection_get_connection (connection);
@@ -65,7 +70,7 @@ _nm_dbus_new_connection (GError **error)
#endif
if (connection == NULL)
- connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, error);
+ connection = dbus_g_bus_get (nm_bus, error);
return connection;
}
diff --git a/libnm/nm-object-private.h b/libnm/nm-object-private.h
index 78764c8611..111dc96b11 100644
--- a/libnm/nm-object-private.h
+++ b/libnm/nm-object-private.h
@@ -40,8 +40,6 @@ DBusGProxy *_nm_object_new_proxy (NMObject *self,
const char *path,
const char *interface);
-gboolean _nm_object_is_connection_private (NMObject *self);
-
void _nm_object_register_properties (NMObject *object,
DBusGProxy *proxy,
const NMPropertiesInfo *info);
diff --git a/libnm/nm-object.c b/libnm/nm-object.c
index bab2a8a1ba..8a014a65bd 100644
--- a/libnm/nm-object.c
+++ b/libnm/nm-object.c
@@ -81,7 +81,6 @@ typedef struct {
enum {
PROP_0,
- PROP_DBUS_CONNECTION,
PROP_PATH,
PROP_NM_RUNNING,
@@ -162,7 +161,7 @@ init_dbus (NMObject *object)
priv->properties_proxy = _nm_object_new_proxy (object, NULL, "org.freedesktop.DBus.Properties");
- if (_nm_object_is_connection_private (object))
+ if (_nm_dbus_is_connection_private (priv->connection))
priv->nm_running = TRUE;
else {
priv->bus_proxy = dbus_g_proxy_new_for_name (priv->connection,
@@ -187,11 +186,9 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
NMObject *self = NM_OBJECT (initable);
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
- if (!priv->connection) {
- priv->connection = _nm_dbus_new_connection (error);
- if (!priv->connection)
- return FALSE;
- }
+ priv->connection = _nm_dbus_new_connection (error);
+ if (!priv->connection)
+ return FALSE;
if (!init_common (self, error))
return FALSE;
@@ -268,14 +265,12 @@ init_async (GAsyncInitable *initable, int io_priority,
simple = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, init_async);
+ priv->connection = _nm_dbus_new_connection (&error);
if (!priv->connection) {
- priv->connection = _nm_dbus_new_connection (&error);
- if (!priv->connection) {
- g_simple_async_result_take_error (simple, error);
- g_simple_async_result_complete_in_idle (simple);
- g_object_unref (simple);
- return;
- }
+ g_simple_async_result_take_error (simple, error);
+ g_simple_async_result_complete_in_idle (simple);
+ g_object_unref (simple);
+ return;
}
if (!init_common (self, &error)) {
g_simple_async_result_take_error (simple, error);
@@ -284,16 +279,15 @@ init_async (GAsyncInitable *initable, int io_priority,
return;
}
- if (_nm_object_is_connection_private (self))
- _nm_object_reload_properties_async (self, init_async_got_properties, simple);
- else {
+ if (priv->bus_proxy) {
/* Check if NM is running */
dbus_g_proxy_begin_call (priv->bus_proxy, "NameHasOwner",
init_async_got_nm_running,
simple, NULL,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID);
- }
+ } else
+ _nm_object_reload_properties_async (self, init_async_got_properties, simple);
}
static gboolean
@@ -352,10 +346,6 @@ set_property (GObject *object, guint prop_id,
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
switch (prop_id) {
- case PROP_DBUS_CONNECTION:
- /* Construct only */
- priv->connection = g_value_dup_boxed (value);
- break;
case PROP_PATH:
/* Construct only */
priv->path = g_value_dup_string (value);
@@ -373,9 +363,6 @@ get_property (GObject *object, guint prop_id,
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
switch (prop_id) {
- case PROP_DBUS_CONNECTION:
- g_value_set_boxed (value, priv->connection);
- break;
case PROP_PATH:
g_value_set_string (value, priv->path);
break;
@@ -406,19 +393,6 @@ nm_object_class_init (NMObjectClass *nm_object_class)
/* Properties */
/**
- * NMObject:connection:
- *
- * The #DBusGConnection of the object.
- **/
- g_object_class_install_property
- (object_class, PROP_DBUS_CONNECTION,
- g_param_spec_boxed (NM_OBJECT_DBUS_CONNECTION, "", "",
- DBUS_TYPE_G_CONNECTION,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- /**
* NMObject:path:
*
* The D-Bus object path.
@@ -480,22 +454,6 @@ nm_object_async_initable_iface_init (GAsyncInitableIface *iface)
}
/**
- * nm_object_get_dbus_connection:
- * @object: a #NMObject
- *
- * Gets the #NMObject's DBusGConnection.
- *
- * Returns: (transfer none): the connection
- **/
-DBusGConnection *
-nm_object_get_dbus_connection (NMObject *object)
-{
- g_return_val_if_fail (NM_IS_OBJECT (object), NULL);
-
- return NM_OBJECT_GET_PRIVATE (object)->connection;
-}
-
-/**
* nm_object_get_path:
* @object: a #NMObject
*
@@ -594,7 +552,6 @@ _nm_object_create (GType type, DBusGConnection *connection, const char *path)
}
object = g_object_new (type,
- NM_OBJECT_DBUS_CONNECTION, connection,
NM_OBJECT_PATH, path,
NULL);
if (NM_IS_OBJECT (object))
@@ -609,7 +566,6 @@ _nm_object_create (GType type, DBusGConnection *connection, const char *path)
typedef void (*NMObjectCreateCallbackFunc) (GObject *, const char *, gpointer);
typedef struct {
- DBusGConnection *connection;
char *path;
NMObjectCreateCallbackFunc callback;
gpointer user_data;
@@ -665,7 +621,6 @@ async_got_type (GType type, gpointer user_data)
}
object = g_object_new (type,
- NM_OBJECT_DBUS_CONNECTION, async_data->connection,
NM_OBJECT_PATH, async_data->path,
NULL);
if (NM_IS_OBJECT (object))
@@ -683,7 +638,6 @@ _nm_object_create_async (GType type, DBusGConnection *connection, const char *pa
NMObjectTypeAsyncData *async_data;
async_data = g_slice_new (NMObjectTypeAsyncData);
- async_data->connection = connection;
async_data->path = g_strdup (path);
async_data->callback = callback;
async_data->user_data = user_data;
@@ -1443,12 +1397,6 @@ _nm_object_new_proxy (NMObject *self, const char *path, const char *interface)
}
gboolean
-_nm_object_is_connection_private (NMObject *self)
-{
- return _nm_dbus_is_connection_private (NM_OBJECT_GET_PRIVATE (self)->connection);
-}
-
-gboolean
_nm_object_get_nm_running (NMObject *self)
{
return NM_OBJECT_GET_PRIVATE (self)->nm_running;
diff --git a/libnm/nm-object.h b/libnm/nm-object.h
index 1d93e2a6a0..c492e67125 100644
--- a/libnm/nm-object.h
+++ b/libnm/nm-object.h
@@ -57,8 +57,7 @@ typedef enum {
#define NM_OBJECT_ERROR nm_object_error_quark ()
GQuark nm_object_error_quark (void);
-#define NM_OBJECT_DBUS_CONNECTION "dbus-connection"
-#define NM_OBJECT_PATH "path"
+#define NM_OBJECT_PATH "path"
typedef struct {
GObject parent;
@@ -85,7 +84,6 @@ typedef struct {
GType nm_object_get_type (void);
-DBusGConnection *nm_object_get_dbus_connection (NMObject *object);
const char *nm_object_get_path (NMObject *object);
G_END_DECLS
diff --git a/libnm/nm-remote-connection.c b/libnm/nm-remote-connection.c
index e42806edc1..e16322b837 100644
--- a/libnm/nm-remote-connection.c
+++ b/libnm/nm-remote-connection.c
@@ -503,9 +503,7 @@ init_dbus (NMObject *object)
NM_OBJECT_CLASS (nm_remote_connection_parent_class)->init_dbus (object);
- priv->proxy = _nm_dbus_new_proxy_for_connection (nm_object_get_dbus_connection (object),
- nm_connection_get_path (NM_CONNECTION (object)),
- NM_DBUS_INTERFACE_SETTINGS_CONNECTION);
+ priv->proxy = _nm_object_new_proxy (object, NULL, NM_DBUS_INTERFACE_SETTINGS_CONNECTION);
g_assert (priv->proxy);
dbus_g_proxy_set_default_timeout (priv->proxy, G_MAXINT);
diff --git a/libnm/tests/test-nm-client.c b/libnm/tests/test-nm-client.c
index 5bf11e4aa7..269f0fdae6 100644
--- a/libnm/tests/test-nm-client.c
+++ b/libnm/tests/test-nm-client.c
@@ -36,32 +36,6 @@ static NMTestServiceInfo *sinfo;
/*******************************************************************/
-static NMClient *
-test_client_new (void)
-{
- NMClient *client;
- DBusGConnection *bus;
- GError *error = NULL;
-
- bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- g_assert_no_error (error);
-
- client = g_object_new (NM_TYPE_CLIENT,
- NM_OBJECT_DBUS_CONNECTION, bus,
- NM_OBJECT_PATH, NM_DBUS_PATH,
- NULL);
- g_assert (client != NULL);
-
- dbus_g_connection_unref (bus);
-
- g_initable_init (G_INITABLE (client), NULL, &error);
- g_assert_no_error (error);
-
- return client;
-}
-
-/*******************************************************************/
-
static gboolean
loop_quit (gpointer user_data)
{
@@ -151,9 +125,11 @@ test_device_added (void)
const GPtrArray *devices;
NMDevice *device;
DeviceAddedInfo info = { loop, FALSE, FALSE, 0, 0 };
+ GError *error = NULL;
sinfo = nm_test_service_init ();
- client = test_client_new ();
+ client = nm_client_new (NULL, &error);
+ g_assert_no_error (error);
devices = nm_client_get_devices (client);
g_assert (devices->len == 0);
@@ -310,7 +286,8 @@ test_wifi_ap_added_removed (void)
char *expected_path = NULL;
sinfo = nm_test_service_init ();
- client = test_client_new ();
+ client = nm_client_new (NULL, &error);
+ g_assert_no_error (error);
/*************************************/
/* Add the wifi device */
@@ -533,7 +510,8 @@ test_wimax_nsp_added_removed (void)
char *expected_path = NULL;
sinfo = nm_test_service_init ();
- client = test_client_new ();
+ client = nm_client_new (NULL, &error);
+ g_assert_no_error (error);
/*************************************/
/* Add the wimax device */
@@ -717,7 +695,8 @@ test_devices_array (void)
GVariant *ret;
sinfo = nm_test_service_init ();
- client = test_client_new ();
+ client = nm_client_new (NULL, &error);
+ g_assert_no_error (error);
/*************************************/
/* Add some devices */
@@ -822,7 +801,8 @@ test_client_nm_running (void)
int running_changed = 0;
GError *error = NULL;
- client1 = test_client_new ();
+ client1 = nm_client_new (NULL, &error);
+ g_assert_no_error (error);
g_assert (!nm_client_get_nm_running (client1));
g_assert_cmpstr (nm_client_get_version (client1), ==, NULL);
@@ -839,7 +819,8 @@ test_client_nm_running (void)
/* Now start the test service. */
sinfo = nm_test_service_init ();
- client2 = test_client_new ();
+ client2 = nm_client_new (NULL, &error);
+ g_assert_no_error (error);
/* client2 should know that NM is running, but the previously-created
* client1 hasn't gotten the news yet.
@@ -875,6 +856,8 @@ test_client_nm_running (void)
int
main (int argc, char **argv)
{
+ g_setenv ("LIBNM_USE_SESSION_BUS", "1", TRUE);
+
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c
index 52977f8e2f..f8ea5b42a3 100644
--- a/libnm/tests/test-remote-settings-client.c
+++ b/libnm/tests/test-remote-settings-client.c
@@ -421,11 +421,9 @@ test_nm_running (void)
/* Now kill the test service. */
nm_test_service_cleanup (sinfo);
- settings2 = g_initable_new (NM_TYPE_REMOTE_SETTINGS, NULL, &error,
- NM_OBJECT_DBUS_CONNECTION, bus,
- NULL);
+ settings2 = nm_remote_settings_new (NULL, &error);
g_assert_no_error (error);
- g_assert (settings != NULL);
+ g_assert (settings2 != NULL);
/* settings2 should know that NM is running, but the previously-created
* settings hasn't gotten the news yet.
@@ -475,6 +473,8 @@ main (int argc, char **argv)
int ret;
GError *error = NULL;
+ g_setenv ("LIBNM_USE_SESSION_BUS", "1", TRUE);
+
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
@@ -486,9 +486,7 @@ main (int argc, char **argv)
sinfo = nm_test_service_init ();
- settings = g_initable_new (NM_TYPE_REMOTE_SETTINGS, NULL, &error,
- NM_OBJECT_DBUS_CONNECTION, bus,
- NULL);
+ settings = nm_remote_settings_new (NULL, &error);
g_assert_no_error (error);
g_assert (settings != NULL);