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>
35 static void bus_connection_remove_transactions (DBusConnection *connection);
39 BusExpireItem expire_item;
41 DBusConnection *will_get_reply;
42 DBusConnection *will_send_reply;
44 dbus_uint32_t reply_serial;
51 DBusList *completed; /**< List of all completed connections */
52 int n_completed; /**< Length of completed list */
53 DBusList *incomplete; /**< List of all not-yet-active connections */
54 int n_incomplete; /**< Length of incomplete list */
56 DBusHashTable *completed_by_user; /**< Number of completed connections for each UID */
57 DBusTimeout *expire_timeout; /**< Timeout for expiring incomplete connections. */
58 int stamp; /**< Incrementing number */
59 BusExpireList *pending_replies; /**< List of pending replies */
62 static dbus_int32_t connection_data_slot = -1;
66 BusConnections *connections;
67 DBusList *link_in_connection_list;
68 DBusConnection *connection;
69 DBusList *services_owned;
71 DBusList *match_rules;
74 DBusList *transaction_messages; /**< Stuff we need to send as part of a transaction */
75 DBusMessage *oom_message;
76 DBusPreallocatedSend *oom_preallocated;
77 BusClientPolicy *policy;
79 BusSELinuxID *selinux_id;
81 long connection_tv_sec; /**< Time when we connected (seconds component) */
82 long connection_tv_usec; /**< Time when we connected (microsec component) */
83 int stamp; /**< connections->stamp last time we were traversed */
86 static dbus_bool_t bus_pending_reply_expired (BusExpireList *list,
90 static void bus_connection_drop_pending_replies (BusConnections *connections,
91 DBusConnection *connection);
93 static dbus_bool_t expire_incomplete_timeout (void *data);
95 #define BUS_CONNECTION_DATA(connection) (dbus_connection_get_data ((connection), connection_data_slot))
98 connection_get_loop (DBusConnection *connection)
100 BusConnectionData *d;
102 d = BUS_CONNECTION_DATA (connection);
104 return bus_context_get_loop (d->connections->context);
109 get_connections_for_uid (BusConnections *connections,
115 /* val is NULL is 0 when it isn't in the hash yet */
117 val = _dbus_hash_table_lookup_ulong (connections->completed_by_user,
120 current_count = _DBUS_POINTER_TO_INT (val);
122 return current_count;
126 adjust_connections_for_uid (BusConnections *connections,
132 current_count = get_connections_for_uid (connections, uid);
134 _dbus_verbose ("Adjusting connection count for UID " DBUS_UID_FORMAT
135 ": was %d adjustment %d making %d\n",
136 uid, current_count, adjustment, current_count + adjustment);
138 _dbus_assert (current_count >= 0);
140 current_count += adjustment;
142 _dbus_assert (current_count >= 0);
144 if (current_count == 0)
146 _dbus_hash_table_remove_ulong (connections->completed_by_user, uid);
153 retval = _dbus_hash_table_insert_ulong (connections->completed_by_user,
154 uid, _DBUS_INT_TO_POINTER (current_count));
156 /* only positive adjustment can fail as otherwise
157 * a hash entry should already exist
159 _dbus_assert (adjustment > 0 ||
160 (adjustment <= 0 && retval));
167 bus_connection_disconnected (DBusConnection *connection)
169 BusConnectionData *d;
171 BusMatchmaker *matchmaker;
173 d = BUS_CONNECTION_DATA (connection);
174 _dbus_assert (d != NULL);
176 _dbus_verbose ("%s disconnected, dropping all service ownership and releasing\n",
177 d->name ? d->name : "(inactive)");
179 /* Delete our match rules */
180 if (d->n_match_rules > 0)
182 matchmaker = bus_context_get_matchmaker (d->connections->context);
183 bus_matchmaker_disconnected (matchmaker, connection);
186 /* Drop any service ownership. FIXME 1.0? Unfortunately, this requires
187 * memory allocation and there doesn't seem to be a good way to
188 * handle it other than sleeping; we can't "fail" the operation of
189 * disconnecting a client, and preallocating a broadcast "service is
190 * now gone" message for every client-service pair seems kind of
191 * involved. Probably we need to do that though.
193 while ((service = _dbus_list_get_last (&d->services_owned)))
195 BusTransaction *transaction;
200 dbus_error_init (&error);
202 while ((transaction = bus_transaction_new (d->connections->context)) == NULL)
203 _dbus_wait_for_memory ();
205 if (!bus_service_remove_owner (service, connection,
206 transaction, &error))
208 _DBUS_ASSERT_ERROR_IS_SET (&error);
210 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
212 dbus_error_free (&error);
213 bus_transaction_cancel_and_free (transaction);
214 _dbus_wait_for_memory ();
219 _dbus_verbose ("Failed to remove service owner: %s %s\n",
220 error.name, error.message);
221 _dbus_assert_not_reached ("Removing service owner failed for non-memory-related reason");
225 bus_transaction_execute_and_free (transaction);
228 bus_dispatch_remove_connection (connection);
230 /* no more watching */
231 if (!dbus_connection_set_watch_functions (connection,
235 _dbus_assert_not_reached ("setting watch functions to NULL failed");
237 if (!dbus_connection_set_timeout_functions (connection,
241 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
243 dbus_connection_set_unix_user_function (connection,
246 dbus_connection_set_dispatch_status_function (connection,
249 bus_connection_remove_transactions (connection);
251 if (d->link_in_connection_list != NULL)
257 _dbus_list_remove_link (&d->connections->completed, d->link_in_connection_list);
258 d->link_in_connection_list = NULL;
259 d->connections->n_completed -= 1;
261 if (dbus_connection_get_unix_user (connection, &uid))
263 if (!adjust_connections_for_uid (d->connections,
265 _dbus_assert_not_reached ("adjusting downward should never fail");
270 _dbus_list_remove_link (&d->connections->incomplete, d->link_in_connection_list);
271 d->link_in_connection_list = NULL;
272 d->connections->n_incomplete -= 1;
275 _dbus_assert (d->connections->n_incomplete >= 0);
276 _dbus_assert (d->connections->n_completed >= 0);
279 bus_connection_drop_pending_replies (d->connections, connection);
281 /* frees "d" as side effect */
282 dbus_connection_set_data (connection,
283 connection_data_slot,
286 dbus_connection_unref (connection);
290 connection_watch_callback (DBusWatch *watch,
291 unsigned int condition,
294 /* FIXME this can be done in dbus-mainloop.c
295 * if the code in activation.c for the babysitter
296 * watch handler is fixed.
300 _dbus_verbose ("Calling handle_watch\n");
302 return dbus_watch_handle (watch, condition);
306 add_connection_watch (DBusWatch *watch,
309 DBusConnection *connection = data;
311 return _dbus_loop_add_watch (connection_get_loop (connection),
312 watch, connection_watch_callback, connection,
317 remove_connection_watch (DBusWatch *watch,
320 DBusConnection *connection = data;
322 _dbus_loop_remove_watch (connection_get_loop (connection),
323 watch, connection_watch_callback, connection);
327 connection_timeout_callback (DBusTimeout *timeout,
330 /* DBusConnection *connection = data; */
332 /* can return FALSE on OOM but we just let it fire again later */
333 dbus_timeout_handle (timeout);
337 add_connection_timeout (DBusTimeout *timeout,
340 DBusConnection *connection = data;
342 return _dbus_loop_add_timeout (connection_get_loop (connection),
343 timeout, connection_timeout_callback, connection, NULL);
347 remove_connection_timeout (DBusTimeout *timeout,
350 DBusConnection *connection = data;
352 _dbus_loop_remove_timeout (connection_get_loop (connection),
353 timeout, connection_timeout_callback, connection);
357 dispatch_status_function (DBusConnection *connection,
358 DBusDispatchStatus new_status,
361 DBusLoop *loop = data;
363 if (new_status != DBUS_DISPATCH_COMPLETE)
365 while (!_dbus_loop_queue_dispatch (loop, connection))
366 _dbus_wait_for_memory ();
371 allow_user_function (DBusConnection *connection,
375 BusConnectionData *d;
377 d = BUS_CONNECTION_DATA (connection);
379 _dbus_assert (d != NULL);
381 return bus_context_allow_user (d->connections->context, uid);
385 free_connection_data (void *data)
387 BusConnectionData *d = data;
389 /* services_owned should be NULL since we should be disconnected */
390 _dbus_assert (d->services_owned == NULL);
391 _dbus_assert (d->n_services_owned == 0);
393 _dbus_assert (d->transaction_messages == NULL);
395 if (d->oom_preallocated)
396 dbus_connection_free_preallocated_send (d->connection, d->oom_preallocated);
399 dbus_message_unref (d->oom_message);
402 bus_client_policy_unref (d->policy);
405 bus_selinux_id_unref (d->selinux_id);
413 call_timeout_callback (DBusTimeout *timeout,
416 /* can return FALSE on OOM but we just let it fire again later */
417 dbus_timeout_handle (timeout);
421 bus_connections_new (BusContext *context)
423 BusConnections *connections;
425 if (!dbus_connection_allocate_data_slot (&connection_data_slot))
428 connections = dbus_new0 (BusConnections, 1);
429 if (connections == NULL)
432 connections->completed_by_user = _dbus_hash_table_new (DBUS_HASH_ULONG,
434 if (connections->completed_by_user == NULL)
437 connections->expire_timeout = _dbus_timeout_new (100, /* irrelevant */
438 expire_incomplete_timeout,
440 if (connections->expire_timeout == NULL)
443 _dbus_timeout_set_enabled (connections->expire_timeout, FALSE);
445 connections->pending_replies = bus_expire_list_new (bus_context_get_loop (context),
446 bus_context_get_reply_timeout (context),
447 bus_pending_reply_expired,
449 if (connections->pending_replies == NULL)
452 if (!_dbus_loop_add_timeout (bus_context_get_loop (context),
453 connections->expire_timeout,
454 call_timeout_callback, NULL, NULL))
457 connections->refcount = 1;
458 connections->context = context;
463 bus_expire_list_free (connections->pending_replies);
465 _dbus_timeout_unref (connections->expire_timeout);
467 _dbus_hash_table_unref (connections->completed_by_user);
469 dbus_free (connections);
471 dbus_connection_free_data_slot (&connection_data_slot);
477 bus_connections_ref (BusConnections *connections)
479 _dbus_assert (connections->refcount > 0);
480 connections->refcount += 1;
486 bus_connections_unref (BusConnections *connections)
488 _dbus_assert (connections->refcount > 0);
489 connections->refcount -= 1;
490 if (connections->refcount == 0)
492 /* drop all incomplete */
493 while (connections->incomplete != NULL)
495 DBusConnection *connection;
497 connection = connections->incomplete->data;
499 dbus_connection_ref (connection);
500 dbus_connection_close (connection);
501 bus_connection_disconnected (connection);
502 dbus_connection_unref (connection);
505 _dbus_assert (connections->n_incomplete == 0);
507 /* drop all real connections */
508 while (connections->completed != NULL)
510 DBusConnection *connection;
512 connection = connections->completed->data;
514 dbus_connection_ref (connection);
515 dbus_connection_close (connection);
516 bus_connection_disconnected (connection);
517 dbus_connection_unref (connection);
520 _dbus_assert (connections->n_completed == 0);
522 bus_expire_list_free (connections->pending_replies);
524 _dbus_loop_remove_timeout (bus_context_get_loop (connections->context),
525 connections->expire_timeout,
526 call_timeout_callback, NULL);
528 _dbus_timeout_unref (connections->expire_timeout);
530 _dbus_hash_table_unref (connections->completed_by_user);
532 dbus_free (connections);
534 dbus_connection_free_data_slot (&connection_data_slot);
539 bus_connections_setup_connection (BusConnections *connections,
540 DBusConnection *connection)
542 BusConnectionData *d;
546 d = dbus_new0 (BusConnectionData, 1);
551 d->connections = connections;
552 d->connection = connection;
554 _dbus_get_current_time (&d->connection_tv_sec,
555 &d->connection_tv_usec);
557 _dbus_assert (connection_data_slot >= 0);
559 if (!dbus_connection_set_data (connection,
560 connection_data_slot,
561 d, free_connection_data))
569 dbus_error_init (&error);
570 d->selinux_id = bus_selinux_init_connection_id (connection,
572 if (dbus_error_is_set (&error))
574 /* This is a bit bogus because we pretend all errors
575 * are OOM; this is done because we know that in bus.c
576 * an OOM error disconnects the connection, which is
577 * the same thing we want on any other error.
579 dbus_error_free (&error);
583 if (!dbus_connection_set_watch_functions (connection,
584 add_connection_watch,
585 remove_connection_watch,
591 if (!dbus_connection_set_timeout_functions (connection,
592 add_connection_timeout,
593 remove_connection_timeout,
598 dbus_connection_set_unix_user_function (connection,
602 dbus_connection_set_dispatch_status_function (connection,
603 dispatch_status_function,
604 bus_context_get_loop (connections->context),
607 d->link_in_connection_list = _dbus_list_alloc_link (connection);
608 if (d->link_in_connection_list == NULL)
611 /* Setup the connection with the dispatcher */
612 if (!bus_dispatch_add_connection (connection))
615 if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
617 if (!_dbus_loop_queue_dispatch (bus_context_get_loop (connections->context), connection))
619 bus_dispatch_remove_connection (connection);
624 _dbus_list_append_link (&connections->incomplete, d->link_in_connection_list);
625 connections->n_incomplete += 1;
627 dbus_connection_ref (connection);
629 /* Note that we might disconnect ourselves here, but it only takes
630 * effect on return to the main loop. We call this to free up
631 * expired connections if possible, and to queue the timeout for our
634 bus_connections_expire_incomplete (connections);
636 /* And we might also disconnect ourselves here, but again it
637 * only takes effect on return to main loop.
639 if (connections->n_incomplete >
640 bus_context_get_max_incomplete_connections (connections->context))
642 _dbus_verbose ("Number of incomplete connections exceeds max, dropping oldest one\n");
644 _dbus_assert (connections->incomplete != NULL);
645 /* Disconnect the oldest unauthenticated connection. FIXME
646 * would it be more secure to drop a *random* connection? This
647 * algorithm seems to mean that if someone can create new
648 * connections quickly enough, they can keep anyone else from
649 * completing authentication. But random may or may not really
650 * help with that, a more elaborate solution might be required.
652 dbus_connection_close (connections->incomplete->data);
661 bus_selinux_id_unref (d->selinux_id);
662 d->selinux_id = NULL;
664 if (!dbus_connection_set_watch_functions (connection,
668 _dbus_assert_not_reached ("setting watch functions to NULL failed");
670 if (!dbus_connection_set_timeout_functions (connection,
674 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
676 dbus_connection_set_unix_user_function (connection,
679 dbus_connection_set_dispatch_status_function (connection,
682 if (d->link_in_connection_list != NULL)
684 _dbus_assert (d->link_in_connection_list->next == NULL);
685 _dbus_assert (d->link_in_connection_list->prev == NULL);
686 _dbus_list_free_link (d->link_in_connection_list);
687 d->link_in_connection_list = NULL;
690 if (!dbus_connection_set_data (connection,
691 connection_data_slot,
693 _dbus_assert_not_reached ("failed to set connection data to null");
695 /* "d" has now been freed */
702 bus_connections_expire_incomplete (BusConnections *connections)
708 if (connections->incomplete != NULL)
710 long tv_sec, tv_usec;
714 _dbus_get_current_time (&tv_sec, &tv_usec);
715 auth_timeout = bus_context_get_auth_timeout (connections->context);
717 link = _dbus_list_get_first_link (&connections->incomplete);
720 DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
721 DBusConnection *connection;
722 BusConnectionData *d;
725 connection = link->data;
727 d = BUS_CONNECTION_DATA (connection);
729 _dbus_assert (d != NULL);
731 elapsed = ELAPSED_MILLISECONDS_SINCE (d->connection_tv_sec,
732 d->connection_tv_usec,
735 if (elapsed >= (double) auth_timeout)
737 _dbus_verbose ("Timing out authentication for connection %p\n", connection);
738 dbus_connection_close (connection);
742 /* We can end the loop, since the connections are in oldest-first order */
743 next_interval = ((double)auth_timeout) - elapsed;
744 _dbus_verbose ("Connection %p authentication expires in %d milliseconds\n",
745 connection, next_interval);
754 bus_expire_timeout_set_interval (connections->expire_timeout,
759 expire_incomplete_timeout (void *data)
761 BusConnections *connections = data;
763 _dbus_verbose ("Running %s\n", _DBUS_FUNCTION_NAME);
765 /* note that this may remove the timeout */
766 bus_connections_expire_incomplete (connections);
772 bus_connection_get_groups (DBusConnection *connection,
773 unsigned long **groups,
777 BusConnectionData *d;
779 DBusUserDatabase *user_database;
781 d = BUS_CONNECTION_DATA (connection);
783 _dbus_assert (d != NULL);
785 user_database = bus_context_get_user_database (d->connections->context);
790 if (dbus_connection_get_unix_user (connection, &uid))
792 if (!_dbus_user_database_get_groups (user_database,
793 uid, groups, n_groups,
796 _DBUS_ASSERT_ERROR_IS_SET (error);
797 _dbus_verbose ("Did not get any groups for UID %lu\n",
803 _dbus_verbose ("Got %d groups for UID %lu\n",
809 return TRUE; /* successfully got 0 groups */
813 bus_connection_is_in_group (DBusConnection *connection,
817 unsigned long *group_ids;
820 if (!bus_connection_get_groups (connection, &group_ids, &n_group_ids,
825 while (i < n_group_ids)
827 if (group_ids[i] == gid)
829 dbus_free (group_ids);
835 dbus_free (group_ids);
840 bus_connection_get_policy (DBusConnection *connection)
842 BusConnectionData *d;
844 d = BUS_CONNECTION_DATA (connection);
846 _dbus_assert (d != NULL);
847 _dbus_assert (d->policy != NULL);
853 foreach_active (BusConnections *connections,
854 BusConnectionForeachFunction function,
859 link = _dbus_list_get_first_link (&connections->completed);
862 DBusConnection *connection = link->data;
863 DBusList *next = _dbus_list_get_next_link (&connections->completed, link);
865 if (!(* function) (connection, data))
875 foreach_inactive (BusConnections *connections,
876 BusConnectionForeachFunction function,
881 link = _dbus_list_get_first_link (&connections->incomplete);
884 DBusConnection *connection = link->data;
885 DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
887 if (!(* function) (connection, data))
897 * Calls function on each active connection; if the function returns
898 * #FALSE, stops iterating. Active connections are authenticated
899 * and have sent a Hello message.
901 * @param connections the connections object
902 * @param function the function
903 * @param data data to pass to it as a second arg
906 bus_connections_foreach_active (BusConnections *connections,
907 BusConnectionForeachFunction function,
910 foreach_active (connections, function, data);
914 * Calls function on each connection; if the function returns
915 * #FALSE, stops iterating.
917 * @param connections the connections object
918 * @param function the function
919 * @param data data to pass to it as a second arg
922 bus_connections_foreach (BusConnections *connections,
923 BusConnectionForeachFunction function,
926 if (!foreach_active (connections, function, data))
929 foreach_inactive (connections, function, data);
933 bus_connections_get_context (BusConnections *connections)
935 return connections->context;
939 * This is used to avoid covering the same connection twice when
940 * traversing connections. Note that it assumes we will
941 * bus_connection_mark_stamp() each connection at least once per
942 * INT_MAX increments of the global stamp, or wraparound would break
946 bus_connections_increment_stamp (BusConnections *connections)
948 connections->stamp += 1;
951 /* Mark connection with current stamp, return TRUE if it
952 * didn't already have that stamp
955 bus_connection_mark_stamp (DBusConnection *connection)
957 BusConnectionData *d;
959 d = BUS_CONNECTION_DATA (connection);
961 _dbus_assert (d != NULL);
963 if (d->stamp == d->connections->stamp)
967 d->stamp = d->connections->stamp;
973 bus_connection_get_context (DBusConnection *connection)
975 BusConnectionData *d;
977 d = BUS_CONNECTION_DATA (connection);
979 _dbus_assert (d != NULL);
981 return d->connections->context;
985 bus_connection_get_connections (DBusConnection *connection)
987 BusConnectionData *d;
989 d = BUS_CONNECTION_DATA (connection);
991 _dbus_assert (d != NULL);
993 return d->connections;
997 bus_connection_get_registry (DBusConnection *connection)
999 BusConnectionData *d;
1001 d = BUS_CONNECTION_DATA (connection);
1003 _dbus_assert (d != NULL);
1005 return bus_context_get_registry (d->connections->context);
1009 bus_connection_get_activation (DBusConnection *connection)
1011 BusConnectionData *d;
1013 d = BUS_CONNECTION_DATA (connection);
1015 _dbus_assert (d != NULL);
1017 return bus_context_get_activation (d->connections->context);
1021 bus_connection_get_matchmaker (DBusConnection *connection)
1023 BusConnectionData *d;
1025 d = BUS_CONNECTION_DATA (connection);
1027 _dbus_assert (d != NULL);
1029 return bus_context_get_matchmaker (d->connections->context);
1033 bus_connection_get_selinux_id (DBusConnection *connection)
1035 BusConnectionData *d;
1037 d = BUS_CONNECTION_DATA (connection);
1039 _dbus_assert (d != NULL);
1041 return d->selinux_id;
1045 * Checks whether the connection is registered with the message bus.
1047 * @param connection the connection
1048 * @returns #TRUE if we're an active message bus participant
1051 bus_connection_is_active (DBusConnection *connection)
1053 BusConnectionData *d;
1055 d = BUS_CONNECTION_DATA (connection);
1057 return d != NULL && d->name != NULL;
1061 bus_connection_preallocate_oom_error (DBusConnection *connection)
1063 DBusMessage *message;
1064 DBusPreallocatedSend *preallocated;
1065 BusConnectionData *d;
1067 d = BUS_CONNECTION_DATA (connection);
1069 _dbus_assert (d != NULL);
1071 if (d->oom_preallocated != NULL)
1074 preallocated = dbus_connection_preallocate_send (connection);
1075 if (preallocated == NULL)
1078 message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1080 if (message == NULL)
1082 dbus_connection_free_preallocated_send (connection, preallocated);
1086 /* d->name may be NULL, but that is OK */
1087 if (!dbus_message_set_error_name (message, DBUS_ERROR_NO_MEMORY) ||
1088 !dbus_message_set_destination (message, d->name) ||
1089 !dbus_message_set_sender (message,
1092 dbus_connection_free_preallocated_send (connection, preallocated);
1093 dbus_message_unref (message);
1097 /* set reply serial to placeholder value just so space is already allocated
1100 if (!dbus_message_set_reply_serial (message, 14))
1102 dbus_connection_free_preallocated_send (connection, preallocated);
1103 dbus_message_unref (message);
1107 d->oom_message = message;
1108 d->oom_preallocated = preallocated;
1114 bus_connection_send_oom_error (DBusConnection *connection,
1115 DBusMessage *in_reply_to)
1117 BusConnectionData *d;
1119 d = BUS_CONNECTION_DATA (connection);
1121 _dbus_assert (d != NULL);
1122 _dbus_assert (d->oom_message != NULL);
1124 /* should always succeed since we set it to a placeholder earlier */
1125 if (!dbus_message_set_reply_serial (d->oom_message,
1126 dbus_message_get_serial (in_reply_to)))
1127 _dbus_assert_not_reached ("Failed to set reply serial for preallocated oom message");
1129 _dbus_assert (dbus_message_get_sender (d->oom_message) != NULL);
1131 dbus_connection_send_preallocated (connection, d->oom_preallocated,
1132 d->oom_message, NULL);
1134 dbus_message_unref (d->oom_message);
1135 d->oom_message = NULL;
1136 d->oom_preallocated = NULL;
1140 bus_connection_add_match_rule_link (DBusConnection *connection,
1143 BusConnectionData *d;
1145 d = BUS_CONNECTION_DATA (connection);
1146 _dbus_assert (d != NULL);
1148 _dbus_list_append_link (&d->match_rules, link);
1150 d->n_match_rules += 1;
1154 bus_connection_add_match_rule (DBusConnection *connection,
1159 link = _dbus_list_alloc_link (rule);
1164 bus_connection_add_match_rule_link (connection, link);
1170 bus_connection_remove_match_rule (DBusConnection *connection,
1173 BusConnectionData *d;
1175 d = BUS_CONNECTION_DATA (connection);
1176 _dbus_assert (d != NULL);
1178 _dbus_list_remove_last (&d->match_rules, rule);
1180 d->n_match_rules -= 1;
1181 _dbus_assert (d->n_match_rules >= 0);
1185 bus_connection_get_n_match_rules (DBusConnection *connection)
1187 BusConnectionData *d;
1189 d = BUS_CONNECTION_DATA (connection);
1190 _dbus_assert (d != NULL);
1192 return d->n_match_rules;
1196 bus_connection_add_owned_service_link (DBusConnection *connection,
1199 BusConnectionData *d;
1201 d = BUS_CONNECTION_DATA (connection);
1202 _dbus_assert (d != NULL);
1204 _dbus_list_append_link (&d->services_owned, link);
1206 d->n_services_owned += 1;
1210 bus_connection_add_owned_service (DBusConnection *connection,
1211 BusService *service)
1215 link = _dbus_list_alloc_link (service);
1220 bus_connection_add_owned_service_link (connection, link);
1226 bus_connection_remove_owned_service (DBusConnection *connection,
1227 BusService *service)
1229 BusConnectionData *d;
1231 d = BUS_CONNECTION_DATA (connection);
1232 _dbus_assert (d != NULL);
1234 _dbus_list_remove_last (&d->services_owned, service);
1236 d->n_services_owned -= 1;
1237 _dbus_assert (d->n_services_owned >= 0);
1241 bus_connection_get_n_services_owned (DBusConnection *connection)
1243 BusConnectionData *d;
1245 d = BUS_CONNECTION_DATA (connection);
1246 _dbus_assert (d != NULL);
1248 return d->n_services_owned;
1252 bus_connection_complete (DBusConnection *connection,
1253 const DBusString *name,
1256 BusConnectionData *d;
1259 d = BUS_CONNECTION_DATA (connection);
1260 _dbus_assert (d != NULL);
1261 _dbus_assert (d->name == NULL);
1262 _dbus_assert (d->policy == NULL);
1264 _dbus_assert (!bus_connection_is_active (connection));
1266 if (!_dbus_string_copy_data (name, &d->name))
1268 BUS_SET_OOM (error);
1272 _dbus_assert (d->name != NULL);
1274 _dbus_verbose ("Name %s assigned to %p\n", d->name, connection);
1276 d->policy = bus_context_create_client_policy (d->connections->context,
1280 /* we may have a NULL policy on OOM or error getting list of
1281 * groups for a user. In the latter case we don't handle it so
1282 * well currently, as it will just keep failing over and over.
1285 if (d->policy == NULL)
1287 _dbus_verbose ("Failed to create security policy for connection %p\n",
1289 _DBUS_ASSERT_ERROR_IS_SET (error);
1290 dbus_free (d->name);
1295 if (dbus_connection_get_unix_user (connection, &uid))
1297 if (!adjust_connections_for_uid (d->connections,
1300 BUS_SET_OOM (error);
1301 dbus_free (d->name);
1307 /* Now the connection is active, move it between lists */
1308 _dbus_list_unlink (&d->connections->incomplete,
1309 d->link_in_connection_list);
1310 d->connections->n_incomplete -= 1;
1311 _dbus_list_append_link (&d->connections->completed,
1312 d->link_in_connection_list);
1313 d->connections->n_completed += 1;
1315 _dbus_assert (d->connections->n_incomplete >= 0);
1316 _dbus_assert (d->connections->n_completed > 0);
1318 /* See if we can remove the timeout */
1319 bus_connections_expire_incomplete (d->connections);
1321 _dbus_assert (bus_connection_is_active (connection));
1327 bus_connection_get_name (DBusConnection *connection)
1329 BusConnectionData *d;
1331 d = BUS_CONNECTION_DATA (connection);
1332 _dbus_assert (d != NULL);
1338 * Check whether completing the passed-in connection would
1339 * exceed limits, and if so set error and return #FALSE
1342 bus_connections_check_limits (BusConnections *connections,
1343 DBusConnection *requesting_completion,
1346 BusConnectionData *d;
1349 d = BUS_CONNECTION_DATA (requesting_completion);
1350 _dbus_assert (d != NULL);
1352 _dbus_assert (d->name == NULL);
1354 if (connections->n_completed >=
1355 bus_context_get_max_completed_connections (connections->context))
1357 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1358 "The maximum number of active connections has been reached");
1362 if (dbus_connection_get_unix_user (requesting_completion, &uid))
1364 if (get_connections_for_uid (connections, uid) >=
1365 bus_context_get_max_connections_per_user (connections->context))
1367 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1368 "The maximum number of active connections for UID %lu has been reached",
1378 bus_pending_reply_free (BusPendingReply *pending)
1380 _dbus_verbose ("Freeing pending reply %p, replier %p receiver %p serial %u\n",
1382 pending->will_send_reply,
1383 pending->will_get_reply,
1384 pending->reply_serial);
1386 dbus_free (pending);
1390 bus_pending_reply_send_no_reply (BusConnections *connections,
1391 BusTransaction *transaction,
1392 BusPendingReply *pending)
1394 DBusMessage *message;
1395 DBusMessageIter iter;
1401 message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1402 if (message == NULL)
1405 dbus_message_set_no_reply (message, TRUE);
1407 if (!dbus_message_set_reply_serial (message,
1408 pending->reply_serial))
1411 if (!dbus_message_set_error_name (message,
1412 DBUS_ERROR_NO_REPLY))
1415 errmsg = "Message did not receive a reply (timeout by message bus)";
1416 dbus_message_iter_init_append (message, &iter);
1417 if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &errmsg))
1420 if (!bus_transaction_send_from_driver (transaction, pending->will_get_reply,
1427 dbus_message_unref (message);
1432 bus_pending_reply_expired (BusExpireList *list,
1436 BusPendingReply *pending = link->data;
1437 BusConnections *connections = data;
1438 BusTransaction *transaction;
1440 /* No reply is forthcoming. So nuke it if we can. If not,
1441 * leave it in the list to try expiring again later when we
1445 _dbus_verbose ("Expiring pending reply %p, replier %p receiver %p serial %u\n",
1447 pending->will_send_reply,
1448 pending->will_get_reply,
1449 pending->reply_serial);
1451 transaction = bus_transaction_new (connections->context);
1452 if (transaction == NULL)
1455 if (!bus_pending_reply_send_no_reply (connections,
1459 bus_transaction_cancel_and_free (transaction);
1463 _dbus_list_remove_link (&connections->pending_replies->items,
1465 bus_pending_reply_free (pending);
1466 bus_transaction_execute_and_free (transaction);
1472 bus_connection_drop_pending_replies (BusConnections *connections,
1473 DBusConnection *connection)
1475 /* The DBusConnection is almost 100% finalized here, so you can't
1476 * do anything with it except check for pointer equality
1480 _dbus_verbose ("Dropping pending replies that involve connection %p\n",
1483 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1484 while (link != NULL)
1487 BusPendingReply *pending;
1489 next = _dbus_list_get_next_link (&connections->pending_replies->items,
1491 pending = link->data;
1493 if (pending->will_get_reply == connection)
1495 /* We don't need to track this pending reply anymore */
1497 _dbus_verbose ("Dropping pending reply %p, replier %p receiver %p serial %u\n",
1499 pending->will_send_reply,
1500 pending->will_get_reply,
1501 pending->reply_serial);
1503 _dbus_list_remove_link (&connections->pending_replies->items,
1505 bus_pending_reply_free (pending);
1507 else if (pending->will_send_reply == connection)
1509 /* The reply isn't going to be sent, so set things
1510 * up so it will be expired right away
1512 _dbus_verbose ("Will expire pending reply %p, replier %p receiver %p serial %u\n",
1514 pending->will_send_reply,
1515 pending->will_get_reply,
1516 pending->reply_serial);
1518 pending->will_send_reply = NULL;
1519 pending->expire_item.added_tv_sec = 0;
1520 pending->expire_item.added_tv_usec = 0;
1522 bus_expire_timeout_set_interval (connections->pending_replies->timeout,
1533 BusPendingReply *pending;
1534 BusConnections *connections;
1535 } CancelPendingReplyData;
1538 cancel_pending_reply (void *data)
1540 CancelPendingReplyData *d = data;
1542 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1544 if (!_dbus_list_remove (&d->connections->pending_replies->items,
1546 _dbus_assert_not_reached ("pending reply did not exist to be cancelled");
1548 bus_pending_reply_free (d->pending); /* since it's been cancelled */
1552 cancel_pending_reply_data_free (void *data)
1554 CancelPendingReplyData *d = data;
1556 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1558 /* d->pending should be either freed or still
1559 * in the list of pending replies (owned by someone
1567 * Record that a reply is allowed; return TRUE on success.
1570 bus_connections_expect_reply (BusConnections *connections,
1571 BusTransaction *transaction,
1572 DBusConnection *will_get_reply,
1573 DBusConnection *will_send_reply,
1574 DBusMessage *reply_to_this,
1577 BusPendingReply *pending;
1578 dbus_uint32_t reply_serial;
1580 CancelPendingReplyData *cprd;
1583 _dbus_assert (will_get_reply != NULL);
1584 _dbus_assert (will_send_reply != NULL);
1585 _dbus_assert (reply_to_this != NULL);
1587 if (dbus_message_get_no_reply (reply_to_this))
1588 return TRUE; /* we won't allow a reply, since client doesn't care for one. */
1590 reply_serial = dbus_message_get_serial (reply_to_this);
1592 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1594 while (link != NULL)
1596 pending = link->data;
1598 if (pending->reply_serial == reply_serial &&
1599 pending->will_get_reply == will_get_reply &&
1600 pending->will_send_reply == will_send_reply)
1602 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1603 "Message has the same reply serial as a currently-outstanding existing method call");
1607 link = _dbus_list_get_next_link (&connections->pending_replies->items,
1609 if (pending->will_get_reply == will_get_reply)
1614 bus_context_get_max_replies_per_connection (connections->context))
1616 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1617 "The maximum number of pending replies per connection has been reached");
1621 pending = dbus_new0 (BusPendingReply, 1);
1622 if (pending == NULL)
1624 BUS_SET_OOM (error);
1628 #ifdef DBUS_ENABLE_VERBOSE_MODE
1629 /* so we can see a not-yet-added pending reply */
1630 pending->expire_item.added_tv_sec = 1;
1631 pending->expire_item.added_tv_usec = 1;
1634 pending->will_get_reply = will_get_reply;
1635 pending->will_send_reply = will_send_reply;
1636 pending->reply_serial = reply_serial;
1638 cprd = dbus_new0 (CancelPendingReplyData, 1);
1641 BUS_SET_OOM (error);
1642 bus_pending_reply_free (pending);
1646 if (!_dbus_list_prepend (&connections->pending_replies->items,
1649 BUS_SET_OOM (error);
1651 bus_pending_reply_free (pending);
1655 if (!bus_transaction_add_cancel_hook (transaction,
1656 cancel_pending_reply,
1658 cancel_pending_reply_data_free))
1660 BUS_SET_OOM (error);
1661 _dbus_list_remove (&connections->pending_replies->items, pending);
1663 bus_pending_reply_free (pending);
1667 cprd->pending = pending;
1668 cprd->connections = connections;
1670 _dbus_get_current_time (&pending->expire_item.added_tv_sec,
1671 &pending->expire_item.added_tv_usec);
1673 _dbus_verbose ("Added pending reply %p, replier %p receiver %p serial %u\n",
1675 pending->will_send_reply,
1676 pending->will_get_reply,
1677 pending->reply_serial);
1685 BusConnections *connections;
1686 } CheckPendingReplyData;
1689 cancel_check_pending_reply (void *data)
1691 CheckPendingReplyData *d = data;
1693 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1695 _dbus_list_prepend_link (&d->connections->pending_replies->items,
1701 check_pending_reply_data_free (void *data)
1703 CheckPendingReplyData *d = data;
1705 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1707 if (d->link != NULL)
1709 BusPendingReply *pending = d->link->data;
1711 _dbus_assert (_dbus_list_find_last (&d->connections->pending_replies->items,
1714 bus_pending_reply_free (pending);
1715 _dbus_list_free_link (d->link);
1722 * Check whether a reply is allowed, remove BusPendingReply
1723 * if so, return TRUE if so.
1726 bus_connections_check_reply (BusConnections *connections,
1727 BusTransaction *transaction,
1728 DBusConnection *sending_reply,
1729 DBusConnection *receiving_reply,
1733 CheckPendingReplyData *cprd;
1735 dbus_uint32_t reply_serial;
1737 _dbus_assert (sending_reply != NULL);
1738 _dbus_assert (receiving_reply != NULL);
1740 reply_serial = dbus_message_get_reply_serial (reply);
1742 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1743 while (link != NULL)
1745 BusPendingReply *pending = link->data;
1747 if (pending->reply_serial == reply_serial &&
1748 pending->will_get_reply == receiving_reply &&
1749 pending->will_send_reply == sending_reply)
1751 _dbus_verbose ("Found pending reply with serial %u\n", reply_serial);
1755 link = _dbus_list_get_next_link (&connections->pending_replies->items,
1761 _dbus_verbose ("No pending reply expected\n");
1766 cprd = dbus_new0 (CheckPendingReplyData, 1);
1769 BUS_SET_OOM (error);
1773 if (!bus_transaction_add_cancel_hook (transaction,
1774 cancel_check_pending_reply,
1776 check_pending_reply_data_free))
1778 BUS_SET_OOM (error);
1784 cprd->connections = connections;
1786 _dbus_list_unlink (&connections->pending_replies->items,
1789 _dbus_assert (_dbus_list_find_last (&connections->pending_replies->items,
1790 link->data) == NULL);
1798 * Note that this is fairly fragile; in particular, don't try to use
1799 * one transaction across any main loop iterations.
1804 BusTransaction *transaction;
1805 DBusMessage *message;
1806 DBusPreallocatedSend *preallocated;
1811 BusTransactionCancelFunction cancel_function;
1812 DBusFreeFunction free_data_function;
1816 struct BusTransaction
1818 DBusList *connections;
1819 BusContext *context;
1820 DBusList *cancel_hooks;
1824 message_to_send_free (DBusConnection *connection,
1825 MessageToSend *to_send)
1827 if (to_send->message)
1828 dbus_message_unref (to_send->message);
1830 if (to_send->preallocated)
1831 dbus_connection_free_preallocated_send (connection, to_send->preallocated);
1833 dbus_free (to_send);
1837 cancel_hook_cancel (void *element,
1840 CancelHook *ch = element;
1842 _dbus_verbose ("Running transaction cancel hook\n");
1844 if (ch->cancel_function)
1845 (* ch->cancel_function) (ch->data);
1849 cancel_hook_free (void *element,
1852 CancelHook *ch = element;
1854 if (ch->free_data_function)
1855 (* ch->free_data_function) (ch->data);
1861 free_cancel_hooks (BusTransaction *transaction)
1863 _dbus_list_foreach (&transaction->cancel_hooks,
1864 cancel_hook_free, NULL);
1866 _dbus_list_clear (&transaction->cancel_hooks);
1870 bus_transaction_new (BusContext *context)
1872 BusTransaction *transaction;
1874 transaction = dbus_new0 (BusTransaction, 1);
1875 if (transaction == NULL)
1878 transaction->context = context;
1884 bus_transaction_get_context (BusTransaction *transaction)
1886 return transaction->context;
1890 bus_transaction_get_connections (BusTransaction *transaction)
1892 return bus_context_get_connections (transaction->context);
1896 bus_transaction_send_from_driver (BusTransaction *transaction,
1897 DBusConnection *connection,
1898 DBusMessage *message)
1900 /* We have to set the sender to the driver, and have
1901 * to check security policy since it was not done in
1904 _dbus_verbose ("Sending %s %s %s from driver\n",
1905 dbus_message_get_interface (message) ?
1906 dbus_message_get_interface (message) : "(no interface)",
1907 dbus_message_get_member (message) ?
1908 dbus_message_get_member (message) : "(no member)",
1909 dbus_message_get_error_name (message) ?
1910 dbus_message_get_error_name (message) : "(no error name)");
1912 if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
1915 if (bus_connection_is_active (connection))
1917 if (!dbus_message_set_destination (message,
1918 bus_connection_get_name (connection)))
1922 /* bus driver never wants a reply */
1923 dbus_message_set_no_reply (message, TRUE);
1925 /* If security policy doesn't allow the message, we silently
1926 * eat it; the driver doesn't care about getting a reply.
1928 if (!bus_context_check_security_policy (bus_transaction_get_context (transaction),
1930 NULL, connection, connection, message, NULL))
1933 return bus_transaction_send (transaction, connection, message);
1937 bus_transaction_send (BusTransaction *transaction,
1938 DBusConnection *connection,
1939 DBusMessage *message)
1941 MessageToSend *to_send;
1942 BusConnectionData *d;
1945 _dbus_verbose (" trying to add %s interface=%s member=%s error=%s to transaction%s\n",
1946 dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR ? "error" :
1947 dbus_message_get_reply_serial (message) != 0 ? "reply" :
1949 dbus_message_get_interface (message) ?
1950 dbus_message_get_interface (message) : "(unset)",
1951 dbus_message_get_member (message) ?
1952 dbus_message_get_member (message) : "(unset)",
1953 dbus_message_get_error_name (message) ?
1954 dbus_message_get_error_name (message) : "(unset)",
1955 dbus_connection_get_is_connected (connection) ?
1956 "" : " (disconnected)");
1958 _dbus_assert (dbus_message_get_sender (message) != NULL);
1960 if (!dbus_connection_get_is_connected (connection))
1961 return TRUE; /* silently ignore disconnected connections */
1963 d = BUS_CONNECTION_DATA (connection);
1964 _dbus_assert (d != NULL);
1966 to_send = dbus_new (MessageToSend, 1);
1967 if (to_send == NULL)
1972 to_send->preallocated = dbus_connection_preallocate_send (connection);
1973 if (to_send->preallocated == NULL)
1975 dbus_free (to_send);
1979 dbus_message_ref (message);
1980 to_send->message = message;
1981 to_send->transaction = transaction;
1983 _dbus_verbose ("about to prepend message\n");
1985 if (!_dbus_list_prepend (&d->transaction_messages, to_send))
1987 message_to_send_free (connection, to_send);
1991 _dbus_verbose ("prepended message\n");
1993 /* See if we already had this connection in the list
1994 * for this transaction. If we have a pending message,
1995 * then we should already be in transaction->connections
1997 link = _dbus_list_get_first_link (&d->transaction_messages);
1998 _dbus_assert (link->data == to_send);
1999 link = _dbus_list_get_next_link (&d->transaction_messages, link);
2000 while (link != NULL)
2002 MessageToSend *m = link->data;
2003 DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
2005 if (m->transaction == transaction)
2013 if (!_dbus_list_prepend (&transaction->connections, connection))
2015 _dbus_list_remove (&d->transaction_messages, to_send);
2016 message_to_send_free (connection, to_send);
2025 connection_cancel_transaction (DBusConnection *connection,
2026 BusTransaction *transaction)
2029 BusConnectionData *d;
2031 d = BUS_CONNECTION_DATA (connection);
2032 _dbus_assert (d != NULL);
2034 link = _dbus_list_get_first_link (&d->transaction_messages);
2035 while (link != NULL)
2037 MessageToSend *m = link->data;
2038 DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
2040 if (m->transaction == transaction)
2042 _dbus_list_remove_link (&d->transaction_messages,
2045 message_to_send_free (connection, m);
2053 bus_transaction_cancel_and_free (BusTransaction *transaction)
2055 DBusConnection *connection;
2057 _dbus_verbose ("TRANSACTION: cancelled\n");
2059 while ((connection = _dbus_list_pop_first (&transaction->connections)))
2060 connection_cancel_transaction (connection, transaction);
2062 _dbus_assert (transaction->connections == NULL);
2064 _dbus_list_foreach (&transaction->cancel_hooks,
2065 cancel_hook_cancel, NULL);
2067 free_cancel_hooks (transaction);
2069 dbus_free (transaction);
2073 connection_execute_transaction (DBusConnection *connection,
2074 BusTransaction *transaction)
2077 BusConnectionData *d;
2079 d = BUS_CONNECTION_DATA (connection);
2080 _dbus_assert (d != NULL);
2082 /* Send the queue in order (FIFO) */
2083 link = _dbus_list_get_last_link (&d->transaction_messages);
2084 while (link != NULL)
2086 MessageToSend *m = link->data;
2087 DBusList *prev = _dbus_list_get_prev_link (&d->transaction_messages, link);
2089 if (m->transaction == transaction)
2091 _dbus_list_remove_link (&d->transaction_messages,
2094 _dbus_assert (dbus_message_get_sender (m->message) != NULL);
2096 dbus_connection_send_preallocated (connection,
2101 m->preallocated = NULL; /* so we don't double-free it */
2103 message_to_send_free (connection, m);
2111 bus_transaction_execute_and_free (BusTransaction *transaction)
2113 /* For each connection in transaction->connections
2116 DBusConnection *connection;
2118 _dbus_verbose ("TRANSACTION: executing\n");
2120 while ((connection = _dbus_list_pop_first (&transaction->connections)))
2121 connection_execute_transaction (connection, transaction);
2123 _dbus_assert (transaction->connections == NULL);
2125 free_cancel_hooks (transaction);
2127 dbus_free (transaction);
2131 bus_connection_remove_transactions (DBusConnection *connection)
2133 MessageToSend *to_send;
2134 BusConnectionData *d;
2136 d = BUS_CONNECTION_DATA (connection);
2137 _dbus_assert (d != NULL);
2139 while ((to_send = _dbus_list_get_first (&d->transaction_messages)))
2141 /* only has an effect for the first MessageToSend listing this transaction */
2142 _dbus_list_remove (&to_send->transaction->connections,
2145 _dbus_list_remove (&d->transaction_messages, to_send);
2146 message_to_send_free (connection, to_send);
2151 * Converts the DBusError to a message reply
2154 bus_transaction_send_error_reply (BusTransaction *transaction,
2155 DBusConnection *connection,
2156 const DBusError *error,
2157 DBusMessage *in_reply_to)
2161 _dbus_assert (error != NULL);
2162 _DBUS_ASSERT_ERROR_IS_SET (error);
2164 _dbus_verbose ("Sending error reply %s \"%s\"\n",
2165 error->name, error->message);
2167 reply = dbus_message_new_error (in_reply_to,
2173 if (!bus_transaction_send_from_driver (transaction, connection, reply))
2175 dbus_message_unref (reply);
2179 dbus_message_unref (reply);
2185 bus_transaction_add_cancel_hook (BusTransaction *transaction,
2186 BusTransactionCancelFunction cancel_function,
2188 DBusFreeFunction free_data_function)
2192 ch = dbus_new (CancelHook, 1);
2196 _dbus_verbose (" adding cancel hook function = %p data = %p\n",
2197 cancel_function, data);
2199 ch->cancel_function = cancel_function;
2201 ch->free_data_function = free_data_function;
2203 /* It's important that the hooks get run in reverse order that they
2206 if (!_dbus_list_prepend (&transaction->cancel_hooks, ch))