Bug: https://bugzilla.gnome.org/show_bug.cgi?id=665211
https://bugzilla.gnome.org/show_bug.cgi?id=548954
G_LOCK_DEFINE_STATIC (message_bus_lock);
G_LOCK_DEFINE_STATIC (message_bus_lock);
-static GDBusConnection *the_session_bus = NULL;
-static GDBusConnection *the_system_bus = NULL;
+static GWeakRef the_session_bus;
+static GWeakRef the_system_bus;
/* Extra pseudo-member of GDBusSendMessageFlags.
* Set by initable_init() to indicate that despite not being initialized yet,
/* Extra pseudo-member of GDBusSendMessageFlags.
* Set by initable_init() to indicate that despite not being initialized yet,
GDBusConnection *connection = G_DBUS_CONNECTION (object);
G_LOCK (message_bus_lock);
GDBusConnection *connection = G_DBUS_CONNECTION (object);
G_LOCK (message_bus_lock);
- if (connection == the_session_bus)
- {
- the_session_bus = NULL;
- }
- else if (connection == the_system_bus)
- {
- the_system_bus = NULL;
- }
CONNECTION_LOCK (connection);
if (connection->worker != NULL)
{
CONNECTION_LOCK (connection);
if (connection->worker != NULL)
{
/* ---------------------------------------------------------------------------------------------------- */
/* Called in any user thread, with the message_bus_lock held. */
/* ---------------------------------------------------------------------------------------------------- */
/* Called in any user thread, with the message_bus_lock held. */
-static GDBusConnection **
message_bus_get_singleton (GBusType bus_type,
GError **error)
{
message_bus_get_singleton (GBusType bus_type,
GError **error)
{
const gchar *starter_bus;
ret = NULL;
const gchar *starter_bus;
ret = NULL;
GCancellable *cancellable,
GError **error)
{
GCancellable *cancellable,
GError **error)
{
- GDBusConnection **singleton;
GDBusConnection *ret;
ret = NULL;
GDBusConnection *ret;
ret = NULL;
if (singleton == NULL)
goto out;
if (singleton == NULL)
goto out;
- if (*singleton == NULL)
+ ret = g_weak_ref_get (singleton);
+
+ if (ret == NULL)
{
gchar *address;
address = g_dbus_address_get_for_bus_sync (bus_type, cancellable, error);
if (address == NULL)
goto out;
{
gchar *address;
address = g_dbus_address_get_for_bus_sync (bus_type, cancellable, error);
if (address == NULL)
goto out;
- ret = *singleton = g_object_new (G_TYPE_DBUS_CONNECTION,
- "address", address,
- "flags", G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
- G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
- "exit-on-close", TRUE,
- NULL);
+ ret = g_object_new (G_TYPE_DBUS_CONNECTION,
+ "address", address,
+ "flags", G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
+ G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
+ "exit-on-close", TRUE,
+ NULL);
+
+ g_weak_ref_set (singleton, ret);
- else
- {
- ret = g_object_ref (*singleton);
- }