2003-01-06 01:08:14 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu" -*- */
|
|
|
|
|
/* connection.c Client connections
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Academic Free License version 1.2
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include "connection.h"
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
#include "dispatch.h"
|
2003-03-23 07:41:54 +00:00
|
|
|
#include "policy.h"
|
2003-01-06 01:08:14 +00:00
|
|
|
#include "services.h"
|
2003-03-13 00:56:43 +00:00
|
|
|
#include "utils.h"
|
2003-01-06 01:08:14 +00:00
|
|
|
#include <dbus/dbus-list.h>
|
2003-04-19 16:16:24 +00:00
|
|
|
#include <dbus/dbus-hash.h>
|
2003-04-24 21:26:25 +00:00
|
|
|
#include <dbus/dbus-timeout.h>
|
2003-01-06 01:08:14 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
static void bus_connection_remove_transactions (DBusConnection *connection);
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
struct BusConnections
|
|
|
|
|
{
|
|
|
|
|
int refcount;
|
2003-04-19 16:16:24 +00:00
|
|
|
DBusList *completed; /**< List of all completed connections */
|
|
|
|
|
int n_completed; /**< Length of completed list */
|
|
|
|
|
DBusList *incomplete; /**< List of all not-yet-active connections */
|
|
|
|
|
int n_incomplete; /**< Length of incomplete list */
|
2003-03-13 03:52:58 +00:00
|
|
|
BusContext *context;
|
2003-04-19 16:16:24 +00:00
|
|
|
DBusHashTable *completed_by_user; /**< Number of completed connections for each UID */
|
2003-04-24 21:26:25 +00:00
|
|
|
DBusTimeout *expire_timeout; /**< Timeout for expiring incomplete connections. */
|
2003-03-13 03:52:58 +00:00
|
|
|
};
|
|
|
|
|
|
2003-06-22 19:39:47 +00:00
|
|
|
static dbus_int32_t connection_data_slot = -1;
|
2003-01-06 01:08:14 +00:00
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2003-03-13 03:52:58 +00:00
|
|
|
BusConnections *connections;
|
2003-04-19 16:16:24 +00:00
|
|
|
DBusList *link_in_connection_list;
|
2003-03-13 00:56:43 +00:00
|
|
|
DBusConnection *connection;
|
2003-01-06 01:08:14 +00:00
|
|
|
DBusList *services_owned;
|
2003-04-25 23:50:34 +00:00
|
|
|
int n_services_owned;
|
2003-01-21 12:42:33 +00:00
|
|
|
char *name;
|
2003-03-13 00:56:43 +00:00
|
|
|
DBusList *transaction_messages; /**< Stuff we need to send as part of a transaction */
|
|
|
|
|
DBusMessage *oom_message;
|
|
|
|
|
DBusPreallocatedSend *oom_preallocated;
|
2003-04-12 18:32:11 +00:00
|
|
|
BusClientPolicy *policy;
|
2003-04-24 21:26:25 +00:00
|
|
|
|
|
|
|
|
long connection_tv_sec; /**< Time when we connected (seconds component) */
|
|
|
|
|
long connection_tv_usec; /**< Time when we connected (microsec component) */
|
2003-01-06 01:08:14 +00:00
|
|
|
} BusConnectionData;
|
|
|
|
|
|
2003-04-24 21:26:25 +00:00
|
|
|
static dbus_bool_t expire_incomplete_timeout (void *data);
|
|
|
|
|
|
2003-01-06 01:08:14 +00:00
|
|
|
#define BUS_CONNECTION_DATA(connection) (dbus_connection_get_data ((connection), connection_data_slot))
|
|
|
|
|
|
2003-04-06 23:53:27 +00:00
|
|
|
static DBusLoop*
|
2003-04-04 00:39:22 +00:00
|
|
|
connection_get_loop (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
|
|
|
|
|
return bus_context_get_loop (d->connections->context);
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-19 16:16:24 +00:00
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
get_connections_for_uid (BusConnections *connections,
|
|
|
|
|
dbus_uid_t uid)
|
|
|
|
|
{
|
|
|
|
|
void *val;
|
|
|
|
|
int current_count;
|
|
|
|
|
|
|
|
|
|
/* val is NULL is 0 when it isn't in the hash yet */
|
|
|
|
|
|
|
|
|
|
val = _dbus_hash_table_lookup_ulong (connections->completed_by_user,
|
|
|
|
|
uid);
|
|
|
|
|
|
|
|
|
|
current_count = _DBUS_POINTER_TO_INT (val);
|
|
|
|
|
|
|
|
|
|
return current_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
adjust_connections_for_uid (BusConnections *connections,
|
|
|
|
|
dbus_uid_t uid,
|
|
|
|
|
int adjustment)
|
|
|
|
|
{
|
|
|
|
|
int current_count;
|
|
|
|
|
|
|
|
|
|
current_count = get_connections_for_uid (connections, uid);
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("Adjusting connection count for UID " DBUS_UID_FORMAT
|
|
|
|
|
": was %d adjustment %d making %d\n",
|
|
|
|
|
uid, current_count, adjustment, current_count + adjustment);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (current_count >= 0);
|
|
|
|
|
|
|
|
|
|
current_count += adjustment;
|
|
|
|
|
|
|
|
|
|
_dbus_assert (current_count >= 0);
|
|
|
|
|
|
|
|
|
|
if (current_count == 0)
|
|
|
|
|
{
|
|
|
|
|
_dbus_hash_table_remove_ulong (connections->completed_by_user, uid);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_bool_t retval;
|
|
|
|
|
|
|
|
|
|
retval = _dbus_hash_table_insert_ulong (connections->completed_by_user,
|
|
|
|
|
uid, _DBUS_INT_TO_POINTER (current_count));
|
|
|
|
|
|
|
|
|
|
/* only positive adjustment can fail as otherwise
|
|
|
|
|
* a hash entry should already exist
|
|
|
|
|
*/
|
|
|
|
|
_dbus_assert (adjustment > 0 ||
|
|
|
|
|
(adjustment <= 0 && retval));
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-15 16:25:08 +00:00
|
|
|
void
|
2003-03-13 00:56:43 +00:00
|
|
|
bus_connection_disconnected (DBusConnection *connection)
|
2003-01-06 01:08:14 +00:00
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
BusService *service;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
2003-03-16 21:01:57 +00:00
|
|
|
_dbus_assert (d != NULL);
|
2003-01-06 01:08:14 +00:00
|
|
|
|
2003-03-16 21:01:57 +00:00
|
|
|
_dbus_verbose ("%s disconnected, dropping all service ownership and releasing\n",
|
|
|
|
|
d->name ? d->name : "(inactive)");
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
/* Drop any service ownership. FIXME Unfortunately, this requires
|
|
|
|
|
* memory allocation and there doesn't seem to be a good way to
|
|
|
|
|
* handle it other than sleeping; we can't "fail" the operation of
|
|
|
|
|
* disconnecting a client, and preallocating a broadcast "service is
|
|
|
|
|
* now gone" message for every client-service pair seems kind of
|
2003-04-24 21:26:25 +00:00
|
|
|
* involved. Probably we need to do that though.
|
2003-03-13 00:56:43 +00:00
|
|
|
*/
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
while ((service = _dbus_list_get_last (&d->services_owned)))
|
|
|
|
|
{
|
|
|
|
|
BusTransaction *transaction;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
retry:
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
|
|
|
|
|
transaction = NULL;
|
|
|
|
|
while (transaction == NULL)
|
|
|
|
|
{
|
|
|
|
|
transaction = bus_transaction_new (d->connections->context);
|
2003-04-06 23:53:27 +00:00
|
|
|
_dbus_wait_for_memory ();
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bus_service_remove_owner (service, connection,
|
|
|
|
|
transaction, &error))
|
|
|
|
|
{
|
2003-04-11 00:03:06 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (&error);
|
|
|
|
|
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
|
|
|
|
|
{
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
bus_transaction_cancel_and_free (transaction);
|
2003-04-06 23:53:27 +00:00
|
|
|
_dbus_wait_for_memory ();
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
goto retry;
|
|
|
|
|
}
|
|
|
|
|
else
|
2003-04-11 00:03:06 +00:00
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Failed to remove service owner: %s %s\n",
|
|
|
|
|
error.name, error.message);
|
|
|
|
|
_dbus_assert_not_reached ("Removing service owner failed for non-memory-related reason");
|
|
|
|
|
}
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bus_transaction_execute_and_free (transaction);
|
|
|
|
|
}
|
2003-01-06 01:08:14 +00:00
|
|
|
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
bus_dispatch_remove_connection (connection);
|
2003-01-21 12:42:33 +00:00
|
|
|
|
2003-01-06 01:08:14 +00:00
|
|
|
/* no more watching */
|
2003-03-14 01:27:58 +00:00
|
|
|
if (!dbus_connection_set_watch_functions (connection,
|
2003-03-15 20:47:16 +00:00
|
|
|
NULL, NULL, NULL,
|
2003-03-14 01:27:58 +00:00
|
|
|
connection,
|
|
|
|
|
NULL))
|
|
|
|
|
_dbus_assert_not_reached ("setting watch functions to NULL failed");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_set_timeout_functions (connection,
|
2003-03-15 20:47:16 +00:00
|
|
|
NULL, NULL, NULL,
|
2003-03-14 01:27:58 +00:00
|
|
|
connection,
|
|
|
|
|
NULL))
|
|
|
|
|
_dbus_assert_not_reached ("setting timeout functions to NULL failed");
|
|
|
|
|
|
2003-03-24 17:30:47 +00:00
|
|
|
dbus_connection_set_unix_user_function (connection,
|
|
|
|
|
NULL, NULL, NULL);
|
2003-04-09 22:15:05 +00:00
|
|
|
|
|
|
|
|
dbus_connection_set_dispatch_status_function (connection,
|
|
|
|
|
NULL, NULL, NULL);
|
2003-03-24 17:30:47 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
bus_connection_remove_transactions (connection);
|
2003-03-13 03:52:58 +00:00
|
|
|
|
2003-04-19 16:16:24 +00:00
|
|
|
if (d->link_in_connection_list != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (d->name != NULL)
|
|
|
|
|
{
|
|
|
|
|
unsigned long uid;
|
|
|
|
|
|
|
|
|
|
_dbus_list_remove_link (&d->connections->completed, d->link_in_connection_list);
|
|
|
|
|
d->link_in_connection_list = NULL;
|
|
|
|
|
d->connections->n_completed -= 1;
|
2003-03-13 03:52:58 +00:00
|
|
|
|
2003-04-19 16:16:24 +00:00
|
|
|
if (dbus_connection_get_unix_user (connection, &uid))
|
|
|
|
|
{
|
|
|
|
|
if (!adjust_connections_for_uid (d->connections,
|
|
|
|
|
uid, -1))
|
|
|
|
|
_dbus_assert_not_reached ("adjusting downward should never fail");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_dbus_list_remove_link (&d->connections->incomplete, d->link_in_connection_list);
|
|
|
|
|
d->link_in_connection_list = NULL;
|
|
|
|
|
d->connections->n_incomplete -= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d->connections->n_incomplete >= 0);
|
|
|
|
|
_dbus_assert (d->connections->n_completed >= 0);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
/* frees "d" as side effect */
|
2003-01-06 01:08:14 +00:00
|
|
|
dbus_connection_set_data (connection,
|
|
|
|
|
connection_data_slot,
|
|
|
|
|
NULL, NULL);
|
2003-03-13 03:52:58 +00:00
|
|
|
|
2003-01-06 01:08:14 +00:00
|
|
|
dbus_connection_unref (connection);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-17 01:54:37 +00:00
|
|
|
static dbus_bool_t
|
2003-01-06 01:08:14 +00:00
|
|
|
connection_watch_callback (DBusWatch *watch,
|
|
|
|
|
unsigned int condition,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
2003-04-18 04:18:57 +00:00
|
|
|
/* FIXME this can be done in dbus-mainloop.c
|
2003-05-11 07:59:08 +00:00
|
|
|
* if the code in activation.c for the babysitter
|
|
|
|
|
* watch handler is fixed.
|
|
|
|
|
*/
|
2003-04-18 04:18:57 +00:00
|
|
|
|
2003-04-10 05:12:19 +00:00
|
|
|
#if 0
|
|
|
|
|
_dbus_verbose ("Calling handle_watch\n");
|
|
|
|
|
#endif
|
2003-04-18 04:18:57 +00:00
|
|
|
return dbus_watch_handle (watch, condition);
|
2003-01-06 01:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
static dbus_bool_t
|
2003-01-06 01:08:14 +00:00
|
|
|
add_connection_watch (DBusWatch *watch,
|
2003-04-04 00:39:22 +00:00
|
|
|
void *data)
|
2003-01-06 01:08:14 +00:00
|
|
|
{
|
2003-04-04 00:39:22 +00:00
|
|
|
DBusConnection *connection = data;
|
|
|
|
|
|
2003-04-06 23:53:27 +00:00
|
|
|
return _dbus_loop_add_watch (connection_get_loop (connection),
|
|
|
|
|
watch, connection_watch_callback, connection,
|
|
|
|
|
NULL);
|
2003-01-06 01:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_connection_watch (DBusWatch *watch,
|
2003-04-04 00:39:22 +00:00
|
|
|
void *data)
|
2003-01-06 01:08:14 +00:00
|
|
|
{
|
2003-04-04 00:39:22 +00:00
|
|
|
DBusConnection *connection = data;
|
|
|
|
|
|
2003-04-06 23:53:27 +00:00
|
|
|
_dbus_loop_remove_watch (connection_get_loop (connection),
|
|
|
|
|
watch, connection_watch_callback, connection);
|
2003-01-06 01:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
static void
|
|
|
|
|
connection_timeout_callback (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
2003-04-18 04:18:57 +00:00
|
|
|
/* DBusConnection *connection = data; */
|
2003-03-15 02:19:02 +00:00
|
|
|
|
2003-03-17 01:54:37 +00:00
|
|
|
/* can return FALSE on OOM but we just let it fire again later */
|
2003-03-14 01:27:58 +00:00
|
|
|
dbus_timeout_handle (timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
add_connection_timeout (DBusTimeout *timeout,
|
2003-04-04 00:39:22 +00:00
|
|
|
void *data)
|
2003-03-14 01:27:58 +00:00
|
|
|
{
|
2003-04-04 00:39:22 +00:00
|
|
|
DBusConnection *connection = data;
|
|
|
|
|
|
2003-04-06 23:53:27 +00:00
|
|
|
return _dbus_loop_add_timeout (connection_get_loop (connection),
|
|
|
|
|
timeout, connection_timeout_callback, connection, NULL);
|
2003-03-14 01:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_connection_timeout (DBusTimeout *timeout,
|
2003-04-04 00:39:22 +00:00
|
|
|
void *data)
|
2003-03-14 01:27:58 +00:00
|
|
|
{
|
2003-04-04 00:39:22 +00:00
|
|
|
DBusConnection *connection = data;
|
|
|
|
|
|
2003-04-06 23:53:27 +00:00
|
|
|
_dbus_loop_remove_timeout (connection_get_loop (connection),
|
|
|
|
|
timeout, connection_timeout_callback, connection);
|
2003-03-14 01:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-09 22:15:05 +00:00
|
|
|
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 ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-23 07:41:54 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
allow_user_function (DBusConnection *connection,
|
|
|
|
|
unsigned long uid,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
return bus_context_allow_user (d->connections->context, uid);
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-06 01:08:14 +00:00
|
|
|
static void
|
|
|
|
|
free_connection_data (void *data)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d = data;
|
|
|
|
|
|
|
|
|
|
/* services_owned should be NULL since we should be disconnected */
|
|
|
|
|
_dbus_assert (d->services_owned == NULL);
|
2003-04-25 23:50:34 +00:00
|
|
|
_dbus_assert (d->n_services_owned == 0);
|
2003-03-13 00:56:43 +00:00
|
|
|
/* similarly */
|
|
|
|
|
_dbus_assert (d->transaction_messages == NULL);
|
2003-01-21 12:42:33 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (d->oom_preallocated)
|
|
|
|
|
dbus_connection_free_preallocated_send (d->connection, d->oom_preallocated);
|
2003-03-17 05:39:10 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (d->oom_message)
|
|
|
|
|
dbus_message_unref (d->oom_message);
|
2003-03-23 07:41:54 +00:00
|
|
|
|
|
|
|
|
if (d->policy)
|
2003-04-12 18:32:11 +00:00
|
|
|
bus_client_policy_unref (d->policy);
|
2003-03-23 07:41:54 +00:00
|
|
|
|
2003-01-21 12:42:33 +00:00
|
|
|
dbus_free (d->name);
|
2003-01-06 01:08:14 +00:00
|
|
|
|
|
|
|
|
dbus_free (d);
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-24 21:26:25 +00:00
|
|
|
static void
|
|
|
|
|
call_timeout_callback (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
/* can return FALSE on OOM but we just let it fire again later */
|
|
|
|
|
dbus_timeout_handle (timeout);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
BusConnections*
|
|
|
|
|
bus_connections_new (BusContext *context)
|
2003-01-06 01:08:14 +00:00
|
|
|
{
|
2003-03-13 03:52:58 +00:00
|
|
|
BusConnections *connections;
|
2003-01-06 01:08:14 +00:00
|
|
|
|
2003-06-22 19:39:47 +00:00
|
|
|
if (!dbus_connection_allocate_data_slot (&connection_data_slot))
|
2003-04-24 21:26:25 +00:00
|
|
|
goto failed_0;
|
2003-01-06 01:08:14 +00:00
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
connections = dbus_new0 (BusConnections, 1);
|
|
|
|
|
if (connections == NULL)
|
2003-04-24 21:26:25 +00:00
|
|
|
goto failed_1;
|
2003-04-19 16:16:24 +00:00
|
|
|
|
|
|
|
|
connections->completed_by_user = _dbus_hash_table_new (DBUS_HASH_ULONG,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
if (connections->completed_by_user == NULL)
|
2003-04-24 21:26:25 +00:00
|
|
|
goto failed_2;
|
|
|
|
|
|
|
|
|
|
connections->expire_timeout = _dbus_timeout_new (100, /* irrelevant */
|
|
|
|
|
expire_incomplete_timeout,
|
|
|
|
|
connections, NULL);
|
|
|
|
|
if (connections->expire_timeout == NULL)
|
|
|
|
|
goto failed_3;
|
|
|
|
|
|
|
|
|
|
_dbus_timeout_set_enabled (connections->expire_timeout, FALSE);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_loop_add_timeout (bus_context_get_loop (context),
|
|
|
|
|
connections->expire_timeout,
|
|
|
|
|
call_timeout_callback, NULL, NULL))
|
|
|
|
|
goto failed_4;
|
2003-03-13 03:52:58 +00:00
|
|
|
|
|
|
|
|
connections->refcount = 1;
|
|
|
|
|
connections->context = context;
|
|
|
|
|
|
|
|
|
|
return connections;
|
2003-04-24 21:26:25 +00:00
|
|
|
|
|
|
|
|
failed_4:
|
|
|
|
|
_dbus_timeout_unref (connections->expire_timeout);
|
|
|
|
|
failed_3:
|
|
|
|
|
_dbus_hash_table_unref (connections->completed_by_user);
|
|
|
|
|
failed_2:
|
|
|
|
|
dbus_free (connections);
|
|
|
|
|
failed_1:
|
2003-06-22 19:39:47 +00:00
|
|
|
dbus_connection_free_data_slot (&connection_data_slot);
|
2003-04-24 21:26:25 +00:00
|
|
|
failed_0:
|
|
|
|
|
return NULL;
|
2003-03-13 03:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_connections_ref (BusConnections *connections)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (connections->refcount > 0);
|
|
|
|
|
connections->refcount += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_connections_unref (BusConnections *connections)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (connections->refcount > 0);
|
|
|
|
|
connections->refcount -= 1;
|
|
|
|
|
if (connections->refcount == 0)
|
|
|
|
|
{
|
2003-04-19 16:16:24 +00:00
|
|
|
/* drop all incomplete */
|
|
|
|
|
while (connections->incomplete != NULL)
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
{
|
|
|
|
|
DBusConnection *connection;
|
|
|
|
|
|
2003-04-19 16:16:24 +00:00
|
|
|
connection = connections->incomplete->data;
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
|
|
|
|
|
dbus_connection_ref (connection);
|
|
|
|
|
dbus_connection_disconnect (connection);
|
|
|
|
|
bus_connection_disconnected (connection);
|
|
|
|
|
dbus_connection_unref (connection);
|
|
|
|
|
}
|
2003-04-19 16:16:24 +00:00
|
|
|
|
|
|
|
|
_dbus_assert (connections->n_incomplete == 0);
|
2003-03-13 03:52:58 +00:00
|
|
|
|
2003-04-19 16:16:24 +00:00
|
|
|
/* drop all real connections */
|
|
|
|
|
while (connections->completed != NULL)
|
|
|
|
|
{
|
|
|
|
|
DBusConnection *connection;
|
|
|
|
|
|
|
|
|
|
connection = connections->completed->data;
|
|
|
|
|
|
|
|
|
|
dbus_connection_ref (connection);
|
|
|
|
|
dbus_connection_disconnect (connection);
|
|
|
|
|
bus_connection_disconnected (connection);
|
|
|
|
|
dbus_connection_unref (connection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_assert (connections->n_completed == 0);
|
|
|
|
|
|
2003-04-24 21:26:25 +00:00
|
|
|
_dbus_loop_remove_timeout (bus_context_get_loop (connections->context),
|
|
|
|
|
connections->expire_timeout,
|
|
|
|
|
call_timeout_callback, NULL);
|
|
|
|
|
|
|
|
|
|
_dbus_timeout_unref (connections->expire_timeout);
|
|
|
|
|
|
2003-04-19 16:16:24 +00:00
|
|
|
_dbus_hash_table_unref (connections->completed_by_user);
|
2003-03-13 03:52:58 +00:00
|
|
|
|
2003-03-17 05:39:10 +00:00
|
|
|
dbus_free (connections);
|
|
|
|
|
|
2003-06-22 19:39:47 +00:00
|
|
|
dbus_connection_free_data_slot (&connection_data_slot);
|
2003-03-13 03:52:58 +00:00
|
|
|
}
|
2003-01-06 01:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
2003-03-13 03:52:58 +00:00
|
|
|
bus_connections_setup_connection (BusConnections *connections,
|
|
|
|
|
DBusConnection *connection)
|
2003-01-06 01:08:14 +00:00
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
dbus_bool_t retval;
|
|
|
|
|
|
2003-01-14 11:19:06 +00:00
|
|
|
d = dbus_new0 (BusConnectionData, 1);
|
|
|
|
|
|
2003-01-06 01:08:14 +00:00
|
|
|
if (d == NULL)
|
|
|
|
|
return FALSE;
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
d->connections = connections;
|
2003-03-13 00:56:43 +00:00
|
|
|
d->connection = connection;
|
2003-05-12 02:44:45 +00:00
|
|
|
|
2003-04-24 21:26:25 +00:00
|
|
|
_dbus_get_current_time (&d->connection_tv_sec,
|
|
|
|
|
&d->connection_tv_usec);
|
|
|
|
|
|
2003-03-17 05:39:10 +00:00
|
|
|
_dbus_assert (connection_data_slot >= 0);
|
2003-01-06 01:08:14 +00:00
|
|
|
|
|
|
|
|
if (!dbus_connection_set_data (connection,
|
|
|
|
|
connection_data_slot,
|
|
|
|
|
d, free_connection_data))
|
|
|
|
|
{
|
|
|
|
|
dbus_free (d);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
|
|
|
|
|
retval = FALSE;
|
2003-01-06 01:08:14 +00:00
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
if (!dbus_connection_set_watch_functions (connection,
|
2003-04-04 00:39:22 +00:00
|
|
|
add_connection_watch,
|
|
|
|
|
remove_connection_watch,
|
2003-03-15 20:47:16 +00:00
|
|
|
NULL,
|
2003-03-14 01:27:58 +00:00
|
|
|
connection,
|
|
|
|
|
NULL))
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
goto out;
|
2003-03-14 01:27:58 +00:00
|
|
|
|
|
|
|
|
if (!dbus_connection_set_timeout_functions (connection,
|
2003-04-04 00:39:22 +00:00
|
|
|
add_connection_timeout,
|
|
|
|
|
remove_connection_timeout,
|
2003-03-15 20:47:16 +00:00
|
|
|
NULL,
|
2003-03-14 01:27:58 +00:00
|
|
|
connection, NULL))
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
goto out;
|
2003-04-19 16:16:24 +00:00
|
|
|
|
2003-03-24 17:30:47 +00:00
|
|
|
dbus_connection_set_unix_user_function (connection,
|
|
|
|
|
allow_user_function,
|
|
|
|
|
NULL, NULL);
|
2003-04-09 22:15:05 +00:00
|
|
|
|
|
|
|
|
dbus_connection_set_dispatch_status_function (connection,
|
|
|
|
|
dispatch_status_function,
|
|
|
|
|
bus_context_get_loop (connections->context),
|
|
|
|
|
NULL);
|
2003-04-19 16:16:24 +00:00
|
|
|
|
|
|
|
|
d->link_in_connection_list = _dbus_list_alloc_link (connection);
|
|
|
|
|
if (d->link_in_connection_list == NULL)
|
|
|
|
|
goto out;
|
2003-01-06 01:08:14 +00:00
|
|
|
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
/* Setup the connection with the dispatcher */
|
|
|
|
|
if (!bus_dispatch_add_connection (connection))
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
goto out;
|
2003-04-09 22:15:05 +00:00
|
|
|
|
|
|
|
|
if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
|
|
|
|
|
{
|
|
|
|
|
if (!_dbus_loop_queue_dispatch (bus_context_get_loop (connections->context), connection))
|
|
|
|
|
{
|
|
|
|
|
bus_dispatch_remove_connection (connection);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-19 16:16:24 +00:00
|
|
|
|
|
|
|
|
_dbus_list_append_link (&connections->incomplete, d->link_in_connection_list);
|
|
|
|
|
connections->n_incomplete += 1;
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
dbus_connection_ref (connection);
|
2003-04-19 16:16:24 +00:00
|
|
|
|
|
|
|
|
/* Note that we might disconnect ourselves here, but it only takes
|
2003-04-24 21:26:25 +00:00
|
|
|
* effect on return to the main loop. We call this to free up
|
|
|
|
|
* expired connections if possible, and to queue the timeout for our
|
|
|
|
|
* own expiration.
|
|
|
|
|
*/
|
|
|
|
|
bus_connections_expire_incomplete (connections);
|
|
|
|
|
|
|
|
|
|
/* And we might also disconnect ourselves here, but again it
|
|
|
|
|
* only takes effect on return to main loop.
|
2003-04-19 16:16:24 +00:00
|
|
|
*/
|
|
|
|
|
if (connections->n_incomplete >
|
|
|
|
|
bus_context_get_max_incomplete_connections (connections->context))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Number of incomplete connections exceeds max, dropping oldest one\n");
|
|
|
|
|
|
|
|
|
|
_dbus_assert (connections->incomplete != NULL);
|
|
|
|
|
/* Disconnect the oldest unauthenticated connection. FIXME
|
|
|
|
|
* would it be more secure to drop a *random* connection? This
|
|
|
|
|
* algorithm seems to mean that if someone can create new
|
|
|
|
|
* connections quickly enough, they can keep anyone else from
|
|
|
|
|
* completing authentication. But random may or may not really
|
|
|
|
|
* help with that, a more elaborate solution might be required.
|
|
|
|
|
*/
|
|
|
|
|
dbus_connection_disconnect (connections->incomplete->data);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (!retval)
|
2003-04-19 16:16:24 +00:00
|
|
|
{
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
if (!dbus_connection_set_watch_functions (connection,
|
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
|
connection,
|
|
|
|
|
NULL))
|
|
|
|
|
_dbus_assert_not_reached ("setting watch functions to NULL failed");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_set_timeout_functions (connection,
|
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
|
connection,
|
|
|
|
|
NULL))
|
|
|
|
|
_dbus_assert_not_reached ("setting timeout functions to NULL failed");
|
2003-03-24 17:30:47 +00:00
|
|
|
|
|
|
|
|
dbus_connection_set_unix_user_function (connection,
|
|
|
|
|
NULL, NULL, NULL);
|
2003-04-04 00:39:22 +00:00
|
|
|
|
2003-04-09 22:15:05 +00:00
|
|
|
dbus_connection_set_dispatch_status_function (connection,
|
|
|
|
|
NULL, NULL, NULL);
|
2003-04-19 16:16:24 +00:00
|
|
|
|
|
|
|
|
if (d->link_in_connection_list != NULL)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (d->link_in_connection_list->next == NULL);
|
|
|
|
|
_dbus_assert (d->link_in_connection_list->prev == NULL);
|
|
|
|
|
_dbus_list_free_link (d->link_in_connection_list);
|
2003-05-12 02:44:45 +00:00
|
|
|
d->link_in_connection_list = NULL;
|
2003-04-19 16:16:24 +00:00
|
|
|
}
|
2003-05-12 02:44:45 +00:00
|
|
|
|
|
|
|
|
if (!dbus_connection_set_data (connection,
|
|
|
|
|
connection_data_slot,
|
|
|
|
|
NULL, NULL))
|
|
|
|
|
_dbus_assert_not_reached ("failed to set connection data to null");
|
|
|
|
|
|
|
|
|
|
/* "d" has now been freed */
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
}
|
2003-01-21 12:42:33 +00:00
|
|
|
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
return retval;
|
2003-01-06 01:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-24 21:26:25 +00:00
|
|
|
void
|
|
|
|
|
bus_connections_expire_incomplete (BusConnections *connections)
|
|
|
|
|
{
|
|
|
|
|
int next_interval;
|
|
|
|
|
|
|
|
|
|
next_interval = -1;
|
|
|
|
|
|
2003-04-25 23:50:34 +00:00
|
|
|
if (connections->incomplete != NULL)
|
2003-04-24 21:26:25 +00:00
|
|
|
{
|
2003-04-25 23:50:34 +00:00
|
|
|
long tv_sec, tv_usec;
|
|
|
|
|
DBusList *link;
|
|
|
|
|
int auth_timeout;
|
2003-04-24 21:26:25 +00:00
|
|
|
|
2003-04-25 23:50:34 +00:00
|
|
|
_dbus_get_current_time (&tv_sec, &tv_usec);
|
|
|
|
|
auth_timeout = bus_context_get_auth_timeout (connections->context);
|
|
|
|
|
|
|
|
|
|
link = _dbus_list_get_first_link (&connections->incomplete);
|
|
|
|
|
while (link != NULL)
|
|
|
|
|
{
|
|
|
|
|
DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
|
|
|
|
|
DBusConnection *connection;
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
double elapsed;
|
2003-04-24 21:26:25 +00:00
|
|
|
|
2003-04-25 23:50:34 +00:00
|
|
|
connection = link->data;
|
2003-04-24 21:26:25 +00:00
|
|
|
|
2003-04-25 23:50:34 +00:00
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
2003-04-24 21:26:25 +00:00
|
|
|
|
2003-04-25 23:50:34 +00:00
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
elapsed = ((double) tv_sec - (double) d->connection_tv_sec) * 1000.0 +
|
|
|
|
|
((double) tv_usec - (double) d->connection_tv_usec) / 1000.0;
|
2003-04-24 21:26:25 +00:00
|
|
|
|
2003-04-25 23:50:34 +00:00
|
|
|
if (elapsed >= (double) auth_timeout)
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Timing out authentication for connection %p\n", connection);
|
|
|
|
|
dbus_connection_disconnect (connection);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* We can end the loop, since the connections are in oldest-first order */
|
|
|
|
|
next_interval = ((double)auth_timeout) - elapsed;
|
|
|
|
|
_dbus_verbose ("Connection %p authentication expires in %d milliseconds\n",
|
|
|
|
|
connection, next_interval);
|
2003-04-24 21:26:25 +00:00
|
|
|
|
2003-04-25 23:50:34 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2003-04-24 21:26:25 +00:00
|
|
|
|
2003-04-25 23:50:34 +00:00
|
|
|
link = next;
|
|
|
|
|
}
|
2003-04-24 21:26:25 +00:00
|
|
|
}
|
2003-04-25 23:50:34 +00:00
|
|
|
|
2003-04-24 21:26:25 +00:00
|
|
|
if (next_interval >= 0)
|
|
|
|
|
{
|
|
|
|
|
_dbus_timeout_set_interval (connections->expire_timeout,
|
|
|
|
|
next_interval);
|
|
|
|
|
_dbus_timeout_set_enabled (connections->expire_timeout, TRUE);
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("Enabled incomplete connections timeout with interval %d, %d incomplete connections\n",
|
|
|
|
|
next_interval, connections->n_incomplete);
|
|
|
|
|
}
|
2003-04-25 23:50:34 +00:00
|
|
|
else if (dbus_timeout_get_enabled (connections->expire_timeout))
|
2003-04-24 21:26:25 +00:00
|
|
|
{
|
|
|
|
|
_dbus_timeout_set_enabled (connections->expire_timeout, FALSE);
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("Disabled incomplete connections timeout, %d incomplete connections\n",
|
|
|
|
|
connections->n_incomplete);
|
|
|
|
|
}
|
2003-04-25 23:50:34 +00:00
|
|
|
else
|
|
|
|
|
_dbus_verbose ("No need to disable incomplete connections timeout\n");
|
2003-04-24 21:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
expire_incomplete_timeout (void *data)
|
|
|
|
|
{
|
|
|
|
|
BusConnections *connections = data;
|
|
|
|
|
|
2003-04-25 23:50:34 +00:00
|
|
|
_dbus_verbose ("Running %s\n", _DBUS_FUNCTION_NAME);
|
|
|
|
|
|
2003-04-24 21:26:25 +00:00
|
|
|
/* note that this may remove the timeout */
|
|
|
|
|
bus_connections_expire_incomplete (connections);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-23 07:41:54 +00:00
|
|
|
dbus_bool_t
|
2003-04-17 00:46:36 +00:00
|
|
|
bus_connection_get_groups (DBusConnection *connection,
|
|
|
|
|
unsigned long **groups,
|
2003-04-27 06:25:42 +00:00
|
|
|
int *n_groups,
|
|
|
|
|
DBusError *error)
|
2003-03-23 07:41:54 +00:00
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
2003-04-17 00:46:36 +00:00
|
|
|
unsigned long uid;
|
|
|
|
|
DBusUserDatabase *user_database;
|
|
|
|
|
|
2003-03-23 07:41:54 +00:00
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
2003-04-17 00:46:36 +00:00
|
|
|
user_database = bus_context_get_user_database (d->connections->context);
|
|
|
|
|
|
2003-03-23 07:41:54 +00:00
|
|
|
*groups = NULL;
|
|
|
|
|
*n_groups = 0;
|
|
|
|
|
|
2003-04-17 00:46:36 +00:00
|
|
|
if (dbus_connection_get_unix_user (connection, &uid))
|
2003-03-23 07:41:54 +00:00
|
|
|
{
|
2003-04-17 00:46:36 +00:00
|
|
|
if (!_dbus_user_database_get_groups (user_database,
|
|
|
|
|
uid, groups, n_groups,
|
2003-04-27 06:25:42 +00:00
|
|
|
error))
|
2003-03-23 07:41:54 +00:00
|
|
|
{
|
2003-04-27 06:25:42 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
2003-04-17 00:46:36 +00:00
|
|
|
_dbus_verbose ("Did not get any groups for UID %lu\n",
|
|
|
|
|
uid);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Got %d groups for UID %lu\n",
|
|
|
|
|
*n_groups, uid);
|
|
|
|
|
return TRUE;
|
2003-03-23 07:41:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-04-17 00:46:36 +00:00
|
|
|
else
|
|
|
|
|
return TRUE; /* successfully got 0 groups */
|
2003-03-23 07:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_connection_is_in_group (DBusConnection *connection,
|
|
|
|
|
unsigned long gid)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2003-04-17 00:46:36 +00:00
|
|
|
unsigned long *group_ids;
|
2003-03-23 07:41:54 +00:00
|
|
|
int n_group_ids;
|
|
|
|
|
|
2003-04-27 06:25:42 +00:00
|
|
|
if (!bus_connection_get_groups (connection, &group_ids, &n_group_ids,
|
|
|
|
|
NULL))
|
2003-03-23 07:41:54 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < n_group_ids)
|
|
|
|
|
{
|
|
|
|
|
if (group_ids[i] == gid)
|
2003-04-17 00:46:36 +00:00
|
|
|
{
|
|
|
|
|
dbus_free (group_ids);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2003-03-23 07:41:54 +00:00
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-17 00:46:36 +00:00
|
|
|
dbus_free (group_ids);
|
2003-03-23 07:41:54 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-12 18:32:11 +00:00
|
|
|
BusClientPolicy*
|
2003-04-27 06:25:42 +00:00
|
|
|
bus_connection_get_policy (DBusConnection *connection)
|
2003-03-23 07:41:54 +00:00
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d != NULL);
|
2003-04-27 06:25:42 +00:00
|
|
|
_dbus_assert (d->policy != NULL);
|
2003-04-25 23:50:34 +00:00
|
|
|
|
2003-03-23 07:41:54 +00:00
|
|
|
return d->policy;
|
|
|
|
|
}
|
2003-03-13 03:52:58 +00:00
|
|
|
|
2003-04-19 16:16:24 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
foreach_active (BusConnections *connections,
|
|
|
|
|
BusConnectionForeachFunction function,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
DBusList *link;
|
|
|
|
|
|
|
|
|
|
link = _dbus_list_get_first_link (&connections->completed);
|
|
|
|
|
while (link != NULL)
|
|
|
|
|
{
|
|
|
|
|
DBusConnection *connection = link->data;
|
|
|
|
|
DBusList *next = _dbus_list_get_next_link (&connections->completed, link);
|
|
|
|
|
|
|
|
|
|
if (!(* function) (connection, data))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
link = next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
foreach_inactive (BusConnections *connections,
|
|
|
|
|
BusConnectionForeachFunction function,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
DBusList *link;
|
|
|
|
|
|
|
|
|
|
link = _dbus_list_get_first_link (&connections->incomplete);
|
|
|
|
|
while (link != NULL)
|
|
|
|
|
{
|
|
|
|
|
DBusConnection *connection = link->data;
|
|
|
|
|
DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
|
|
|
|
|
|
|
|
|
|
if (!(* function) (connection, data))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
link = next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calls function on each active connection; if the function returns
|
|
|
|
|
* #FALSE, stops iterating. Active connections are authenticated
|
|
|
|
|
* and have sent a Hello message.
|
|
|
|
|
*
|
|
|
|
|
* @param connections the connections object
|
|
|
|
|
* @param function the function
|
|
|
|
|
* @param data data to pass to it as a second arg
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
bus_connections_foreach_active (BusConnections *connections,
|
|
|
|
|
BusConnectionForeachFunction function,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
foreach_active (connections, function, data);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
/**
|
|
|
|
|
* Calls function on each connection; if the function returns
|
|
|
|
|
* #FALSE, stops iterating.
|
|
|
|
|
*
|
|
|
|
|
* @param connections the connections object
|
|
|
|
|
* @param function the function
|
|
|
|
|
* @param data data to pass to it as a second arg
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
bus_connections_foreach (BusConnections *connections,
|
|
|
|
|
BusConnectionForeachFunction function,
|
2003-04-19 16:16:24 +00:00
|
|
|
void *data)
|
2003-03-13 03:52:58 +00:00
|
|
|
{
|
2003-04-19 16:16:24 +00:00
|
|
|
if (!foreach_active (connections, function, data))
|
|
|
|
|
return;
|
2003-03-13 03:52:58 +00:00
|
|
|
|
2003-04-19 16:16:24 +00:00
|
|
|
foreach_inactive (connections, function, data);
|
2003-03-13 03:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BusContext*
|
|
|
|
|
bus_connections_get_context (BusConnections *connections)
|
|
|
|
|
{
|
|
|
|
|
return connections->context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BusContext*
|
|
|
|
|
bus_connection_get_context (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
return d->connections->context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BusConnections*
|
|
|
|
|
bus_connection_get_connections (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
return d->connections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BusRegistry*
|
|
|
|
|
bus_connection_get_registry (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
return bus_context_get_registry (d->connections->context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BusActivation*
|
|
|
|
|
bus_connection_get_activation (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
return bus_context_get_activation (d->connections->context);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
/**
|
|
|
|
|
* Checks whether the connection is registered with the message bus.
|
|
|
|
|
*
|
|
|
|
|
* @param connection the connection
|
|
|
|
|
* @returns #TRUE if we're an active message bus participant
|
|
|
|
|
*/
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_connection_is_active (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
|
|
|
|
|
return d != NULL && d->name != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_connection_preallocate_oom_error (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusPreallocatedSend *preallocated;
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
if (d->oom_preallocated != NULL)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
preallocated = dbus_connection_preallocate_send (connection);
|
|
|
|
|
if (preallocated == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_connection_free_preallocated_send (connection, preallocated);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
/* d->name may be NULL, but that is OK */
|
|
|
|
|
if (!dbus_message_set_name (message, DBUS_ERROR_NO_MEMORY) ||
|
|
|
|
|
!dbus_message_set_destination (message, d->name) ||
|
|
|
|
|
!dbus_message_set_sender (message,
|
2003-03-20 07:57:39 +00:00
|
|
|
DBUS_SERVICE_DBUS))
|
|
|
|
|
{
|
|
|
|
|
dbus_connection_free_preallocated_send (connection, preallocated);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-15 20:47:16 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
/* set reply serial to placeholder value just so space is already allocated
|
|
|
|
|
* for it.
|
|
|
|
|
*/
|
|
|
|
|
if (!dbus_message_set_reply_serial (message, 14))
|
|
|
|
|
{
|
|
|
|
|
dbus_connection_free_preallocated_send (connection, preallocated);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d->oom_message = message;
|
|
|
|
|
d->oom_preallocated = preallocated;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_connection_send_oom_error (DBusConnection *connection,
|
|
|
|
|
DBusMessage *in_reply_to)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
_dbus_assert (d->oom_message != NULL);
|
|
|
|
|
|
|
|
|
|
/* should always succeed since we set it to a placeholder earlier */
|
|
|
|
|
if (!dbus_message_set_reply_serial (d->oom_message,
|
|
|
|
|
dbus_message_get_serial (in_reply_to)))
|
|
|
|
|
_dbus_assert_not_reached ("Failed to set reply serial for preallocated oom message");
|
|
|
|
|
|
2003-03-20 07:57:39 +00:00
|
|
|
_dbus_assert (dbus_message_get_sender (d->oom_message) != NULL);
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_connection_send_preallocated (connection, d->oom_preallocated,
|
|
|
|
|
d->oom_message, NULL);
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (d->oom_message);
|
|
|
|
|
d->oom_message = NULL;
|
|
|
|
|
d->oom_preallocated = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-11 00:03:06 +00:00
|
|
|
void
|
|
|
|
|
bus_connection_add_owned_service_link (DBusConnection *connection,
|
|
|
|
|
DBusList *link)
|
2003-01-06 01:08:14 +00:00
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
2003-04-11 00:03:06 +00:00
|
|
|
_dbus_list_append_link (&d->services_owned, link);
|
2003-04-25 23:50:34 +00:00
|
|
|
|
|
|
|
|
d->n_services_owned += 1;
|
2003-04-11 00:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_connection_add_owned_service (DBusConnection *connection,
|
|
|
|
|
BusService *service)
|
|
|
|
|
{
|
|
|
|
|
DBusList *link;
|
|
|
|
|
|
|
|
|
|
link = _dbus_list_alloc_link (service);
|
|
|
|
|
|
|
|
|
|
if (link == NULL)
|
2003-01-06 01:08:14 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
2003-04-11 00:03:06 +00:00
|
|
|
bus_connection_add_owned_service_link (connection, link);
|
|
|
|
|
|
2003-01-06 01:08:14 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_connection_remove_owned_service (DBusConnection *connection,
|
|
|
|
|
BusService *service)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
_dbus_list_remove_last (&d->services_owned, service);
|
2003-04-25 23:50:34 +00:00
|
|
|
|
|
|
|
|
d->n_services_owned -= 1;
|
|
|
|
|
_dbus_assert (d->n_services_owned >= 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
bus_connection_get_n_services_owned (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
return d->n_services_owned;
|
2003-01-06 01:08:14 +00:00
|
|
|
}
|
2003-01-21 12:42:33 +00:00
|
|
|
|
|
|
|
|
dbus_bool_t
|
2003-04-27 06:25:42 +00:00
|
|
|
bus_connection_complete (DBusConnection *connection,
|
|
|
|
|
const DBusString *name,
|
|
|
|
|
DBusError *error)
|
2003-01-21 12:42:33 +00:00
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
2003-04-19 16:16:24 +00:00
|
|
|
unsigned long uid;
|
2003-01-21 12:42:33 +00:00
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
_dbus_assert (d->name == NULL);
|
2003-04-27 06:25:42 +00:00
|
|
|
_dbus_assert (d->policy == NULL);
|
2003-04-19 16:16:24 +00:00
|
|
|
|
2003-03-31 20:56:29 +00:00
|
|
|
if (!_dbus_string_copy_data (name, &d->name))
|
2003-04-27 06:25:42 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-21 12:42:33 +00:00
|
|
|
|
2003-03-31 20:56:29 +00:00
|
|
|
_dbus_assert (d->name != NULL);
|
|
|
|
|
|
2003-03-16 21:01:57 +00:00
|
|
|
_dbus_verbose ("Name %s assigned to %p\n", d->name, connection);
|
2003-04-19 16:16:24 +00:00
|
|
|
|
2003-04-27 06:25:42 +00:00
|
|
|
d->policy = bus_context_create_client_policy (d->connections->context,
|
|
|
|
|
connection,
|
|
|
|
|
error);
|
|
|
|
|
|
|
|
|
|
/* we may have a NULL policy on OOM or error getting list of
|
|
|
|
|
* groups for a user. In the latter case we don't handle it so
|
|
|
|
|
* well currently, as it will just keep failing over and over.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (d->policy == NULL)
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Failed to create security policy for connection %p\n",
|
|
|
|
|
connection);
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
|
|
|
|
dbus_free (d->name);
|
|
|
|
|
d->name = NULL;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-19 16:16:24 +00:00
|
|
|
if (dbus_connection_get_unix_user (connection, &uid))
|
|
|
|
|
{
|
|
|
|
|
if (!adjust_connections_for_uid (d->connections,
|
|
|
|
|
uid, 1))
|
|
|
|
|
{
|
2003-04-27 06:25:42 +00:00
|
|
|
BUS_SET_OOM (error);
|
2003-04-19 16:16:24 +00:00
|
|
|
dbus_free (d->name);
|
|
|
|
|
d->name = NULL;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now the connection is active, move it between lists */
|
|
|
|
|
_dbus_list_unlink (&d->connections->incomplete,
|
|
|
|
|
d->link_in_connection_list);
|
|
|
|
|
d->connections->n_incomplete -= 1;
|
|
|
|
|
_dbus_list_append_link (&d->connections->completed,
|
|
|
|
|
d->link_in_connection_list);
|
|
|
|
|
d->connections->n_completed += 1;
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d->connections->n_incomplete >= 0);
|
|
|
|
|
_dbus_assert (d->connections->n_completed > 0);
|
2003-04-25 23:50:34 +00:00
|
|
|
|
|
|
|
|
/* See if we can remove the timeout */
|
|
|
|
|
bus_connections_expire_incomplete (d->connections);
|
2003-03-16 21:01:57 +00:00
|
|
|
|
2003-01-21 12:42:33 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
bus_connection_get_name (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
return d->name;
|
|
|
|
|
}
|
2003-01-24 23:51:59 +00:00
|
|
|
|
2003-04-19 16:16:24 +00:00
|
|
|
/**
|
|
|
|
|
* Check whether completing the passed-in connection would
|
|
|
|
|
* exceed limits, and if so set error and return #FALSE
|
|
|
|
|
*/
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_connections_check_limits (BusConnections *connections,
|
|
|
|
|
DBusConnection *requesting_completion,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
unsigned long uid;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (requesting_completion);
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d->name == NULL);
|
|
|
|
|
|
|
|
|
|
if (connections->n_completed >=
|
|
|
|
|
bus_context_get_max_completed_connections (connections->context))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
|
|
|
|
|
"The maximum number of active connections has been reached");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dbus_connection_get_unix_user (requesting_completion, &uid))
|
|
|
|
|
{
|
|
|
|
|
if (get_connections_for_uid (connections, uid) >=
|
|
|
|
|
bus_context_get_max_connections_per_user (connections->context))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
|
|
|
|
|
"The maximum number of active connections for UID %lu has been reached",
|
|
|
|
|
uid);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-18 04:18:57 +00:00
|
|
|
/*
|
2003-04-11 00:03:06 +00:00
|
|
|
* Transactions
|
|
|
|
|
*
|
|
|
|
|
* Note that this is fairly fragile; in particular, don't try to use
|
|
|
|
|
* one transaction across any main loop iterations.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
BusTransaction *transaction;
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusPreallocatedSend *preallocated;
|
|
|
|
|
} MessageToSend;
|
|
|
|
|
|
2003-04-11 00:03:06 +00:00
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
BusTransactionCancelFunction cancel_function;
|
|
|
|
|
DBusFreeFunction free_data_function;
|
|
|
|
|
void *data;
|
|
|
|
|
} CancelHook;
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
struct BusTransaction
|
|
|
|
|
{
|
|
|
|
|
DBusList *connections;
|
2003-03-13 03:52:58 +00:00
|
|
|
BusContext *context;
|
2003-04-11 00:03:06 +00:00
|
|
|
DBusList *cancel_hooks;
|
2003-03-13 00:56:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
message_to_send_free (DBusConnection *connection,
|
|
|
|
|
MessageToSend *to_send)
|
|
|
|
|
{
|
|
|
|
|
if (to_send->message)
|
|
|
|
|
dbus_message_unref (to_send->message);
|
|
|
|
|
|
|
|
|
|
if (to_send->preallocated)
|
|
|
|
|
dbus_connection_free_preallocated_send (connection, to_send->preallocated);
|
|
|
|
|
|
|
|
|
|
dbus_free (to_send);
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-11 00:03:06 +00:00
|
|
|
static void
|
|
|
|
|
cancel_hook_cancel (void *element,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
CancelHook *ch = element;
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("Running transaction cancel hook\n");
|
|
|
|
|
|
|
|
|
|
if (ch->cancel_function)
|
|
|
|
|
(* ch->cancel_function) (ch->data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
cancel_hook_free (void *element,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
CancelHook *ch = element;
|
|
|
|
|
|
|
|
|
|
if (ch->free_data_function)
|
|
|
|
|
(* ch->free_data_function) (ch->data);
|
|
|
|
|
|
|
|
|
|
dbus_free (ch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
free_cancel_hooks (BusTransaction *transaction)
|
|
|
|
|
{
|
|
|
|
|
_dbus_list_foreach (&transaction->cancel_hooks,
|
|
|
|
|
cancel_hook_free, NULL);
|
|
|
|
|
|
|
|
|
|
_dbus_list_clear (&transaction->cancel_hooks);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
BusTransaction*
|
2003-03-13 03:52:58 +00:00
|
|
|
bus_transaction_new (BusContext *context)
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
BusTransaction *transaction;
|
|
|
|
|
|
|
|
|
|
transaction = dbus_new0 (BusTransaction, 1);
|
|
|
|
|
if (transaction == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
transaction->context = context;
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
return transaction;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
BusContext*
|
|
|
|
|
bus_transaction_get_context (BusTransaction *transaction)
|
|
|
|
|
{
|
|
|
|
|
return transaction->context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BusConnections*
|
|
|
|
|
bus_transaction_get_connections (BusTransaction *transaction)
|
|
|
|
|
{
|
|
|
|
|
return bus_context_get_connections (transaction->context);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_bool_t
|
2003-04-14 02:29:21 +00:00
|
|
|
bus_transaction_send_from_driver (BusTransaction *transaction,
|
|
|
|
|
DBusConnection *connection,
|
|
|
|
|
DBusMessage *message)
|
|
|
|
|
{
|
|
|
|
|
/* We have to set the sender to the driver, and have
|
|
|
|
|
* to check security policy since it was not done in
|
|
|
|
|
* dispatch.c
|
|
|
|
|
*/
|
|
|
|
|
_dbus_verbose ("Sending %s from driver\n",
|
|
|
|
|
dbus_message_get_name (message));
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* If security policy doesn't allow the message, we silently
|
|
|
|
|
* eat it; the driver doesn't care about getting a reply.
|
|
|
|
|
*/
|
|
|
|
|
if (!bus_context_check_security_policy (bus_transaction_get_context (transaction),
|
|
|
|
|
NULL, connection, message, NULL))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return bus_transaction_send (transaction, connection, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_transaction_send (BusTransaction *transaction,
|
|
|
|
|
DBusConnection *connection,
|
|
|
|
|
DBusMessage *message)
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
MessageToSend *to_send;
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
DBusList *link;
|
|
|
|
|
|
2003-04-10 05:12:19 +00:00
|
|
|
_dbus_verbose (" trying to add %s %s to transaction%s\n",
|
2003-08-11 02:11:58 +00:00
|
|
|
dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR ? "error" :
|
2003-04-17 04:25:45 +00:00
|
|
|
dbus_message_get_reply_serial (message) != 0 ? "reply" :
|
2003-04-10 05:12:19 +00:00
|
|
|
"message",
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
dbus_message_get_name (message),
|
|
|
|
|
dbus_connection_get_is_connected (connection) ?
|
|
|
|
|
"" : " (disconnected)");
|
2003-03-20 07:57:39 +00:00
|
|
|
|
|
|
|
|
_dbus_assert (dbus_message_get_sender (message) != NULL);
|
2003-03-15 20:47:16 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!dbus_connection_get_is_connected (connection))
|
|
|
|
|
return TRUE; /* silently ignore disconnected connections */
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
to_send = dbus_new (MessageToSend, 1);
|
|
|
|
|
if (to_send == NULL)
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
to_send->preallocated = dbus_connection_preallocate_send (connection);
|
|
|
|
|
if (to_send->preallocated == NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_free (to_send);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_ref (message);
|
|
|
|
|
to_send->message = message;
|
|
|
|
|
to_send->transaction = transaction;
|
|
|
|
|
|
2003-03-16 21:01:57 +00:00
|
|
|
_dbus_verbose ("about to prepend message\n");
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!_dbus_list_prepend (&d->transaction_messages, to_send))
|
|
|
|
|
{
|
|
|
|
|
message_to_send_free (connection, to_send);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-16 21:01:57 +00:00
|
|
|
|
|
|
|
|
_dbus_verbose ("prepended message\n");
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
/* See if we already had this connection in the list
|
|
|
|
|
* for this transaction. If we have a pending message,
|
|
|
|
|
* then we should already be in transaction->connections
|
|
|
|
|
*/
|
|
|
|
|
link = _dbus_list_get_first_link (&d->transaction_messages);
|
|
|
|
|
_dbus_assert (link->data == to_send);
|
|
|
|
|
link = _dbus_list_get_next_link (&d->transaction_messages, link);
|
|
|
|
|
while (link != NULL)
|
|
|
|
|
{
|
|
|
|
|
MessageToSend *m = link->data;
|
|
|
|
|
DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
|
|
|
|
|
|
|
|
|
|
if (m->transaction == transaction)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
link = next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (link == NULL)
|
|
|
|
|
{
|
|
|
|
|
if (!_dbus_list_prepend (&transaction->connections, connection))
|
|
|
|
|
{
|
|
|
|
|
_dbus_list_remove (&d->transaction_messages, to_send);
|
|
|
|
|
message_to_send_free (connection, to_send);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
connection_cancel_transaction (DBusConnection *connection,
|
|
|
|
|
BusTransaction *transaction)
|
|
|
|
|
{
|
|
|
|
|
DBusList *link;
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
link = _dbus_list_get_first_link (&d->transaction_messages);
|
|
|
|
|
while (link != NULL)
|
|
|
|
|
{
|
|
|
|
|
MessageToSend *m = link->data;
|
|
|
|
|
DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
|
|
|
|
|
|
|
|
|
|
if (m->transaction == transaction)
|
|
|
|
|
{
|
|
|
|
|
_dbus_list_remove_link (&d->transaction_messages,
|
|
|
|
|
link);
|
|
|
|
|
|
|
|
|
|
message_to_send_free (connection, m);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
link = next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_transaction_cancel_and_free (BusTransaction *transaction)
|
|
|
|
|
{
|
|
|
|
|
DBusConnection *connection;
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
|
|
|
|
|
_dbus_verbose ("TRANSACTION: cancelled\n");
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
while ((connection = _dbus_list_pop_first (&transaction->connections)))
|
|
|
|
|
connection_cancel_transaction (connection, transaction);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (transaction->connections == NULL);
|
|
|
|
|
|
2003-04-11 00:03:06 +00:00
|
|
|
_dbus_list_foreach (&transaction->cancel_hooks,
|
|
|
|
|
cancel_hook_cancel, NULL);
|
|
|
|
|
|
|
|
|
|
free_cancel_hooks (transaction);
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_free (transaction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
connection_execute_transaction (DBusConnection *connection,
|
|
|
|
|
BusTransaction *transaction)
|
|
|
|
|
{
|
|
|
|
|
DBusList *link;
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
/* Send the queue in order (FIFO) */
|
|
|
|
|
link = _dbus_list_get_last_link (&d->transaction_messages);
|
|
|
|
|
while (link != NULL)
|
|
|
|
|
{
|
|
|
|
|
MessageToSend *m = link->data;
|
|
|
|
|
DBusList *prev = _dbus_list_get_prev_link (&d->transaction_messages, link);
|
|
|
|
|
|
|
|
|
|
if (m->transaction == transaction)
|
|
|
|
|
{
|
|
|
|
|
_dbus_list_remove_link (&d->transaction_messages,
|
|
|
|
|
link);
|
|
|
|
|
|
2003-03-20 07:57:39 +00:00
|
|
|
_dbus_assert (dbus_message_get_sender (m->message) != NULL);
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_connection_send_preallocated (connection,
|
|
|
|
|
m->preallocated,
|
|
|
|
|
m->message,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
m->preallocated = NULL; /* so we don't double-free it */
|
|
|
|
|
|
|
|
|
|
message_to_send_free (connection, m);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
link = prev;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_transaction_execute_and_free (BusTransaction *transaction)
|
|
|
|
|
{
|
|
|
|
|
/* For each connection in transaction->connections
|
|
|
|
|
* send the messages
|
|
|
|
|
*/
|
|
|
|
|
DBusConnection *connection;
|
2003-03-16 Havoc Pennington <hp@pobox.com>
Oops - test code was only testing failure of around 30 of the
mallocs in the test path, but it turns out there are 500+
mallocs. I believe this was due to misguided linking setup such
that there was one copy of dbus_malloc etc. in the daemon and one
in the shared lib, and only daemon mallocs were tested. In any
case, the test case now tests all 500+ mallocs, and doesn't pass
yet, though there are lots of fixes in this patch.
* dbus/dbus-connection.c (dbus_connection_dispatch_message): fix
this so that it doesn't need to allocate memory, since it
has no way of indicating failure due to OOM (and would be
annoying if it did).
* dbus/dbus-list.c (_dbus_list_pop_first_link): new function
* bus/Makefile.am: rearrange to create two self-contained
libraries, to avoid having libraries with overlapping symbols.
that was resulting in weirdness, e.g. I'm pretty sure there
were two copies of global static variables.
* dbus/dbus-internals.c: move the malloc debug stuff to
dbus-memory.c
* dbus/dbus-list.c (free_link): free list mempool if it becomes
empty.
* dbus/dbus-memory.c (_dbus_disable_mem_pools): new function
* dbus/dbus-address.c (dbus_parse_address): free list nodes
on failure.
* bus/dispatch.c (bus_dispatch_add_connection): free
message_handler_slot when no longer using it, so
memory leak checkers are happy for the test suite.
* dbus/dbus-server-debug-pipe.c (debug_finalize): free server name
* bus/bus.c (new_connection_callback): disconnect in here if
bus_connections_setup_connection fails.
* bus/connection.c (bus_connections_unref): fix to free the
connections
(bus_connections_setup_connection): if this fails, don't
disconnect the connection, just be sure there are no side
effects.
* dbus/dbus-string.c (undo_alignment): unbreak this
* dbus/dbus-auth.c (_dbus_auth_unref): free some stuff we were
leaking
(_dbus_auth_new): fix the order in which we free strings
on OOM failure
* bus/connection.c (bus_connection_disconnected): fix to
not send ServiceDeleted multiple times in case of memory
allocation failure
* dbus/dbus-bus.c (dbus_bus_get_base_service): new function to
get the base service name
(dbus_bus_register_client): don't return base service name,
instead store it on the DBusConnection and have an accessor
function for it.
(dbus_bus_register_client): rename dbus_bus_register()
* bus/dispatch.c (check_hello_message): verify that other
connections on the bus also got the correct results, not
just the one sending hello
2003-03-16 08:08:21 +00:00
|
|
|
|
|
|
|
|
_dbus_verbose ("TRANSACTION: executing\n");
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
while ((connection = _dbus_list_pop_first (&transaction->connections)))
|
|
|
|
|
connection_execute_transaction (connection, transaction);
|
|
|
|
|
|
|
|
|
|
_dbus_assert (transaction->connections == NULL);
|
|
|
|
|
|
2003-04-11 00:03:06 +00:00
|
|
|
free_cancel_hooks (transaction);
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_free (transaction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bus_connection_remove_transactions (DBusConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
MessageToSend *to_send;
|
|
|
|
|
BusConnectionData *d;
|
|
|
|
|
|
|
|
|
|
d = BUS_CONNECTION_DATA (connection);
|
|
|
|
|
_dbus_assert (d != NULL);
|
|
|
|
|
|
|
|
|
|
while ((to_send = _dbus_list_get_first (&d->transaction_messages)))
|
|
|
|
|
{
|
|
|
|
|
/* only has an effect for the first MessageToSend listing this transaction */
|
|
|
|
|
_dbus_list_remove (&to_send->transaction->connections,
|
|
|
|
|
connection);
|
|
|
|
|
|
|
|
|
|
_dbus_list_remove (&d->transaction_messages, to_send);
|
|
|
|
|
message_to_send_free (connection, to_send);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts the DBusError to a message reply
|
|
|
|
|
*/
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_transaction_send_error_reply (BusTransaction *transaction,
|
|
|
|
|
DBusConnection *connection,
|
|
|
|
|
const DBusError *error,
|
|
|
|
|
DBusMessage *in_reply_to)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *reply;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
_dbus_assert (error != NULL);
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
2003-04-27 06:25:42 +00:00
|
|
|
|
|
|
|
|
_dbus_verbose ("Sending error reply %s \"%s\"\n",
|
|
|
|
|
error->name, error->message);
|
|
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
reply = dbus_message_new_error (in_reply_to,
|
|
|
|
|
error->name,
|
|
|
|
|
error->message);
|
2003-03-13 00:56:43 +00:00
|
|
|
if (reply == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2003-04-14 02:29:21 +00:00
|
|
|
if (!bus_transaction_send_from_driver (transaction, connection, reply))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-02 20:14:52 +00:00
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
return TRUE;
|
2003-01-24 23:51:59 +00:00
|
|
|
}
|
2003-04-11 00:03:06 +00:00
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_transaction_add_cancel_hook (BusTransaction *transaction,
|
|
|
|
|
BusTransactionCancelFunction cancel_function,
|
|
|
|
|
void *data,
|
|
|
|
|
DBusFreeFunction free_data_function)
|
|
|
|
|
{
|
|
|
|
|
CancelHook *ch;
|
|
|
|
|
|
|
|
|
|
ch = dbus_new (CancelHook, 1);
|
|
|
|
|
if (ch == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
ch->cancel_function = cancel_function;
|
|
|
|
|
ch->data = data;
|
|
|
|
|
ch->free_data_function = free_data_function;
|
|
|
|
|
|
|
|
|
|
/* It's important that the hooks get run in reverse order that they
|
|
|
|
|
* were added
|
|
|
|
|
*/
|
|
|
|
|
if (!_dbus_list_prepend (&transaction->cancel_hooks, ch))
|
|
|
|
|
{
|
|
|
|
|
dbus_free (ch);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|