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. 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
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))
567 dbus_connection_set_route_peer_messages (connection, TRUE);
571 dbus_error_init (&error);
572 d->selinux_id = bus_selinux_init_connection_id (connection,
574 if (dbus_error_is_set (&error))
576 /* This is a bit bogus because we pretend all errors
577 * are OOM; this is done because we know that in bus.c
578 * an OOM error disconnects the connection, which is
579 * the same thing we want on any other error.
581 dbus_error_free (&error);
585 if (!dbus_connection_set_watch_functions (connection,
586 add_connection_watch,
587 remove_connection_watch,
593 if (!dbus_connection_set_timeout_functions (connection,
594 add_connection_timeout,
595 remove_connection_timeout,
600 dbus_connection_set_unix_user_function (connection,
604 dbus_connection_set_dispatch_status_function (connection,
605 dispatch_status_function,
606 bus_context_get_loop (connections->context),
609 d->link_in_connection_list = _dbus_list_alloc_link (connection);
610 if (d->link_in_connection_list == NULL)
613 /* Setup the connection with the dispatcher */
614 if (!bus_dispatch_add_connection (connection))
617 if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
619 if (!_dbus_loop_queue_dispatch (bus_context_get_loop (connections->context), connection))
621 bus_dispatch_remove_connection (connection);
626 _dbus_list_append_link (&connections->incomplete, d->link_in_connection_list);
627 connections->n_incomplete += 1;
629 dbus_connection_ref (connection);
631 /* Note that we might disconnect ourselves here, but it only takes
632 * effect on return to the main loop. We call this to free up
633 * expired connections if possible, and to queue the timeout for our
636 bus_connections_expire_incomplete (connections);
638 /* And we might also disconnect ourselves here, but again it
639 * only takes effect on return to main loop.
641 if (connections->n_incomplete >
642 bus_context_get_max_incomplete_connections (connections->context))
644 _dbus_verbose ("Number of incomplete connections exceeds max, dropping oldest one\n");
646 _dbus_assert (connections->incomplete != NULL);
647 /* Disconnect the oldest unauthenticated connection. FIXME
648 * would it be more secure to drop a *random* connection? This
649 * algorithm seems to mean that if someone can create new
650 * connections quickly enough, they can keep anyone else from
651 * completing authentication. But random may or may not really
652 * help with that, a more elaborate solution might be required.
654 dbus_connection_close (connections->incomplete->data);
663 bus_selinux_id_unref (d->selinux_id);
664 d->selinux_id = NULL;
666 if (!dbus_connection_set_watch_functions (connection,
670 _dbus_assert_not_reached ("setting watch functions to NULL failed");
672 if (!dbus_connection_set_timeout_functions (connection,
676 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
678 dbus_connection_set_unix_user_function (connection,
681 dbus_connection_set_dispatch_status_function (connection,
684 if (d->link_in_connection_list != NULL)
686 _dbus_assert (d->link_in_connection_list->next == NULL);
687 _dbus_assert (d->link_in_connection_list->prev == NULL);
688 _dbus_list_free_link (d->link_in_connection_list);
689 d->link_in_connection_list = NULL;
692 if (!dbus_connection_set_data (connection,
693 connection_data_slot,
695 _dbus_assert_not_reached ("failed to set connection data to null");
697 /* "d" has now been freed */
704 bus_connections_expire_incomplete (BusConnections *connections)
710 if (connections->incomplete != NULL)
712 long tv_sec, tv_usec;
716 _dbus_get_current_time (&tv_sec, &tv_usec);
717 auth_timeout = bus_context_get_auth_timeout (connections->context);
719 link = _dbus_list_get_first_link (&connections->incomplete);
722 DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
723 DBusConnection *connection;
724 BusConnectionData *d;
727 connection = link->data;
729 d = BUS_CONNECTION_DATA (connection);
731 _dbus_assert (d != NULL);
733 elapsed = ELAPSED_MILLISECONDS_SINCE (d->connection_tv_sec,
734 d->connection_tv_usec,
737 if (elapsed >= (double) auth_timeout)
739 _dbus_verbose ("Timing out authentication for connection %p\n", connection);
740 dbus_connection_close (connection);
744 /* We can end the loop, since the connections are in oldest-first order */
745 next_interval = ((double)auth_timeout) - elapsed;
746 _dbus_verbose ("Connection %p authentication expires in %d milliseconds\n",
747 connection, next_interval);
756 bus_expire_timeout_set_interval (connections->expire_timeout,
761 expire_incomplete_timeout (void *data)
763 BusConnections *connections = data;
765 _dbus_verbose ("Running %s\n", _DBUS_FUNCTION_NAME);
767 /* note that this may remove the timeout */
768 bus_connections_expire_incomplete (connections);
774 bus_connection_get_groups (DBusConnection *connection,
775 unsigned long **groups,
779 BusConnectionData *d;
781 DBusUserDatabase *user_database;
783 d = BUS_CONNECTION_DATA (connection);
785 _dbus_assert (d != NULL);
787 user_database = bus_context_get_user_database (d->connections->context);
792 if (dbus_connection_get_unix_user (connection, &uid))
794 if (!_dbus_user_database_get_groups (user_database,
795 uid, groups, n_groups,
798 _DBUS_ASSERT_ERROR_IS_SET (error);
799 _dbus_verbose ("Did not get any groups for UID %lu\n",
805 _dbus_verbose ("Got %d groups for UID %lu\n",
811 return TRUE; /* successfully got 0 groups */
815 bus_connection_is_in_group (DBusConnection *connection,
819 unsigned long *group_ids;
822 if (!bus_connection_get_groups (connection, &group_ids, &n_group_ids,
827 while (i < n_group_ids)
829 if (group_ids[i] == gid)
831 dbus_free (group_ids);
837 dbus_free (group_ids);
842 bus_connection_get_policy (DBusConnection *connection)
844 BusConnectionData *d;
846 d = BUS_CONNECTION_DATA (connection);
848 _dbus_assert (d != NULL);
849 _dbus_assert (d->policy != NULL);
855 foreach_active (BusConnections *connections,
856 BusConnectionForeachFunction function,
861 link = _dbus_list_get_first_link (&connections->completed);
864 DBusConnection *connection = link->data;
865 DBusList *next = _dbus_list_get_next_link (&connections->completed, link);
867 if (!(* function) (connection, data))
877 foreach_inactive (BusConnections *connections,
878 BusConnectionForeachFunction function,
883 link = _dbus_list_get_first_link (&connections->incomplete);
886 DBusConnection *connection = link->data;
887 DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
889 if (!(* function) (connection, data))
899 * Calls function on each active connection; if the function returns
900 * #FALSE, stops iterating. Active connections are authenticated
901 * and have sent a Hello message.
903 * @param connections the connections object
904 * @param function the function
905 * @param data data to pass to it as a second arg
908 bus_connections_foreach_active (BusConnections *connections,
909 BusConnectionForeachFunction function,
912 foreach_active (connections, function, data);
916 * Calls function on each connection; if the function returns
917 * #FALSE, stops iterating.
919 * @param connections the connections object
920 * @param function the function
921 * @param data data to pass to it as a second arg
924 bus_connections_foreach (BusConnections *connections,
925 BusConnectionForeachFunction function,
928 if (!foreach_active (connections, function, data))
931 foreach_inactive (connections, function, data);
935 bus_connections_get_context (BusConnections *connections)
937 return connections->context;
941 * This is used to avoid covering the same connection twice when
942 * traversing connections. Note that it assumes we will
943 * bus_connection_mark_stamp() each connection at least once per
944 * INT_MAX increments of the global stamp, or wraparound would break
948 bus_connections_increment_stamp (BusConnections *connections)
950 connections->stamp += 1;
953 /* Mark connection with current stamp, return TRUE if it
954 * didn't already have that stamp
957 bus_connection_mark_stamp (DBusConnection *connection)
959 BusConnectionData *d;
961 d = BUS_CONNECTION_DATA (connection);
963 _dbus_assert (d != NULL);
965 if (d->stamp == d->connections->stamp)
969 d->stamp = d->connections->stamp;
975 bus_connection_get_context (DBusConnection *connection)
977 BusConnectionData *d;
979 d = BUS_CONNECTION_DATA (connection);
981 _dbus_assert (d != NULL);
983 return d->connections->context;
987 bus_connection_get_connections (DBusConnection *connection)
989 BusConnectionData *d;
991 d = BUS_CONNECTION_DATA (connection);
993 _dbus_assert (d != NULL);
995 return d->connections;
999 bus_connection_get_registry (DBusConnection *connection)
1001 BusConnectionData *d;
1003 d = BUS_CONNECTION_DATA (connection);
1005 _dbus_assert (d != NULL);
1007 return bus_context_get_registry (d->connections->context);
1011 bus_connection_get_activation (DBusConnection *connection)
1013 BusConnectionData *d;
1015 d = BUS_CONNECTION_DATA (connection);
1017 _dbus_assert (d != NULL);
1019 return bus_context_get_activation (d->connections->context);
1023 bus_connection_get_matchmaker (DBusConnection *connection)
1025 BusConnectionData *d;
1027 d = BUS_CONNECTION_DATA (connection);
1029 _dbus_assert (d != NULL);
1031 return bus_context_get_matchmaker (d->connections->context);
1035 bus_connection_get_selinux_id (DBusConnection *connection)
1037 BusConnectionData *d;
1039 d = BUS_CONNECTION_DATA (connection);
1041 _dbus_assert (d != NULL);
1043 return d->selinux_id;
1047 * Checks whether the connection is registered with the message bus.
1049 * @param connection the connection
1050 * @returns #TRUE if we're an active message bus participant
1053 bus_connection_is_active (DBusConnection *connection)
1055 BusConnectionData *d;
1057 d = BUS_CONNECTION_DATA (connection);
1059 return d != NULL && d->name != NULL;
1063 bus_connection_preallocate_oom_error (DBusConnection *connection)
1065 DBusMessage *message;
1066 DBusPreallocatedSend *preallocated;
1067 BusConnectionData *d;
1069 d = BUS_CONNECTION_DATA (connection);
1071 _dbus_assert (d != NULL);
1073 if (d->oom_preallocated != NULL)
1076 preallocated = dbus_connection_preallocate_send (connection);
1077 if (preallocated == NULL)
1080 message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1082 if (message == NULL)
1084 dbus_connection_free_preallocated_send (connection, preallocated);
1088 /* d->name may be NULL, but that is OK */
1089 if (!dbus_message_set_error_name (message, DBUS_ERROR_NO_MEMORY) ||
1090 !dbus_message_set_destination (message, d->name) ||
1091 !dbus_message_set_sender (message,
1094 dbus_connection_free_preallocated_send (connection, preallocated);
1095 dbus_message_unref (message);
1099 /* set reply serial to placeholder value just so space is already allocated
1102 if (!dbus_message_set_reply_serial (message, 14))
1104 dbus_connection_free_preallocated_send (connection, preallocated);
1105 dbus_message_unref (message);
1109 d->oom_message = message;
1110 d->oom_preallocated = preallocated;
1116 bus_connection_send_oom_error (DBusConnection *connection,
1117 DBusMessage *in_reply_to)
1119 BusConnectionData *d;
1121 d = BUS_CONNECTION_DATA (connection);
1123 _dbus_assert (d != NULL);
1124 _dbus_assert (d->oom_message != NULL);
1126 /* should always succeed since we set it to a placeholder earlier */
1127 if (!dbus_message_set_reply_serial (d->oom_message,
1128 dbus_message_get_serial (in_reply_to)))
1129 _dbus_assert_not_reached ("Failed to set reply serial for preallocated oom message");
1131 _dbus_assert (dbus_message_get_sender (d->oom_message) != NULL);
1133 dbus_connection_send_preallocated (connection, d->oom_preallocated,
1134 d->oom_message, NULL);
1136 dbus_message_unref (d->oom_message);
1137 d->oom_message = NULL;
1138 d->oom_preallocated = NULL;
1142 bus_connection_add_match_rule_link (DBusConnection *connection,
1145 BusConnectionData *d;
1147 d = BUS_CONNECTION_DATA (connection);
1148 _dbus_assert (d != NULL);
1150 _dbus_list_append_link (&d->match_rules, link);
1152 d->n_match_rules += 1;
1156 bus_connection_add_match_rule (DBusConnection *connection,
1161 link = _dbus_list_alloc_link (rule);
1166 bus_connection_add_match_rule_link (connection, link);
1172 bus_connection_remove_match_rule (DBusConnection *connection,
1175 BusConnectionData *d;
1177 d = BUS_CONNECTION_DATA (connection);
1178 _dbus_assert (d != NULL);
1180 _dbus_list_remove_last (&d->match_rules, rule);
1182 d->n_match_rules -= 1;
1183 _dbus_assert (d->n_match_rules >= 0);
1187 bus_connection_get_n_match_rules (DBusConnection *connection)
1189 BusConnectionData *d;
1191 d = BUS_CONNECTION_DATA (connection);
1192 _dbus_assert (d != NULL);
1194 return d->n_match_rules;
1198 bus_connection_add_owned_service_link (DBusConnection *connection,
1201 BusConnectionData *d;
1203 d = BUS_CONNECTION_DATA (connection);
1204 _dbus_assert (d != NULL);
1206 _dbus_list_append_link (&d->services_owned, link);
1208 d->n_services_owned += 1;
1212 bus_connection_add_owned_service (DBusConnection *connection,
1213 BusService *service)
1217 link = _dbus_list_alloc_link (service);
1222 bus_connection_add_owned_service_link (connection, link);
1228 bus_connection_remove_owned_service (DBusConnection *connection,
1229 BusService *service)
1231 BusConnectionData *d;
1233 d = BUS_CONNECTION_DATA (connection);
1234 _dbus_assert (d != NULL);
1236 _dbus_list_remove_last (&d->services_owned, service);
1238 d->n_services_owned -= 1;
1239 _dbus_assert (d->n_services_owned >= 0);
1243 bus_connection_get_n_services_owned (DBusConnection *connection)
1245 BusConnectionData *d;
1247 d = BUS_CONNECTION_DATA (connection);
1248 _dbus_assert (d != NULL);
1250 return d->n_services_owned;
1254 bus_connection_complete (DBusConnection *connection,
1255 const DBusString *name,
1258 BusConnectionData *d;
1261 d = BUS_CONNECTION_DATA (connection);
1262 _dbus_assert (d != NULL);
1263 _dbus_assert (d->name == NULL);
1264 _dbus_assert (d->policy == NULL);
1266 _dbus_assert (!bus_connection_is_active (connection));
1268 if (!_dbus_string_copy_data (name, &d->name))
1270 BUS_SET_OOM (error);
1274 _dbus_assert (d->name != NULL);
1276 _dbus_verbose ("Name %s assigned to %p\n", d->name, connection);
1278 d->policy = bus_context_create_client_policy (d->connections->context,
1282 /* we may have a NULL policy on OOM or error getting list of
1283 * groups for a user. In the latter case we don't handle it so
1284 * well currently, as it will just keep failing over and over.
1287 if (d->policy == NULL)
1289 _dbus_verbose ("Failed to create security policy for connection %p\n",
1291 _DBUS_ASSERT_ERROR_IS_SET (error);
1292 dbus_free (d->name);
1297 if (dbus_connection_get_unix_user (connection, &uid))
1299 if (!adjust_connections_for_uid (d->connections,
1302 BUS_SET_OOM (error);
1303 dbus_free (d->name);
1309 /* Now the connection is active, move it between lists */
1310 _dbus_list_unlink (&d->connections->incomplete,
1311 d->link_in_connection_list);
1312 d->connections->n_incomplete -= 1;
1313 _dbus_list_append_link (&d->connections->completed,
1314 d->link_in_connection_list);
1315 d->connections->n_completed += 1;
1317 _dbus_assert (d->connections->n_incomplete >= 0);
1318 _dbus_assert (d->connections->n_completed > 0);
1320 /* See if we can remove the timeout */
1321 bus_connections_expire_incomplete (d->connections);
1323 _dbus_assert (bus_connection_is_active (connection));
1329 bus_connection_get_name (DBusConnection *connection)
1331 BusConnectionData *d;
1333 d = BUS_CONNECTION_DATA (connection);
1334 _dbus_assert (d != NULL);
1340 * Check whether completing the passed-in connection would
1341 * exceed limits, and if so set error and return #FALSE
1344 bus_connections_check_limits (BusConnections *connections,
1345 DBusConnection *requesting_completion,
1348 BusConnectionData *d;
1351 d = BUS_CONNECTION_DATA (requesting_completion);
1352 _dbus_assert (d != NULL);
1354 _dbus_assert (d->name == NULL);
1356 if (connections->n_completed >=
1357 bus_context_get_max_completed_connections (connections->context))
1359 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1360 "The maximum number of active connections has been reached");
1364 if (dbus_connection_get_unix_user (requesting_completion, &uid))
1366 if (get_connections_for_uid (connections, uid) >=
1367 bus_context_get_max_connections_per_user (connections->context))
1369 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1370 "The maximum number of active connections for UID %lu has been reached",
1380 bus_pending_reply_free (BusPendingReply *pending)
1382 _dbus_verbose ("Freeing pending reply %p, replier %p receiver %p serial %u\n",
1384 pending->will_send_reply,
1385 pending->will_get_reply,
1386 pending->reply_serial);
1388 dbus_free (pending);
1392 bus_pending_reply_send_no_reply (BusConnections *connections,
1393 BusTransaction *transaction,
1394 BusPendingReply *pending)
1396 DBusMessage *message;
1397 DBusMessageIter iter;
1403 message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1404 if (message == NULL)
1407 dbus_message_set_no_reply (message, TRUE);
1409 if (!dbus_message_set_reply_serial (message,
1410 pending->reply_serial))
1413 if (!dbus_message_set_error_name (message,
1414 DBUS_ERROR_NO_REPLY))
1417 errmsg = "Message did not receive a reply (timeout by message bus)";
1418 dbus_message_iter_init_append (message, &iter);
1419 if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &errmsg))
1422 if (!bus_transaction_send_from_driver (transaction, pending->will_get_reply,
1429 dbus_message_unref (message);
1434 bus_pending_reply_expired (BusExpireList *list,
1438 BusPendingReply *pending = link->data;
1439 BusConnections *connections = data;
1440 BusTransaction *transaction;
1442 /* No reply is forthcoming. So nuke it if we can. If not,
1443 * leave it in the list to try expiring again later when we
1447 _dbus_verbose ("Expiring pending reply %p, replier %p receiver %p serial %u\n",
1449 pending->will_send_reply,
1450 pending->will_get_reply,
1451 pending->reply_serial);
1453 transaction = bus_transaction_new (connections->context);
1454 if (transaction == NULL)
1457 if (!bus_pending_reply_send_no_reply (connections,
1461 bus_transaction_cancel_and_free (transaction);
1465 _dbus_list_remove_link (&connections->pending_replies->items,
1467 bus_pending_reply_free (pending);
1468 bus_transaction_execute_and_free (transaction);
1474 bus_connection_drop_pending_replies (BusConnections *connections,
1475 DBusConnection *connection)
1477 /* The DBusConnection is almost 100% finalized here, so you can't
1478 * do anything with it except check for pointer equality
1482 _dbus_verbose ("Dropping pending replies that involve connection %p\n",
1485 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1486 while (link != NULL)
1489 BusPendingReply *pending;
1491 next = _dbus_list_get_next_link (&connections->pending_replies->items,
1493 pending = link->data;
1495 if (pending->will_get_reply == connection)
1497 /* We don't need to track this pending reply anymore */
1499 _dbus_verbose ("Dropping pending reply %p, replier %p receiver %p serial %u\n",
1501 pending->will_send_reply,
1502 pending->will_get_reply,
1503 pending->reply_serial);
1505 _dbus_list_remove_link (&connections->pending_replies->items,
1507 bus_pending_reply_free (pending);
1509 else if (pending->will_send_reply == connection)
1511 /* The reply isn't going to be sent, so set things
1512 * up so it will be expired right away
1514 _dbus_verbose ("Will expire pending reply %p, replier %p receiver %p serial %u\n",
1516 pending->will_send_reply,
1517 pending->will_get_reply,
1518 pending->reply_serial);
1520 pending->will_send_reply = NULL;
1521 pending->expire_item.added_tv_sec = 0;
1522 pending->expire_item.added_tv_usec = 0;
1524 bus_expire_timeout_set_interval (connections->pending_replies->timeout,
1535 BusPendingReply *pending;
1536 BusConnections *connections;
1537 } CancelPendingReplyData;
1540 cancel_pending_reply (void *data)
1542 CancelPendingReplyData *d = data;
1544 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1546 if (!_dbus_list_remove (&d->connections->pending_replies->items,
1548 _dbus_assert_not_reached ("pending reply did not exist to be cancelled");
1550 bus_pending_reply_free (d->pending); /* since it's been cancelled */
1554 cancel_pending_reply_data_free (void *data)
1556 CancelPendingReplyData *d = data;
1558 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1560 /* d->pending should be either freed or still
1561 * in the list of pending replies (owned by someone
1569 * Record that a reply is allowed; return TRUE on success.
1572 bus_connections_expect_reply (BusConnections *connections,
1573 BusTransaction *transaction,
1574 DBusConnection *will_get_reply,
1575 DBusConnection *will_send_reply,
1576 DBusMessage *reply_to_this,
1579 BusPendingReply *pending;
1580 dbus_uint32_t reply_serial;
1582 CancelPendingReplyData *cprd;
1585 _dbus_assert (will_get_reply != NULL);
1586 _dbus_assert (will_send_reply != NULL);
1587 _dbus_assert (reply_to_this != NULL);
1589 if (dbus_message_get_no_reply (reply_to_this))
1590 return TRUE; /* we won't allow a reply, since client doesn't care for one. */
1592 reply_serial = dbus_message_get_serial (reply_to_this);
1594 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1596 while (link != NULL)
1598 pending = link->data;
1600 if (pending->reply_serial == reply_serial &&
1601 pending->will_get_reply == will_get_reply &&
1602 pending->will_send_reply == will_send_reply)
1604 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1605 "Message has the same reply serial as a currently-outstanding existing method call");
1609 link = _dbus_list_get_next_link (&connections->pending_replies->items,
1611 if (pending->will_get_reply == will_get_reply)
1616 bus_context_get_max_replies_per_connection (connections->context))
1618 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1619 "The maximum number of pending replies per connection has been reached");
1623 pending = dbus_new0 (BusPendingReply, 1);
1624 if (pending == NULL)
1626 BUS_SET_OOM (error);
1630 #ifdef DBUS_ENABLE_VERBOSE_MODE
1631 /* so we can see a not-yet-added pending reply */
1632 pending->expire_item.added_tv_sec = 1;
1633 pending->expire_item.added_tv_usec = 1;
1636 pending->will_get_reply = will_get_reply;
1637 pending->will_send_reply = will_send_reply;
1638 pending->reply_serial = reply_serial;
1640 cprd = dbus_new0 (CancelPendingReplyData, 1);
1643 BUS_SET_OOM (error);
1644 bus_pending_reply_free (pending);
1648 if (!_dbus_list_prepend (&connections->pending_replies->items,
1651 BUS_SET_OOM (error);
1653 bus_pending_reply_free (pending);
1657 if (!bus_transaction_add_cancel_hook (transaction,
1658 cancel_pending_reply,
1660 cancel_pending_reply_data_free))
1662 BUS_SET_OOM (error);
1663 _dbus_list_remove (&connections->pending_replies->items, pending);
1665 bus_pending_reply_free (pending);
1669 cprd->pending = pending;
1670 cprd->connections = connections;
1672 _dbus_get_current_time (&pending->expire_item.added_tv_sec,
1673 &pending->expire_item.added_tv_usec);
1675 _dbus_verbose ("Added pending reply %p, replier %p receiver %p serial %u\n",
1677 pending->will_send_reply,
1678 pending->will_get_reply,
1679 pending->reply_serial);
1687 BusConnections *connections;
1688 } CheckPendingReplyData;
1691 cancel_check_pending_reply (void *data)
1693 CheckPendingReplyData *d = data;
1695 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1697 _dbus_list_prepend_link (&d->connections->pending_replies->items,
1703 check_pending_reply_data_free (void *data)
1705 CheckPendingReplyData *d = data;
1707 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1709 if (d->link != NULL)
1711 BusPendingReply *pending = d->link->data;
1713 _dbus_assert (_dbus_list_find_last (&d->connections->pending_replies->items,
1716 bus_pending_reply_free (pending);
1717 _dbus_list_free_link (d->link);
1724 * Check whether a reply is allowed, remove BusPendingReply
1725 * if so, return TRUE if so.
1728 bus_connections_check_reply (BusConnections *connections,
1729 BusTransaction *transaction,
1730 DBusConnection *sending_reply,
1731 DBusConnection *receiving_reply,
1735 CheckPendingReplyData *cprd;
1737 dbus_uint32_t reply_serial;
1739 _dbus_assert (sending_reply != NULL);
1740 _dbus_assert (receiving_reply != NULL);
1742 reply_serial = dbus_message_get_reply_serial (reply);
1744 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1745 while (link != NULL)
1747 BusPendingReply *pending = link->data;
1749 if (pending->reply_serial == reply_serial &&
1750 pending->will_get_reply == receiving_reply &&
1751 pending->will_send_reply == sending_reply)
1753 _dbus_verbose ("Found pending reply with serial %u\n", reply_serial);
1757 link = _dbus_list_get_next_link (&connections->pending_replies->items,
1763 _dbus_verbose ("No pending reply expected\n");
1768 cprd = dbus_new0 (CheckPendingReplyData, 1);
1771 BUS_SET_OOM (error);
1775 if (!bus_transaction_add_cancel_hook (transaction,
1776 cancel_check_pending_reply,
1778 check_pending_reply_data_free))
1780 BUS_SET_OOM (error);
1786 cprd->connections = connections;
1788 _dbus_list_unlink (&connections->pending_replies->items,
1791 _dbus_assert (_dbus_list_find_last (&connections->pending_replies->items,
1792 link->data) == NULL);
1800 * Note that this is fairly fragile; in particular, don't try to use
1801 * one transaction across any main loop iterations.
1806 BusTransaction *transaction;
1807 DBusMessage *message;
1808 DBusPreallocatedSend *preallocated;
1813 BusTransactionCancelFunction cancel_function;
1814 DBusFreeFunction free_data_function;
1818 struct BusTransaction
1820 DBusList *connections;
1821 BusContext *context;
1822 DBusList *cancel_hooks;
1826 message_to_send_free (DBusConnection *connection,
1827 MessageToSend *to_send)
1829 if (to_send->message)
1830 dbus_message_unref (to_send->message);
1832 if (to_send->preallocated)
1833 dbus_connection_free_preallocated_send (connection, to_send->preallocated);
1835 dbus_free (to_send);
1839 cancel_hook_cancel (void *element,
1842 CancelHook *ch = element;
1844 _dbus_verbose ("Running transaction cancel hook\n");
1846 if (ch->cancel_function)
1847 (* ch->cancel_function) (ch->data);
1851 cancel_hook_free (void *element,
1854 CancelHook *ch = element;
1856 if (ch->free_data_function)
1857 (* ch->free_data_function) (ch->data);
1863 free_cancel_hooks (BusTransaction *transaction)
1865 _dbus_list_foreach (&transaction->cancel_hooks,
1866 cancel_hook_free, NULL);
1868 _dbus_list_clear (&transaction->cancel_hooks);
1872 bus_transaction_new (BusContext *context)
1874 BusTransaction *transaction;
1876 transaction = dbus_new0 (BusTransaction, 1);
1877 if (transaction == NULL)
1880 transaction->context = context;
1886 bus_transaction_get_context (BusTransaction *transaction)
1888 return transaction->context;
1892 bus_transaction_get_connections (BusTransaction *transaction)
1894 return bus_context_get_connections (transaction->context);
1898 bus_transaction_send_from_driver (BusTransaction *transaction,
1899 DBusConnection *connection,
1900 DBusMessage *message)
1902 /* We have to set the sender to the driver, and have
1903 * to check security policy since it was not done in
1906 _dbus_verbose ("Sending %s %s %s from driver\n",
1907 dbus_message_get_interface (message) ?
1908 dbus_message_get_interface (message) : "(no interface)",
1909 dbus_message_get_member (message) ?
1910 dbus_message_get_member (message) : "(no member)",
1911 dbus_message_get_error_name (message) ?
1912 dbus_message_get_error_name (message) : "(no error name)");
1914 if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
1917 if (bus_connection_is_active (connection))
1919 if (!dbus_message_set_destination (message,
1920 bus_connection_get_name (connection)))
1924 /* bus driver never wants a reply */
1925 dbus_message_set_no_reply (message, TRUE);
1927 /* If security policy doesn't allow the message, we silently
1928 * eat it; the driver doesn't care about getting a reply.
1930 if (!bus_context_check_security_policy (bus_transaction_get_context (transaction),
1932 NULL, connection, connection, message, NULL))
1935 return bus_transaction_send (transaction, connection, message);
1939 bus_transaction_send (BusTransaction *transaction,
1940 DBusConnection *connection,
1941 DBusMessage *message)
1943 MessageToSend *to_send;
1944 BusConnectionData *d;
1947 _dbus_verbose (" trying to add %s interface=%s member=%s error=%s to transaction%s\n",
1948 dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR ? "error" :
1949 dbus_message_get_reply_serial (message) != 0 ? "reply" :
1951 dbus_message_get_interface (message) ?
1952 dbus_message_get_interface (message) : "(unset)",
1953 dbus_message_get_member (message) ?
1954 dbus_message_get_member (message) : "(unset)",
1955 dbus_message_get_error_name (message) ?
1956 dbus_message_get_error_name (message) : "(unset)",
1957 dbus_connection_get_is_connected (connection) ?
1958 "" : " (disconnected)");
1960 _dbus_assert (dbus_message_get_sender (message) != NULL);
1962 if (!dbus_connection_get_is_connected (connection))
1963 return TRUE; /* silently ignore disconnected connections */
1965 d = BUS_CONNECTION_DATA (connection);
1966 _dbus_assert (d != NULL);
1968 to_send = dbus_new (MessageToSend, 1);
1969 if (to_send == NULL)
1974 to_send->preallocated = dbus_connection_preallocate_send (connection);
1975 if (to_send->preallocated == NULL)
1977 dbus_free (to_send);
1981 dbus_message_ref (message);
1982 to_send->message = message;
1983 to_send->transaction = transaction;
1985 _dbus_verbose ("about to prepend message\n");
1987 if (!_dbus_list_prepend (&d->transaction_messages, to_send))
1989 message_to_send_free (connection, to_send);
1993 _dbus_verbose ("prepended message\n");
1995 /* See if we already had this connection in the list
1996 * for this transaction. If we have a pending message,
1997 * then we should already be in transaction->connections
1999 link = _dbus_list_get_first_link (&d->transaction_messages);
2000 _dbus_assert (link->data == to_send);
2001 link = _dbus_list_get_next_link (&d->transaction_messages, link);
2002 while (link != NULL)
2004 MessageToSend *m = link->data;
2005 DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
2007 if (m->transaction == transaction)
2015 if (!_dbus_list_prepend (&transaction->connections, connection))
2017 _dbus_list_remove (&d->transaction_messages, to_send);
2018 message_to_send_free (connection, to_send);
2027 connection_cancel_transaction (DBusConnection *connection,
2028 BusTransaction *transaction)
2031 BusConnectionData *d;
2033 d = BUS_CONNECTION_DATA (connection);
2034 _dbus_assert (d != NULL);
2036 link = _dbus_list_get_first_link (&d->transaction_messages);
2037 while (link != NULL)
2039 MessageToSend *m = link->data;
2040 DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
2042 if (m->transaction == transaction)
2044 _dbus_list_remove_link (&d->transaction_messages,
2047 message_to_send_free (connection, m);
2055 bus_transaction_cancel_and_free (BusTransaction *transaction)
2057 DBusConnection *connection;
2059 _dbus_verbose ("TRANSACTION: cancelled\n");
2061 while ((connection = _dbus_list_pop_first (&transaction->connections)))
2062 connection_cancel_transaction (connection, transaction);
2064 _dbus_assert (transaction->connections == NULL);
2066 _dbus_list_foreach (&transaction->cancel_hooks,
2067 cancel_hook_cancel, NULL);
2069 free_cancel_hooks (transaction);
2071 dbus_free (transaction);
2075 connection_execute_transaction (DBusConnection *connection,
2076 BusTransaction *transaction)
2079 BusConnectionData *d;
2081 d = BUS_CONNECTION_DATA (connection);
2082 _dbus_assert (d != NULL);
2084 /* Send the queue in order (FIFO) */
2085 link = _dbus_list_get_last_link (&d->transaction_messages);
2086 while (link != NULL)
2088 MessageToSend *m = link->data;
2089 DBusList *prev = _dbus_list_get_prev_link (&d->transaction_messages, link);
2091 if (m->transaction == transaction)
2093 _dbus_list_remove_link (&d->transaction_messages,
2096 _dbus_assert (dbus_message_get_sender (m->message) != NULL);
2098 dbus_connection_send_preallocated (connection,
2103 m->preallocated = NULL; /* so we don't double-free it */
2105 message_to_send_free (connection, m);
2113 bus_transaction_execute_and_free (BusTransaction *transaction)
2115 /* For each connection in transaction->connections
2118 DBusConnection *connection;
2120 _dbus_verbose ("TRANSACTION: executing\n");
2122 while ((connection = _dbus_list_pop_first (&transaction->connections)))
2123 connection_execute_transaction (connection, transaction);
2125 _dbus_assert (transaction->connections == NULL);
2127 free_cancel_hooks (transaction);
2129 dbus_free (transaction);
2133 bus_connection_remove_transactions (DBusConnection *connection)
2135 MessageToSend *to_send;
2136 BusConnectionData *d;
2138 d = BUS_CONNECTION_DATA (connection);
2139 _dbus_assert (d != NULL);
2141 while ((to_send = _dbus_list_get_first (&d->transaction_messages)))
2143 /* only has an effect for the first MessageToSend listing this transaction */
2144 _dbus_list_remove (&to_send->transaction->connections,
2147 _dbus_list_remove (&d->transaction_messages, to_send);
2148 message_to_send_free (connection, to_send);
2153 * Converts the DBusError to a message reply
2156 bus_transaction_send_error_reply (BusTransaction *transaction,
2157 DBusConnection *connection,
2158 const DBusError *error,
2159 DBusMessage *in_reply_to)
2163 _dbus_assert (error != NULL);
2164 _DBUS_ASSERT_ERROR_IS_SET (error);
2166 _dbus_verbose ("Sending error reply %s \"%s\"\n",
2167 error->name, error->message);
2169 reply = dbus_message_new_error (in_reply_to,
2175 if (!bus_transaction_send_from_driver (transaction, connection, reply))
2177 dbus_message_unref (reply);
2181 dbus_message_unref (reply);
2187 bus_transaction_add_cancel_hook (BusTransaction *transaction,
2188 BusTransactionCancelFunction cancel_function,
2190 DBusFreeFunction free_data_function)
2194 ch = dbus_new (CancelHook, 1);
2198 _dbus_verbose (" adding cancel hook function = %p data = %p\n",
2199 cancel_function, data);
2201 ch->cancel_function = cancel_function;
2203 ch->free_data_function = free_data_function;
2205 /* It's important that the hooks get run in reverse order that they
2208 if (!_dbus_list_prepend (&transaction->cancel_hooks, ch))