libnm: drop NMObject:dbus-connection (bgo #735916)

This commit is contained in:
Dan Winship 2014-09-09 12:15:54 -04:00
commit 8723bbd3e8
8 changed files with 47 additions and 124 deletions

View file

@ -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;

View file

@ -27,18 +27,22 @@
#include "nm-dbus-interface.h"
static dbus_int32_t priv_slot = -1;
static DBusBusType nm_bus = DBUS_BUS_SYSTEM;
static gboolean
_ensure_dbus_data_slot (void)
static void
_ensure_nm_dbus_helpers_inited (void)
{
static gsize init_value = 0;
gboolean success = TRUE;
if (g_once_init_enter (&init_value)) {
success = dbus_connection_allocate_data_slot (&priv_slot);
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);
}
return success;
}
DBusGConnection *
@ -46,14 +50,11 @@ _nm_dbus_new_connection (GError **error)
{
DBusGConnection *connection = NULL;
if (!_ensure_dbus_data_slot ()) {
g_set_error (error, DBUS_GERROR, DBUS_GERROR_FAILED, "failed to allocated data slot");
return NULL;
}
_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);
@ -69,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;
}
@ -77,7 +78,7 @@ _nm_dbus_new_connection (GError **error)
gboolean
_nm_dbus_is_connection_private (DBusGConnection *connection)
{
if (!_ensure_dbus_data_slot ())
if (priv_slot == -1)
return FALSE;
return !!dbus_connection_get_data (dbus_g_connection_get_connection (connection), priv_slot);
}

View file

@ -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);

View file

@ -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;
@ -405,19 +392,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:
*
@ -479,22 +453,6 @@ nm_object_async_initable_iface_init (GAsyncInitableIface *iface)
iface->init_finish = init_finish;
}
/**
* 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;
@ -1442,12 +1396,6 @@ _nm_object_new_proxy (NMObject *self, const char *path, const char *interface)
return _nm_dbus_new_proxy_for_connection (priv->connection, path ? path : priv->path, 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)
{

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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);