1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* connection.c Client connections
4 * Copyright (C) 2003 Red Hat, Inc.
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "connection.h"
29 #include "expirelist.h"
31 #include <dbus/dbus-list.h>
32 #include <dbus/dbus-hash.h>
33 #include <dbus/dbus-timeout.h>
34 #include <dbus/dbus-userdb.h>
36 static void bus_connection_remove_transactions (DBusConnection *connection);
40 BusExpireItem expire_item;
42 DBusConnection *will_get_reply;
43 DBusConnection *will_send_reply;
45 dbus_uint32_t reply_serial;
52 DBusList *completed; /**< List of all completed connections */
53 int n_completed; /**< Length of completed list */
54 DBusList *incomplete; /**< List of all not-yet-active connections */
55 int n_incomplete; /**< Length of incomplete list */
57 DBusHashTable *completed_by_user; /**< Number of completed connections for each UID */
58 DBusTimeout *expire_timeout; /**< Timeout for expiring incomplete connections. */
59 int stamp; /**< Incrementing number */
60 BusExpireList *pending_replies; /**< List of pending replies */
63 static dbus_int32_t connection_data_slot = -1;
67 BusConnections *connections;
68 DBusList *link_in_connection_list;
69 DBusConnection *connection;
70 DBusList *services_owned;
72 DBusList *match_rules;
75 DBusList *transaction_messages; /**< Stuff we need to send as part of a transaction */
76 DBusMessage *oom_message;
77 DBusPreallocatedSend *oom_preallocated;
78 BusClientPolicy *policy;
80 BusSELinuxID *selinux_id;
82 long connection_tv_sec; /**< Time when we connected (seconds component) */
83 long connection_tv_usec; /**< Time when we connected (microsec component) */
84 int stamp; /**< connections->stamp last time we were traversed */
87 static dbus_bool_t bus_pending_reply_expired (BusExpireList *list,
91 static void bus_connection_drop_pending_replies (BusConnections *connections,
92 DBusConnection *connection);
94 static dbus_bool_t expire_incomplete_timeout (void *data);
96 #define BUS_CONNECTION_DATA(connection) (dbus_connection_get_data ((connection), connection_data_slot))
99 connection_get_loop (DBusConnection *connection)
101 BusConnectionData *d;
103 d = BUS_CONNECTION_DATA (connection);
105 return bus_context_get_loop (d->connections->context);
110 get_connections_for_uid (BusConnections *connections,
116 /* val is NULL is 0 when it isn't in the hash yet */
118 val = _dbus_hash_table_lookup_ulong (connections->completed_by_user,
121 current_count = _DBUS_POINTER_TO_INT (val);
123 return current_count;
127 adjust_connections_for_uid (BusConnections *connections,
133 current_count = get_connections_for_uid (connections, uid);
135 _dbus_verbose ("Adjusting connection count for UID " DBUS_UID_FORMAT
136 ": was %d adjustment %d making %d\n",
137 uid, current_count, adjustment, current_count + adjustment);
139 _dbus_assert (current_count >= 0);
141 current_count += adjustment;
143 _dbus_assert (current_count >= 0);
145 if (current_count == 0)
147 _dbus_hash_table_remove_ulong (connections->completed_by_user, uid);
154 retval = _dbus_hash_table_insert_ulong (connections->completed_by_user,
155 uid, _DBUS_INT_TO_POINTER (current_count));
157 /* only positive adjustment can fail as otherwise
158 * a hash entry should already exist
160 _dbus_assert (adjustment > 0 ||
161 (adjustment <= 0 && retval));
168 bus_connection_disconnected (DBusConnection *connection)
170 BusConnectionData *d;
172 BusMatchmaker *matchmaker;
174 d = BUS_CONNECTION_DATA (connection);
175 _dbus_assert (d != NULL);
177 _dbus_verbose ("%s disconnected, dropping all service ownership and releasing\n",
178 d->name ? d->name : "(inactive)");
180 /* Delete our match rules */
181 if (d->n_match_rules > 0)
183 matchmaker = bus_context_get_matchmaker (d->connections->context);
184 bus_matchmaker_disconnected (matchmaker, connection);
187 /* Drop any service ownership. Unfortunately, this requires
188 * memory allocation and there doesn't seem to be a good way to
189 * handle it other than sleeping; we can't "fail" the operation of
190 * disconnecting a client, and preallocating a broadcast "service is
191 * now gone" message for every client-service pair seems kind of
194 while ((service = _dbus_list_get_last (&d->services_owned)))
196 BusTransaction *transaction;
201 dbus_error_init (&error);
203 while ((transaction = bus_transaction_new (d->connections->context)) == NULL)
204 _dbus_wait_for_memory ();
206 if (!bus_service_remove_owner (service, connection,
207 transaction, &error))
209 _DBUS_ASSERT_ERROR_IS_SET (&error);
211 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
213 dbus_error_free (&error);
214 bus_transaction_cancel_and_free (transaction);
215 _dbus_wait_for_memory ();
220 _dbus_verbose ("Failed to remove service owner: %s %s\n",
221 error.name, error.message);
222 _dbus_assert_not_reached ("Removing service owner failed for non-memory-related reason");
226 bus_transaction_execute_and_free (transaction);
229 bus_dispatch_remove_connection (connection);
231 /* no more watching */
232 if (!dbus_connection_set_watch_functions (connection,
236 _dbus_assert_not_reached ("setting watch functions to NULL failed");
238 if (!dbus_connection_set_timeout_functions (connection,
242 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
244 dbus_connection_set_unix_user_function (connection,
247 dbus_connection_set_dispatch_status_function (connection,
250 bus_connection_remove_transactions (connection);
252 if (d->link_in_connection_list != NULL)
258 _dbus_list_remove_link (&d->connections->completed, d->link_in_connection_list);
259 d->link_in_connection_list = NULL;
260 d->connections->n_completed -= 1;
262 if (dbus_connection_get_unix_user (connection, &uid))
264 if (!adjust_connections_for_uid (d->connections,
266 _dbus_assert_not_reached ("adjusting downward should never fail");
271 _dbus_list_remove_link (&d->connections->incomplete, d->link_in_connection_list);
272 d->link_in_connection_list = NULL;
273 d->connections->n_incomplete -= 1;
276 _dbus_assert (d->connections->n_incomplete >= 0);
277 _dbus_assert (d->connections->n_completed >= 0);
280 bus_connection_drop_pending_replies (d->connections, connection);
282 /* frees "d" as side effect */
283 dbus_connection_set_data (connection,
284 connection_data_slot,
287 dbus_connection_unref (connection);
291 connection_watch_callback (DBusWatch *watch,
292 unsigned int condition,
295 /* FIXME this can be done in dbus-mainloop.c
296 * if the code in activation.c for the babysitter
297 * watch handler is fixed.
301 _dbus_verbose ("Calling handle_watch\n");
303 return dbus_watch_handle (watch, condition);
307 add_connection_watch (DBusWatch *watch,
310 DBusConnection *connection = data;
312 return _dbus_loop_add_watch (connection_get_loop (connection),
313 watch, connection_watch_callback, connection,
318 remove_connection_watch (DBusWatch *watch,
321 DBusConnection *connection = data;
323 _dbus_loop_remove_watch (connection_get_loop (connection),
324 watch, connection_watch_callback, connection);
328 connection_timeout_callback (DBusTimeout *timeout,
331 /* DBusConnection *connection = data; */
333 /* can return FALSE on OOM but we just let it fire again later */
334 dbus_timeout_handle (timeout);
338 add_connection_timeout (DBusTimeout *timeout,
341 DBusConnection *connection = data;
343 return _dbus_loop_add_timeout (connection_get_loop (connection),
344 timeout, connection_timeout_callback, connection, NULL);
348 remove_connection_timeout (DBusTimeout *timeout,
351 DBusConnection *connection = data;
353 _dbus_loop_remove_timeout (connection_get_loop (connection),
354 timeout, connection_timeout_callback, connection);
358 dispatch_status_function (DBusConnection *connection,
359 DBusDispatchStatus new_status,
362 DBusLoop *loop = data;
364 if (new_status != DBUS_DISPATCH_COMPLETE)
366 while (!_dbus_loop_queue_dispatch (loop, connection))
367 _dbus_wait_for_memory ();
372 allow_user_function (DBusConnection *connection,
376 BusConnectionData *d;
378 d = BUS_CONNECTION_DATA (connection);
380 _dbus_assert (d != NULL);
382 return bus_context_allow_user (d->connections->context, uid);
386 free_connection_data (void *data)
388 BusConnectionData *d = data;
390 /* services_owned should be NULL since we should be disconnected */
391 _dbus_assert (d->services_owned == NULL);
392 _dbus_assert (d->n_services_owned == 0);
394 _dbus_assert (d->transaction_messages == NULL);
396 if (d->oom_preallocated)
397 dbus_connection_free_preallocated_send (d->connection, d->oom_preallocated);
400 dbus_message_unref (d->oom_message);
403 bus_client_policy_unref (d->policy);
406 bus_selinux_id_unref (d->selinux_id);
414 call_timeout_callback (DBusTimeout *timeout,
417 /* can return FALSE on OOM but we just let it fire again later */
418 dbus_timeout_handle (timeout);
422 bus_connections_new (BusContext *context)
424 BusConnections *connections;
426 if (!dbus_connection_allocate_data_slot (&connection_data_slot))
429 connections = dbus_new0 (BusConnections, 1);
430 if (connections == NULL)
433 connections->completed_by_user = _dbus_hash_table_new (DBUS_HASH_ULONG,
435 if (connections->completed_by_user == NULL)
438 connections->expire_timeout = _dbus_timeout_new (100, /* irrelevant */
439 expire_incomplete_timeout,
441 if (connections->expire_timeout == NULL)
444 _dbus_timeout_set_enabled (connections->expire_timeout, FALSE);
446 connections->pending_replies = bus_expire_list_new (bus_context_get_loop (context),
447 bus_context_get_reply_timeout (context),
448 bus_pending_reply_expired,
450 if (connections->pending_replies == NULL)
453 if (!_dbus_loop_add_timeout (bus_context_get_loop (context),
454 connections->expire_timeout,
455 call_timeout_callback, NULL, NULL))
458 connections->refcount = 1;
459 connections->context = context;
464 bus_expire_list_free (connections->pending_replies);
466 _dbus_timeout_unref (connections->expire_timeout);
468 _dbus_hash_table_unref (connections->completed_by_user);
470 dbus_free (connections);
472 dbus_connection_free_data_slot (&connection_data_slot);
478 bus_connections_ref (BusConnections *connections)
480 _dbus_assert (connections->refcount > 0);
481 connections->refcount += 1;
487 bus_connections_unref (BusConnections *connections)
489 _dbus_assert (connections->refcount > 0);
490 connections->refcount -= 1;
491 if (connections->refcount == 0)
493 /* drop all incomplete */
494 while (connections->incomplete != NULL)
496 DBusConnection *connection;
498 connection = connections->incomplete->data;
500 dbus_connection_ref (connection);
501 dbus_connection_close (connection);
502 bus_connection_disconnected (connection);
503 dbus_connection_unref (connection);
506 _dbus_assert (connections->n_incomplete == 0);
508 /* drop all real connections */
509 while (connections->completed != NULL)
511 DBusConnection *connection;
513 connection = connections->completed->data;
515 dbus_connection_ref (connection);
516 dbus_connection_close (connection);
517 bus_connection_disconnected (connection);
518 dbus_connection_unref (connection);
521 _dbus_assert (connections->n_completed == 0);
523 bus_expire_list_free (connections->pending_replies);
525 _dbus_loop_remove_timeout (bus_context_get_loop (connections->context),
526 connections->expire_timeout,
527 call_timeout_callback, NULL);
529 _dbus_timeout_unref (connections->expire_timeout);
531 _dbus_hash_table_unref (connections->completed_by_user);
533 dbus_free (connections);
535 dbus_connection_free_data_slot (&connection_data_slot);
540 bus_connections_setup_connection (BusConnections *connections,
541 DBusConnection *connection)
543 BusConnectionData *d;
547 d = dbus_new0 (BusConnectionData, 1);
552 d->connections = connections;
553 d->connection = connection;
555 _dbus_get_current_time (&d->connection_tv_sec,
556 &d->connection_tv_usec);
558 _dbus_assert (connection_data_slot >= 0);
560 if (!dbus_connection_set_data (connection,
561 connection_data_slot,
562 d, free_connection_data))
568 dbus_connection_set_route_peer_messages (connection, TRUE);
572 dbus_error_init (&error);
573 d->selinux_id = bus_selinux_init_connection_id (connection,
575 if (dbus_error_is_set (&error))
577 /* This is a bit bogus because we pretend all errors
578 * are OOM; this is done because we know that in bus.c
579 * an OOM error disconnects the connection, which is
580 * the same thing we want on any other error.
582 dbus_error_free (&error);
586 if (!dbus_connection_set_watch_functions (connection,
587 add_connection_watch,
588 remove_connection_watch,
594 if (!dbus_connection_set_timeout_functions (connection,
595 add_connection_timeout,
596 remove_connection_timeout,
601 dbus_connection_set_unix_user_function (connection,
605 dbus_connection_set_dispatch_status_function (connection,
606 dispatch_status_function,
607 bus_context_get_loop (connections->context),
610 d->link_in_connection_list = _dbus_list_alloc_link (connection);
611 if (d->link_in_connection_list == NULL)
614 /* Setup the connection with the dispatcher */
615 if (!bus_dispatch_add_connection (connection))
618 if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
620 if (!_dbus_loop_queue_dispatch (bus_context_get_loop (connections->context), connection))
622 bus_dispatch_remove_connection (connection);
627 _dbus_list_append_link (&connections->incomplete, d->link_in_connection_list);
628 connections->n_incomplete += 1;
630 dbus_connection_ref (connection);
632 /* Note that we might disconnect ourselves here, but it only takes
633 * effect on return to the main loop. We call this to free up
634 * expired connections if possible, and to queue the timeout for our
637 bus_connections_expire_incomplete (connections);
639 /* And we might also disconnect ourselves here, but again it
640 * only takes effect on return to main loop.
642 if (connections->n_incomplete >
643 bus_context_get_max_incomplete_connections (connections->context))
645 _dbus_verbose ("Number of incomplete connections exceeds max, dropping oldest one\n");
647 _dbus_assert (connections->incomplete != NULL);
648 /* Disconnect the oldest unauthenticated connection. FIXME
649 * would it be more secure to drop a *random* connection? This
650 * algorithm seems to mean that if someone can create new
651 * connections quickly enough, they can keep anyone else from
652 * completing authentication. But random may or may not really
653 * help with that, a more elaborate solution might be required.
655 dbus_connection_close (connections->incomplete->data);
664 bus_selinux_id_unref (d->selinux_id);
665 d->selinux_id = NULL;
667 if (!dbus_connection_set_watch_functions (connection,
671 _dbus_assert_not_reached ("setting watch functions to NULL failed");
673 if (!dbus_connection_set_timeout_functions (connection,
677 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
679 dbus_connection_set_unix_user_function (connection,
682 dbus_connection_set_dispatch_status_function (connection,
685 if (d->link_in_connection_list != NULL)
687 _dbus_assert (d->link_in_connection_list->next == NULL);
688 _dbus_assert (d->link_in_connection_list->prev == NULL);
689 _dbus_list_free_link (d->link_in_connection_list);
690 d->link_in_connection_list = NULL;
693 if (!dbus_connection_set_data (connection,
694 connection_data_slot,
696 _dbus_assert_not_reached ("failed to set connection data to null");
698 /* "d" has now been freed */
705 bus_connections_expire_incomplete (BusConnections *connections)
711 if (connections->incomplete != NULL)
713 long tv_sec, tv_usec;
717 _dbus_get_current_time (&tv_sec, &tv_usec);
718 auth_timeout = bus_context_get_auth_timeout (connections->context);
720 link = _dbus_list_get_first_link (&connections->incomplete);
723 DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
724 DBusConnection *connection;
725 BusConnectionData *d;
728 connection = link->data;
730 d = BUS_CONNECTION_DATA (connection);
732 _dbus_assert (d != NULL);
734 elapsed = ELAPSED_MILLISECONDS_SINCE (d->connection_tv_sec,
735 d->connection_tv_usec,
738 if (elapsed >= (double) auth_timeout)
740 _dbus_verbose ("Timing out authentication for connection %p\n", connection);
741 dbus_connection_close (connection);
745 /* We can end the loop, since the connections are in oldest-first order */
746 next_interval = ((double)auth_timeout) - elapsed;
747 _dbus_verbose ("Connection %p authentication expires in %d milliseconds\n",
748 connection, next_interval);
757 bus_expire_timeout_set_interval (connections->expire_timeout,
762 expire_incomplete_timeout (void *data)
764 BusConnections *connections = data;
766 _dbus_verbose ("Running %s\n", _DBUS_FUNCTION_NAME);
768 /* note that this may remove the timeout */
769 bus_connections_expire_incomplete (connections);
775 bus_connection_get_groups (DBusConnection *connection,
776 unsigned long **groups,
780 BusConnectionData *d;
783 d = BUS_CONNECTION_DATA (connection);
785 _dbus_assert (d != NULL);
790 if (dbus_connection_get_unix_user (connection, &uid))
792 if (!_dbus_groups_from_uid (uid, groups, n_groups))
794 _dbus_verbose ("Did not get any groups for UID %lu\n",
800 _dbus_verbose ("Got %d groups for UID %lu\n",
806 return TRUE; /* successfully got 0 groups */
810 bus_connection_is_in_group (DBusConnection *connection,
814 unsigned long *group_ids;
817 if (!bus_connection_get_groups (connection, &group_ids, &n_group_ids,
822 while (i < n_group_ids)
824 if (group_ids[i] == gid)
826 dbus_free (group_ids);
832 dbus_free (group_ids);
837 bus_connection_get_policy (DBusConnection *connection)
839 BusConnectionData *d;
841 d = BUS_CONNECTION_DATA (connection);
843 _dbus_assert (d != NULL);
844 _dbus_assert (d->policy != NULL);
850 foreach_active (BusConnections *connections,
851 BusConnectionForeachFunction function,
856 link = _dbus_list_get_first_link (&connections->completed);
859 DBusConnection *connection = link->data;
860 DBusList *next = _dbus_list_get_next_link (&connections->completed, link);
862 if (!(* function) (connection, data))
872 foreach_inactive (BusConnections *connections,
873 BusConnectionForeachFunction function,
878 link = _dbus_list_get_first_link (&connections->incomplete);
881 DBusConnection *connection = link->data;
882 DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
884 if (!(* function) (connection, data))
894 * Calls function on each active connection; if the function returns
895 * #FALSE, stops iterating. Active connections are authenticated
896 * and have sent a Hello message.
898 * @param connections the connections object
899 * @param function the function
900 * @param data data to pass to it as a second arg
903 bus_connections_foreach_active (BusConnections *connections,
904 BusConnectionForeachFunction function,
907 foreach_active (connections, function, data);
911 * Calls function on each connection; if the function returns
912 * #FALSE, stops iterating.
914 * @param connections the connections object
915 * @param function the function
916 * @param data data to pass to it as a second arg
919 bus_connections_foreach (BusConnections *connections,
920 BusConnectionForeachFunction function,
923 if (!foreach_active (connections, function, data))
926 foreach_inactive (connections, function, data);
930 bus_connections_get_context (BusConnections *connections)
932 return connections->context;
936 * This is used to avoid covering the same connection twice when
937 * traversing connections. Note that it assumes we will
938 * bus_connection_mark_stamp() each connection at least once per
939 * INT_MAX increments of the global stamp, or wraparound would break
943 bus_connections_increment_stamp (BusConnections *connections)
945 connections->stamp += 1;
948 /* Mark connection with current stamp, return TRUE if it
949 * didn't already have that stamp
952 bus_connection_mark_stamp (DBusConnection *connection)
954 BusConnectionData *d;
956 d = BUS_CONNECTION_DATA (connection);
958 _dbus_assert (d != NULL);
960 if (d->stamp == d->connections->stamp)
964 d->stamp = d->connections->stamp;
970 bus_connection_get_context (DBusConnection *connection)
972 BusConnectionData *d;
974 d = BUS_CONNECTION_DATA (connection);
976 _dbus_assert (d != NULL);
978 return d->connections->context;
982 bus_connection_get_connections (DBusConnection *connection)
984 BusConnectionData *d;
986 d = BUS_CONNECTION_DATA (connection);
988 _dbus_assert (d != NULL);
990 return d->connections;
994 bus_connection_get_registry (DBusConnection *connection)
996 BusConnectionData *d;
998 d = BUS_CONNECTION_DATA (connection);
1000 _dbus_assert (d != NULL);
1002 return bus_context_get_registry (d->connections->context);
1006 bus_connection_get_activation (DBusConnection *connection)
1008 BusConnectionData *d;
1010 d = BUS_CONNECTION_DATA (connection);
1012 _dbus_assert (d != NULL);
1014 return bus_context_get_activation (d->connections->context);
1018 bus_connection_get_matchmaker (DBusConnection *connection)
1020 BusConnectionData *d;
1022 d = BUS_CONNECTION_DATA (connection);
1024 _dbus_assert (d != NULL);
1026 return bus_context_get_matchmaker (d->connections->context);
1030 bus_connection_get_selinux_id (DBusConnection *connection)
1032 BusConnectionData *d;
1034 d = BUS_CONNECTION_DATA (connection);
1036 _dbus_assert (d != NULL);
1038 return d->selinux_id;
1042 * Checks whether the connection is registered with the message bus.
1044 * @param connection the connection
1045 * @returns #TRUE if we're an active message bus participant
1048 bus_connection_is_active (DBusConnection *connection)
1050 BusConnectionData *d;
1052 d = BUS_CONNECTION_DATA (connection);
1054 return d != NULL && d->name != NULL;
1058 bus_connection_preallocate_oom_error (DBusConnection *connection)
1060 DBusMessage *message;
1061 DBusPreallocatedSend *preallocated;
1062 BusConnectionData *d;
1064 d = BUS_CONNECTION_DATA (connection);
1066 _dbus_assert (d != NULL);
1068 if (d->oom_preallocated != NULL)
1071 preallocated = dbus_connection_preallocate_send (connection);
1072 if (preallocated == NULL)
1075 message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1077 if (message == NULL)
1079 dbus_connection_free_preallocated_send (connection, preallocated);
1083 /* d->name may be NULL, but that is OK */
1084 if (!dbus_message_set_error_name (message, DBUS_ERROR_NO_MEMORY) ||
1085 !dbus_message_set_destination (message, d->name) ||
1086 !dbus_message_set_sender (message,
1089 dbus_connection_free_preallocated_send (connection, preallocated);
1090 dbus_message_unref (message);
1094 /* set reply serial to placeholder value just so space is already allocated
1097 if (!dbus_message_set_reply_serial (message, 14))
1099 dbus_connection_free_preallocated_send (connection, preallocated);
1100 dbus_message_unref (message);
1104 d->oom_message = message;
1105 d->oom_preallocated = preallocated;
1111 bus_connection_send_oom_error (DBusConnection *connection,
1112 DBusMessage *in_reply_to)
1114 BusConnectionData *d;
1116 d = BUS_CONNECTION_DATA (connection);
1118 _dbus_assert (d != NULL);
1119 _dbus_assert (d->oom_message != NULL);
1121 /* should always succeed since we set it to a placeholder earlier */
1122 if (!dbus_message_set_reply_serial (d->oom_message,
1123 dbus_message_get_serial (in_reply_to)))
1124 _dbus_assert_not_reached ("Failed to set reply serial for preallocated oom message");
1126 _dbus_assert (dbus_message_get_sender (d->oom_message) != NULL);
1128 dbus_connection_send_preallocated (connection, d->oom_preallocated,
1129 d->oom_message, NULL);
1131 dbus_message_unref (d->oom_message);
1132 d->oom_message = NULL;
1133 d->oom_preallocated = NULL;
1137 bus_connection_add_match_rule_link (DBusConnection *connection,
1140 BusConnectionData *d;
1142 d = BUS_CONNECTION_DATA (connection);
1143 _dbus_assert (d != NULL);
1145 _dbus_list_append_link (&d->match_rules, link);
1147 d->n_match_rules += 1;
1151 bus_connection_add_match_rule (DBusConnection *connection,
1156 link = _dbus_list_alloc_link (rule);
1161 bus_connection_add_match_rule_link (connection, link);
1167 bus_connection_remove_match_rule (DBusConnection *connection,
1170 BusConnectionData *d;
1172 d = BUS_CONNECTION_DATA (connection);
1173 _dbus_assert (d != NULL);
1175 _dbus_list_remove_last (&d->match_rules, rule);
1177 d->n_match_rules -= 1;
1178 _dbus_assert (d->n_match_rules >= 0);
1182 bus_connection_get_n_match_rules (DBusConnection *connection)
1184 BusConnectionData *d;
1186 d = BUS_CONNECTION_DATA (connection);
1187 _dbus_assert (d != NULL);
1189 return d->n_match_rules;
1193 bus_connection_add_owned_service_link (DBusConnection *connection,
1196 BusConnectionData *d;
1198 d = BUS_CONNECTION_DATA (connection);
1199 _dbus_assert (d != NULL);
1201 _dbus_list_append_link (&d->services_owned, link);
1203 d->n_services_owned += 1;
1207 bus_connection_add_owned_service (DBusConnection *connection,
1208 BusService *service)
1212 link = _dbus_list_alloc_link (service);
1217 bus_connection_add_owned_service_link (connection, link);
1223 bus_connection_remove_owned_service (DBusConnection *connection,
1224 BusService *service)
1226 BusConnectionData *d;
1228 d = BUS_CONNECTION_DATA (connection);
1229 _dbus_assert (d != NULL);
1231 _dbus_list_remove_last (&d->services_owned, service);
1233 d->n_services_owned -= 1;
1234 _dbus_assert (d->n_services_owned >= 0);
1238 bus_connection_get_n_services_owned (DBusConnection *connection)
1240 BusConnectionData *d;
1242 d = BUS_CONNECTION_DATA (connection);
1243 _dbus_assert (d != NULL);
1245 return d->n_services_owned;
1249 bus_connection_complete (DBusConnection *connection,
1250 const DBusString *name,
1253 BusConnectionData *d;
1256 d = BUS_CONNECTION_DATA (connection);
1257 _dbus_assert (d != NULL);
1258 _dbus_assert (d->name == NULL);
1259 _dbus_assert (d->policy == NULL);
1261 _dbus_assert (!bus_connection_is_active (connection));
1263 if (!_dbus_string_copy_data (name, &d->name))
1265 BUS_SET_OOM (error);
1269 _dbus_assert (d->name != NULL);
1271 _dbus_verbose ("Name %s assigned to %p\n", d->name, connection);
1273 d->policy = bus_context_create_client_policy (d->connections->context,
1277 /* we may have a NULL policy on OOM or error getting list of
1278 * groups for a user. In the latter case we don't handle it so
1279 * well currently, as it will just keep failing over and over.
1282 if (d->policy == NULL)
1284 _dbus_verbose ("Failed to create security policy for connection %p\n",
1286 _DBUS_ASSERT_ERROR_IS_SET (error);
1287 dbus_free (d->name);
1292 if (dbus_connection_get_unix_user (connection, &uid))
1294 if (!adjust_connections_for_uid (d->connections,
1297 BUS_SET_OOM (error);
1298 dbus_free (d->name);
1304 /* Now the connection is active, move it between lists */
1305 _dbus_list_unlink (&d->connections->incomplete,
1306 d->link_in_connection_list);
1307 d->connections->n_incomplete -= 1;
1308 _dbus_list_append_link (&d->connections->completed,
1309 d->link_in_connection_list);
1310 d->connections->n_completed += 1;
1312 _dbus_assert (d->connections->n_incomplete >= 0);
1313 _dbus_assert (d->connections->n_completed > 0);
1315 /* See if we can remove the timeout */
1316 bus_connections_expire_incomplete (d->connections);
1318 _dbus_assert (bus_connection_is_active (connection));
1324 bus_connection_get_name (DBusConnection *connection)
1326 BusConnectionData *d;
1328 d = BUS_CONNECTION_DATA (connection);
1329 _dbus_assert (d != NULL);
1335 * Check whether completing the passed-in connection would
1336 * exceed limits, and if so set error and return #FALSE
1339 bus_connections_check_limits (BusConnections *connections,
1340 DBusConnection *requesting_completion,
1343 BusConnectionData *d;
1346 d = BUS_CONNECTION_DATA (requesting_completion);
1347 _dbus_assert (d != NULL);
1349 _dbus_assert (d->name == NULL);
1351 if (connections->n_completed >=
1352 bus_context_get_max_completed_connections (connections->context))
1354 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1355 "The maximum number of active connections has been reached");
1359 if (dbus_connection_get_unix_user (requesting_completion, &uid))
1361 if (get_connections_for_uid (connections, uid) >=
1362 bus_context_get_max_connections_per_user (connections->context))
1364 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1365 "The maximum number of active connections for UID %lu has been reached",
1375 bus_pending_reply_free (BusPendingReply *pending)
1377 _dbus_verbose ("Freeing pending reply %p, replier %p receiver %p serial %u\n",
1379 pending->will_send_reply,
1380 pending->will_get_reply,
1381 pending->reply_serial);
1383 dbus_free (pending);
1387 bus_pending_reply_send_no_reply (BusConnections *connections,
1388 BusTransaction *transaction,
1389 BusPendingReply *pending)
1391 DBusMessage *message;
1392 DBusMessageIter iter;
1398 message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1399 if (message == NULL)
1402 dbus_message_set_no_reply (message, TRUE);
1404 if (!dbus_message_set_reply_serial (message,
1405 pending->reply_serial))
1408 if (!dbus_message_set_error_name (message,
1409 DBUS_ERROR_NO_REPLY))
1412 errmsg = "Message did not receive a reply (timeout by message bus)";
1413 dbus_message_iter_init_append (message, &iter);
1414 if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &errmsg))
1417 if (!bus_transaction_send_from_driver (transaction, pending->will_get_reply,
1424 dbus_message_unref (message);
1429 bus_pending_reply_expired (BusExpireList *list,
1433 BusPendingReply *pending = link->data;
1434 BusConnections *connections = data;
1435 BusTransaction *transaction;
1437 /* No reply is forthcoming. So nuke it if we can. If not,
1438 * leave it in the list to try expiring again later when we
1442 _dbus_verbose ("Expiring pending reply %p, replier %p receiver %p serial %u\n",
1444 pending->will_send_reply,
1445 pending->will_get_reply,
1446 pending->reply_serial);
1448 transaction = bus_transaction_new (connections->context);
1449 if (transaction == NULL)
1452 if (!bus_pending_reply_send_no_reply (connections,
1456 bus_transaction_cancel_and_free (transaction);
1460 _dbus_list_remove_link (&connections->pending_replies->items,
1462 bus_pending_reply_free (pending);
1463 bus_transaction_execute_and_free (transaction);
1469 bus_connection_drop_pending_replies (BusConnections *connections,
1470 DBusConnection *connection)
1472 /* The DBusConnection is almost 100% finalized here, so you can't
1473 * do anything with it except check for pointer equality
1477 _dbus_verbose ("Dropping pending replies that involve connection %p\n",
1480 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1481 while (link != NULL)
1484 BusPendingReply *pending;
1486 next = _dbus_list_get_next_link (&connections->pending_replies->items,
1488 pending = link->data;
1490 if (pending->will_get_reply == connection)
1492 /* We don't need to track this pending reply anymore */
1494 _dbus_verbose ("Dropping pending reply %p, replier %p receiver %p serial %u\n",
1496 pending->will_send_reply,
1497 pending->will_get_reply,
1498 pending->reply_serial);
1500 _dbus_list_remove_link (&connections->pending_replies->items,
1502 bus_pending_reply_free (pending);
1504 else if (pending->will_send_reply == connection)
1506 /* The reply isn't going to be sent, so set things
1507 * up so it will be expired right away
1509 _dbus_verbose ("Will expire pending reply %p, replier %p receiver %p serial %u\n",
1511 pending->will_send_reply,
1512 pending->will_get_reply,
1513 pending->reply_serial);
1515 pending->will_send_reply = NULL;
1516 pending->expire_item.added_tv_sec = 0;
1517 pending->expire_item.added_tv_usec = 0;
1519 bus_expire_timeout_set_interval (connections->pending_replies->timeout,
1530 BusPendingReply *pending;
1531 BusConnections *connections;
1532 } CancelPendingReplyData;
1535 cancel_pending_reply (void *data)
1537 CancelPendingReplyData *d = data;
1539 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1541 if (!_dbus_list_remove (&d->connections->pending_replies->items,
1543 _dbus_assert_not_reached ("pending reply did not exist to be cancelled");
1545 bus_pending_reply_free (d->pending); /* since it's been cancelled */
1549 cancel_pending_reply_data_free (void *data)
1551 CancelPendingReplyData *d = data;
1553 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1555 /* d->pending should be either freed or still
1556 * in the list of pending replies (owned by someone
1564 * Record that a reply is allowed; return TRUE on success.
1567 bus_connections_expect_reply (BusConnections *connections,
1568 BusTransaction *transaction,
1569 DBusConnection *will_get_reply,
1570 DBusConnection *will_send_reply,
1571 DBusMessage *reply_to_this,
1574 BusPendingReply *pending;
1575 dbus_uint32_t reply_serial;
1577 CancelPendingReplyData *cprd;
1580 _dbus_assert (will_get_reply != NULL);
1581 _dbus_assert (will_send_reply != NULL);
1582 _dbus_assert (reply_to_this != NULL);
1584 if (dbus_message_get_no_reply (reply_to_this))
1585 return TRUE; /* we won't allow a reply, since client doesn't care for one. */
1587 reply_serial = dbus_message_get_serial (reply_to_this);
1589 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1591 while (link != NULL)
1593 pending = link->data;
1595 if (pending->reply_serial == reply_serial &&
1596 pending->will_get_reply == will_get_reply &&
1597 pending->will_send_reply == will_send_reply)
1599 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1600 "Message has the same reply serial as a currently-outstanding existing method call");
1604 link = _dbus_list_get_next_link (&connections->pending_replies->items,
1606 if (pending->will_get_reply == will_get_reply)
1611 bus_context_get_max_replies_per_connection (connections->context))
1613 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1614 "The maximum number of pending replies per connection has been reached");
1618 pending = dbus_new0 (BusPendingReply, 1);
1619 if (pending == NULL)
1621 BUS_SET_OOM (error);
1625 #ifdef DBUS_ENABLE_VERBOSE_MODE
1626 /* so we can see a not-yet-added pending reply */
1627 pending->expire_item.added_tv_sec = 1;
1628 pending->expire_item.added_tv_usec = 1;
1631 pending->will_get_reply = will_get_reply;
1632 pending->will_send_reply = will_send_reply;
1633 pending->reply_serial = reply_serial;
1635 cprd = dbus_new0 (CancelPendingReplyData, 1);
1638 BUS_SET_OOM (error);
1639 bus_pending_reply_free (pending);
1643 if (!_dbus_list_prepend (&connections->pending_replies->items,
1646 BUS_SET_OOM (error);
1648 bus_pending_reply_free (pending);
1652 if (!bus_transaction_add_cancel_hook (transaction,
1653 cancel_pending_reply,
1655 cancel_pending_reply_data_free))
1657 BUS_SET_OOM (error);
1658 _dbus_list_remove (&connections->pending_replies->items, pending);
1660 bus_pending_reply_free (pending);
1664 cprd->pending = pending;
1665 cprd->connections = connections;
1667 _dbus_get_current_time (&pending->expire_item.added_tv_sec,
1668 &pending->expire_item.added_tv_usec);
1670 _dbus_verbose ("Added pending reply %p, replier %p receiver %p serial %u\n",
1672 pending->will_send_reply,
1673 pending->will_get_reply,
1674 pending->reply_serial);
1682 BusConnections *connections;
1683 } CheckPendingReplyData;
1686 cancel_check_pending_reply (void *data)
1688 CheckPendingReplyData *d = data;
1690 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1692 _dbus_list_prepend_link (&d->connections->pending_replies->items,
1698 check_pending_reply_data_free (void *data)
1700 CheckPendingReplyData *d = data;
1702 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1704 if (d->link != NULL)
1706 BusPendingReply *pending = d->link->data;
1708 _dbus_assert (_dbus_list_find_last (&d->connections->pending_replies->items,
1711 bus_pending_reply_free (pending);
1712 _dbus_list_free_link (d->link);
1719 * Check whether a reply is allowed, remove BusPendingReply
1720 * if so, return TRUE if so.
1723 bus_connections_check_reply (BusConnections *connections,
1724 BusTransaction *transaction,
1725 DBusConnection *sending_reply,
1726 DBusConnection *receiving_reply,
1730 CheckPendingReplyData *cprd;
1732 dbus_uint32_t reply_serial;
1734 _dbus_assert (sending_reply != NULL);
1735 _dbus_assert (receiving_reply != NULL);
1737 reply_serial = dbus_message_get_reply_serial (reply);
1739 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1740 while (link != NULL)
1742 BusPendingReply *pending = link->data;
1744 if (pending->reply_serial == reply_serial &&
1745 pending->will_get_reply == receiving_reply &&
1746 pending->will_send_reply == sending_reply)
1748 _dbus_verbose ("Found pending reply with serial %u\n", reply_serial);
1752 link = _dbus_list_get_next_link (&connections->pending_replies->items,
1758 _dbus_verbose ("No pending reply expected\n");
1763 cprd = dbus_new0 (CheckPendingReplyData, 1);
1766 BUS_SET_OOM (error);
1770 if (!bus_transaction_add_cancel_hook (transaction,
1771 cancel_check_pending_reply,
1773 check_pending_reply_data_free))
1775 BUS_SET_OOM (error);
1781 cprd->connections = connections;
1783 _dbus_list_unlink (&connections->pending_replies->items,
1786 _dbus_assert (_dbus_list_find_last (&connections->pending_replies->items,
1787 link->data) == NULL);
1795 * Note that this is fairly fragile; in particular, don't try to use
1796 * one transaction across any main loop iterations.
1801 BusTransaction *transaction;
1802 DBusMessage *message;
1803 DBusPreallocatedSend *preallocated;
1808 BusTransactionCancelFunction cancel_function;
1809 DBusFreeFunction free_data_function;
1813 struct BusTransaction
1815 DBusList *connections;
1816 BusContext *context;
1817 DBusList *cancel_hooks;
1821 message_to_send_free (DBusConnection *connection,
1822 MessageToSend *to_send)
1824 if (to_send->message)
1825 dbus_message_unref (to_send->message);
1827 if (to_send->preallocated)
1828 dbus_connection_free_preallocated_send (connection, to_send->preallocated);
1830 dbus_free (to_send);
1834 cancel_hook_cancel (void *element,
1837 CancelHook *ch = element;
1839 _dbus_verbose ("Running transaction cancel hook\n");
1841 if (ch->cancel_function)
1842 (* ch->cancel_function) (ch->data);
1846 cancel_hook_free (void *element,
1849 CancelHook *ch = element;
1851 if (ch->free_data_function)
1852 (* ch->free_data_function) (ch->data);
1858 free_cancel_hooks (BusTransaction *transaction)
1860 _dbus_list_foreach (&transaction->cancel_hooks,
1861 cancel_hook_free, NULL);
1863 _dbus_list_clear (&transaction->cancel_hooks);
1867 bus_transaction_new (BusContext *context)
1869 BusTransaction *transaction;
1871 transaction = dbus_new0 (BusTransaction, 1);
1872 if (transaction == NULL)
1875 transaction->context = context;
1881 bus_transaction_get_context (BusTransaction *transaction)
1883 return transaction->context;
1887 bus_transaction_get_connections (BusTransaction *transaction)
1889 return bus_context_get_connections (transaction->context);
1893 bus_transaction_send_from_driver (BusTransaction *transaction,
1894 DBusConnection *connection,
1895 DBusMessage *message)
1897 /* We have to set the sender to the driver, and have
1898 * to check security policy since it was not done in
1901 _dbus_verbose ("Sending %s %s %s from driver\n",
1902 dbus_message_get_interface (message) ?
1903 dbus_message_get_interface (message) : "(no interface)",
1904 dbus_message_get_member (message) ?
1905 dbus_message_get_member (message) : "(no member)",
1906 dbus_message_get_error_name (message) ?
1907 dbus_message_get_error_name (message) : "(no error name)");
1909 if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
1912 if (bus_connection_is_active (connection))
1914 if (!dbus_message_set_destination (message,
1915 bus_connection_get_name (connection)))
1919 /* bus driver never wants a reply */
1920 dbus_message_set_no_reply (message, TRUE);
1922 /* If security policy doesn't allow the message, we silently
1923 * eat it; the driver doesn't care about getting a reply.
1925 if (!bus_context_check_security_policy (bus_transaction_get_context (transaction),
1927 NULL, connection, connection, message, NULL))
1930 return bus_transaction_send (transaction, connection, message);
1934 bus_transaction_send (BusTransaction *transaction,
1935 DBusConnection *connection,
1936 DBusMessage *message)
1938 MessageToSend *to_send;
1939 BusConnectionData *d;
1942 _dbus_verbose (" trying to add %s interface=%s member=%s error=%s to transaction%s\n",
1943 dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR ? "error" :
1944 dbus_message_get_reply_serial (message) != 0 ? "reply" :
1946 dbus_message_get_interface (message) ?
1947 dbus_message_get_interface (message) : "(unset)",
1948 dbus_message_get_member (message) ?
1949 dbus_message_get_member (message) : "(unset)",
1950 dbus_message_get_error_name (message) ?
1951 dbus_message_get_error_name (message) : "(unset)",
1952 dbus_connection_get_is_connected (connection) ?
1953 "" : " (disconnected)");
1955 _dbus_assert (dbus_message_get_sender (message) != NULL);
1957 if (!dbus_connection_get_is_connected (connection))
1958 return TRUE; /* silently ignore disconnected connections */
1960 d = BUS_CONNECTION_DATA (connection);
1961 _dbus_assert (d != NULL);
1963 to_send = dbus_new (MessageToSend, 1);
1964 if (to_send == NULL)
1969 to_send->preallocated = dbus_connection_preallocate_send (connection);
1970 if (to_send->preallocated == NULL)
1972 dbus_free (to_send);
1976 dbus_message_ref (message);
1977 to_send->message = message;
1978 to_send->transaction = transaction;
1980 _dbus_verbose ("about to prepend message\n");
1982 if (!_dbus_list_prepend (&d->transaction_messages, to_send))
1984 message_to_send_free (connection, to_send);
1988 _dbus_verbose ("prepended message\n");
1990 /* See if we already had this connection in the list
1991 * for this transaction. If we have a pending message,
1992 * then we should already be in transaction->connections
1994 link = _dbus_list_get_first_link (&d->transaction_messages);
1995 _dbus_assert (link->data == to_send);
1996 link = _dbus_list_get_next_link (&d->transaction_messages, link);
1997 while (link != NULL)
1999 MessageToSend *m = link->data;
2000 DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
2002 if (m->transaction == transaction)
2010 if (!_dbus_list_prepend (&transaction->connections, connection))
2012 _dbus_list_remove (&d->transaction_messages, to_send);
2013 message_to_send_free (connection, to_send);
2022 connection_cancel_transaction (DBusConnection *connection,
2023 BusTransaction *transaction)
2026 BusConnectionData *d;
2028 d = BUS_CONNECTION_DATA (connection);
2029 _dbus_assert (d != NULL);
2031 link = _dbus_list_get_first_link (&d->transaction_messages);
2032 while (link != NULL)
2034 MessageToSend *m = link->data;
2035 DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
2037 if (m->transaction == transaction)
2039 _dbus_list_remove_link (&d->transaction_messages,
2042 message_to_send_free (connection, m);
2050 bus_transaction_cancel_and_free (BusTransaction *transaction)
2052 DBusConnection *connection;
2054 _dbus_verbose ("TRANSACTION: cancelled\n");
2056 while ((connection = _dbus_list_pop_first (&transaction->connections)))
2057 connection_cancel_transaction (connection, transaction);
2059 _dbus_assert (transaction->connections == NULL);
2061 _dbus_list_foreach (&transaction->cancel_hooks,
2062 cancel_hook_cancel, NULL);
2064 free_cancel_hooks (transaction);
2066 dbus_free (transaction);
2070 connection_execute_transaction (DBusConnection *connection,
2071 BusTransaction *transaction)
2074 BusConnectionData *d;
2076 d = BUS_CONNECTION_DATA (connection);
2077 _dbus_assert (d != NULL);
2079 /* Send the queue in order (FIFO) */
2080 link = _dbus_list_get_last_link (&d->transaction_messages);
2081 while (link != NULL)
2083 MessageToSend *m = link->data;
2084 DBusList *prev = _dbus_list_get_prev_link (&d->transaction_messages, link);
2086 if (m->transaction == transaction)
2088 _dbus_list_remove_link (&d->transaction_messages,
2091 _dbus_assert (dbus_message_get_sender (m->message) != NULL);
2093 dbus_connection_send_preallocated (connection,
2098 m->preallocated = NULL; /* so we don't double-free it */
2100 message_to_send_free (connection, m);
2108 bus_transaction_execute_and_free (BusTransaction *transaction)
2110 /* For each connection in transaction->connections
2113 DBusConnection *connection;
2115 _dbus_verbose ("TRANSACTION: executing\n");
2117 while ((connection = _dbus_list_pop_first (&transaction->connections)))
2118 connection_execute_transaction (connection, transaction);
2120 _dbus_assert (transaction->connections == NULL);
2122 free_cancel_hooks (transaction);
2124 dbus_free (transaction);
2128 bus_connection_remove_transactions (DBusConnection *connection)
2130 MessageToSend *to_send;
2131 BusConnectionData *d;
2133 d = BUS_CONNECTION_DATA (connection);
2134 _dbus_assert (d != NULL);
2136 while ((to_send = _dbus_list_get_first (&d->transaction_messages)))
2138 /* only has an effect for the first MessageToSend listing this transaction */
2139 _dbus_list_remove (&to_send->transaction->connections,
2142 _dbus_list_remove (&d->transaction_messages, to_send);
2143 message_to_send_free (connection, to_send);
2148 * Converts the DBusError to a message reply
2151 bus_transaction_send_error_reply (BusTransaction *transaction,
2152 DBusConnection *connection,
2153 const DBusError *error,
2154 DBusMessage *in_reply_to)
2158 _dbus_assert (error != NULL);
2159 _DBUS_ASSERT_ERROR_IS_SET (error);
2161 _dbus_verbose ("Sending error reply %s \"%s\"\n",
2162 error->name, error->message);
2164 reply = dbus_message_new_error (in_reply_to,
2170 if (!bus_transaction_send_from_driver (transaction, connection, reply))
2172 dbus_message_unref (reply);
2176 dbus_message_unref (reply);
2182 bus_transaction_add_cancel_hook (BusTransaction *transaction,
2183 BusTransactionCancelFunction cancel_function,
2185 DBusFreeFunction free_data_function)
2189 ch = dbus_new (CancelHook, 1);
2193 _dbus_verbose (" adding cancel hook function = %p data = %p\n",
2194 cancel_function, data);
2196 ch->cancel_function = cancel_function;
2198 ch->free_data_function = free_data_function;
2200 /* It's important that the hooks get run in reverse order that they
2203 if (!_dbus_list_prepend (&transaction->cancel_hooks, ch))