mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2025-12-24 20:30:07 +01:00
* dbus/dbus-connection.c (_dbus_connection_close_if_only_one_ref):
Add a hack to make DBusNewConnectionFunction work right.
* dbus/dbus-server-socket.c (handle_new_client_fd_and_unlock): use
the hack here. Also, fix the todo about refcount leak.
* dbus/dbus-server-debug-pipe.c (_dbus_transport_debug_pipe_new):
and use the hack here
* dbus/dbus-connection.c: Kill the "shared" flag vs. the
"shareable" flag; this was completely broken, since it meant
dbus_connection_open() returned a connection of unknown
shared-ness. Now, we always hold a ref on anything opened
as shareable.
Move the call to notify dbus-bus.c into
connection_forget_shared_unlocked, so libdbus consistently forgets
all its knowledge of a connection at once. This exposed numerous
places where things were totally broken if we dropped a ref inside
get_dispatch_status_unlocked where
connection_forget_shared_unlocked was previously, so move
connection_forget_shared_unlocked into
_dbus_connection_update_dispatch_status_and_unlock. Also move the
exit_on_disconnect here.
(shared_connections_shutdown): this assumed weak refs to the
shared connections; since we have strong refs now, the assertion
was failing and stuff was left in the hash. Fix it to close
still-open shared connections.
* bus/dispatch.c: fixup to use dbus_connection_open_private on the
debug pipe connections
* dbus/dbus-connection.c (dbus_connection_dispatch): only notify
dbus-bus.c if the closed connection is in fact shared
(_dbus_connection_close_possibly_shared): rename from
_dbus_connection_close_internal
(dbus_connection_close, dbus_connection_open,
dbus_connection_open_private): Improve docs to explain the deal
with when you should close or unref or both
* dbus/dbus-bus.c
(_dbus_bus_notify_shared_connection_disconnected_unlocked): rename
from _dbus_bus_check_connection_and_unref_unlocked and modify to
loop over all connections
* test/test-utils.c (test_connection_shutdown): don't try to close
shared connections.
* test/name-test/test-threads-init.c (main): fix warnings in here
* dbus/dbus-sysdeps.c (_dbus_abort): support DBUS_BLOCK_ON_ABORT
env variable to cause blocking waiting for gdb; drop
DBUS_PRINT_BACKTRACE and just call _dbus_print_backtrace()
unconditionally.
* configure.in: add -export-dynamic to libtool flags if assertions enabled
so _dbus_print_backtrace works.
* dbus/dbus-sysdeps-unix.c (_dbus_print_backtrace): use fprintf
instead of _dbus_verbose to print the backtrace, and diagnose lack
of -rdynamic/-export-dynamic
189 lines
4.8 KiB
C
189 lines
4.8 KiB
C
#include "test-utils.h"
|
|
|
|
typedef struct
|
|
{
|
|
DBusLoop *loop;
|
|
DBusConnection *connection;
|
|
|
|
} CData;
|
|
|
|
static dbus_bool_t
|
|
connection_watch_callback (DBusWatch *watch,
|
|
unsigned int condition,
|
|
void *data)
|
|
{
|
|
return dbus_watch_handle (watch, condition);
|
|
}
|
|
|
|
static dbus_bool_t
|
|
add_watch (DBusWatch *watch,
|
|
void *data)
|
|
{
|
|
CData *cd = data;
|
|
|
|
return _dbus_loop_add_watch (cd->loop,
|
|
watch,
|
|
connection_watch_callback,
|
|
cd, NULL);
|
|
}
|
|
|
|
static void
|
|
remove_watch (DBusWatch *watch,
|
|
void *data)
|
|
{
|
|
CData *cd = data;
|
|
|
|
_dbus_loop_remove_watch (cd->loop,
|
|
watch, connection_watch_callback, cd);
|
|
}
|
|
|
|
static void
|
|
connection_timeout_callback (DBusTimeout *timeout,
|
|
void *data)
|
|
{
|
|
/* Can return FALSE on OOM but we just let it fire again later */
|
|
dbus_timeout_handle (timeout);
|
|
}
|
|
|
|
static dbus_bool_t
|
|
add_timeout (DBusTimeout *timeout,
|
|
void *data)
|
|
{
|
|
CData *cd = data;
|
|
|
|
return _dbus_loop_add_timeout (cd->loop,
|
|
timeout, connection_timeout_callback, cd, NULL);
|
|
}
|
|
|
|
static void
|
|
remove_timeout (DBusTimeout *timeout,
|
|
void *data)
|
|
{
|
|
CData *cd = data;
|
|
|
|
_dbus_loop_remove_timeout (cd->loop,
|
|
timeout, connection_timeout_callback, cd);
|
|
}
|
|
|
|
static void
|
|
dispatch_status_function (DBusConnection *connection,
|
|
DBusDispatchStatus new_status,
|
|
void *data)
|
|
{
|
|
DBusLoop *loop = data;
|
|
|
|
if (new_status != DBUS_DISPATCH_COMPLETE)
|
|
{
|
|
while (!_dbus_loop_queue_dispatch (loop, connection))
|
|
_dbus_wait_for_memory ();
|
|
}
|
|
}
|
|
|
|
static void
|
|
cdata_free (void *data)
|
|
{
|
|
CData *cd = data;
|
|
|
|
dbus_connection_unref (cd->connection);
|
|
_dbus_loop_unref (cd->loop);
|
|
|
|
dbus_free (cd);
|
|
}
|
|
|
|
static CData*
|
|
cdata_new (DBusLoop *loop,
|
|
DBusConnection *connection)
|
|
{
|
|
CData *cd;
|
|
|
|
cd = dbus_new0 (CData, 1);
|
|
if (cd == NULL)
|
|
return NULL;
|
|
|
|
cd->loop = loop;
|
|
cd->connection = connection;
|
|
|
|
dbus_connection_ref (cd->connection);
|
|
_dbus_loop_ref (cd->loop);
|
|
|
|
return cd;
|
|
}
|
|
|
|
dbus_bool_t
|
|
test_connection_setup (DBusLoop *loop,
|
|
DBusConnection *connection)
|
|
{
|
|
CData *cd;
|
|
|
|
cd = NULL;
|
|
|
|
dbus_connection_set_dispatch_status_function (connection, dispatch_status_function,
|
|
loop, NULL);
|
|
|
|
cd = cdata_new (loop, connection);
|
|
if (cd == NULL)
|
|
goto nomem;
|
|
|
|
/* Because dbus-mainloop.c checks dbus_timeout_get_enabled(),
|
|
* dbus_watch_get_enabled() directly, we don't have to provide
|
|
* "toggled" callbacks.
|
|
*/
|
|
|
|
if (!dbus_connection_set_watch_functions (connection,
|
|
add_watch,
|
|
remove_watch,
|
|
NULL,
|
|
cd, cdata_free))
|
|
goto nomem;
|
|
|
|
|
|
cd = cdata_new (loop, connection);
|
|
if (cd == NULL)
|
|
goto nomem;
|
|
|
|
if (!dbus_connection_set_timeout_functions (connection,
|
|
add_timeout,
|
|
remove_timeout,
|
|
NULL,
|
|
cd, cdata_free))
|
|
goto nomem;
|
|
|
|
if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
|
|
{
|
|
if (!_dbus_loop_queue_dispatch (loop, connection))
|
|
goto nomem;
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
nomem:
|
|
if (cd)
|
|
cdata_free (cd);
|
|
|
|
dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
|
|
dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL);
|
|
dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
void
|
|
test_connection_shutdown (DBusLoop *loop,
|
|
DBusConnection *connection)
|
|
{
|
|
if (!dbus_connection_set_watch_functions (connection,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL, NULL))
|
|
_dbus_assert_not_reached ("setting watch functions to NULL failed");
|
|
|
|
if (!dbus_connection_set_timeout_functions (connection,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL, NULL))
|
|
_dbus_assert_not_reached ("setting timeout functions to NULL failed");
|
|
|
|
dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
|
|
}
|