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 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);
203 while (transaction == NULL)
205 transaction = bus_transaction_new (d->connections->context);
206 _dbus_wait_for_memory ();
209 if (!bus_service_remove_owner (service, connection,
210 transaction, &error))
212 _DBUS_ASSERT_ERROR_IS_SET (&error);
214 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
216 dbus_error_free (&error);
217 bus_transaction_cancel_and_free (transaction);
218 _dbus_wait_for_memory ();
223 _dbus_verbose ("Failed to remove service owner: %s %s\n",
224 error.name, error.message);
225 _dbus_assert_not_reached ("Removing service owner failed for non-memory-related reason");
229 bus_transaction_execute_and_free (transaction);
232 bus_dispatch_remove_connection (connection);
234 /* no more watching */
235 if (!dbus_connection_set_watch_functions (connection,
239 _dbus_assert_not_reached ("setting watch functions to NULL failed");
241 if (!dbus_connection_set_timeout_functions (connection,
245 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
247 dbus_connection_set_unix_user_function (connection,
250 dbus_connection_set_dispatch_status_function (connection,
253 bus_connection_remove_transactions (connection);
255 if (d->link_in_connection_list != NULL)
261 _dbus_list_remove_link (&d->connections->completed, d->link_in_connection_list);
262 d->link_in_connection_list = NULL;
263 d->connections->n_completed -= 1;
265 if (dbus_connection_get_unix_user (connection, &uid))
267 if (!adjust_connections_for_uid (d->connections,
269 _dbus_assert_not_reached ("adjusting downward should never fail");
274 _dbus_list_remove_link (&d->connections->incomplete, d->link_in_connection_list);
275 d->link_in_connection_list = NULL;
276 d->connections->n_incomplete -= 1;
279 _dbus_assert (d->connections->n_incomplete >= 0);
280 _dbus_assert (d->connections->n_completed >= 0);
283 bus_connection_drop_pending_replies (d->connections, connection);
285 /* frees "d" as side effect */
286 dbus_connection_set_data (connection,
287 connection_data_slot,
290 dbus_connection_unref (connection);
294 connection_watch_callback (DBusWatch *watch,
295 unsigned int condition,
298 /* FIXME this can be done in dbus-mainloop.c
299 * if the code in activation.c for the babysitter
300 * watch handler is fixed.
304 _dbus_verbose ("Calling handle_watch\n");
306 return dbus_watch_handle (watch, condition);
310 add_connection_watch (DBusWatch *watch,
313 DBusConnection *connection = data;
315 return _dbus_loop_add_watch (connection_get_loop (connection),
316 watch, connection_watch_callback, connection,
321 remove_connection_watch (DBusWatch *watch,
324 DBusConnection *connection = data;
326 _dbus_loop_remove_watch (connection_get_loop (connection),
327 watch, connection_watch_callback, connection);
331 connection_timeout_callback (DBusTimeout *timeout,
334 /* DBusConnection *connection = data; */
336 /* can return FALSE on OOM but we just let it fire again later */
337 dbus_timeout_handle (timeout);
341 add_connection_timeout (DBusTimeout *timeout,
344 DBusConnection *connection = data;
346 return _dbus_loop_add_timeout (connection_get_loop (connection),
347 timeout, connection_timeout_callback, connection, NULL);
351 remove_connection_timeout (DBusTimeout *timeout,
354 DBusConnection *connection = data;
356 _dbus_loop_remove_timeout (connection_get_loop (connection),
357 timeout, connection_timeout_callback, connection);
361 dispatch_status_function (DBusConnection *connection,
362 DBusDispatchStatus new_status,
365 DBusLoop *loop = data;
367 if (new_status != DBUS_DISPATCH_COMPLETE)
369 while (!_dbus_loop_queue_dispatch (loop, connection))
370 _dbus_wait_for_memory ();
375 allow_user_function (DBusConnection *connection,
379 BusConnectionData *d;
381 d = BUS_CONNECTION_DATA (connection);
383 _dbus_assert (d != NULL);
385 return bus_context_allow_user (d->connections->context, uid);
389 free_connection_data (void *data)
391 BusConnectionData *d = data;
393 /* services_owned should be NULL since we should be disconnected */
394 _dbus_assert (d->services_owned == NULL);
395 _dbus_assert (d->n_services_owned == 0);
397 _dbus_assert (d->transaction_messages == NULL);
399 if (d->oom_preallocated)
400 dbus_connection_free_preallocated_send (d->connection, d->oom_preallocated);
403 dbus_message_unref (d->oom_message);
406 bus_client_policy_unref (d->policy);
409 bus_selinux_id_unref (d->selinux_id);
417 call_timeout_callback (DBusTimeout *timeout,
420 /* can return FALSE on OOM but we just let it fire again later */
421 dbus_timeout_handle (timeout);
425 bus_connections_new (BusContext *context)
427 BusConnections *connections;
429 if (!dbus_connection_allocate_data_slot (&connection_data_slot))
432 connections = dbus_new0 (BusConnections, 1);
433 if (connections == NULL)
436 connections->completed_by_user = _dbus_hash_table_new (DBUS_HASH_ULONG,
438 if (connections->completed_by_user == NULL)
441 connections->expire_timeout = _dbus_timeout_new (100, /* irrelevant */
442 expire_incomplete_timeout,
444 if (connections->expire_timeout == NULL)
447 _dbus_timeout_set_enabled (connections->expire_timeout, FALSE);
449 connections->pending_replies = bus_expire_list_new (bus_context_get_loop (context),
450 bus_context_get_reply_timeout (context),
451 bus_pending_reply_expired,
453 if (connections->pending_replies == NULL)
456 if (!_dbus_loop_add_timeout (bus_context_get_loop (context),
457 connections->expire_timeout,
458 call_timeout_callback, NULL, NULL))
461 connections->refcount = 1;
462 connections->context = context;
467 bus_expire_list_free (connections->pending_replies);
469 _dbus_timeout_unref (connections->expire_timeout);
471 _dbus_hash_table_unref (connections->completed_by_user);
473 dbus_free (connections);
475 dbus_connection_free_data_slot (&connection_data_slot);
481 bus_connections_ref (BusConnections *connections)
483 _dbus_assert (connections->refcount > 0);
484 connections->refcount += 1;
490 bus_connections_unref (BusConnections *connections)
492 _dbus_assert (connections->refcount > 0);
493 connections->refcount -= 1;
494 if (connections->refcount == 0)
496 /* drop all incomplete */
497 while (connections->incomplete != NULL)
499 DBusConnection *connection;
501 connection = connections->incomplete->data;
503 dbus_connection_ref (connection);
504 dbus_connection_disconnect (connection);
505 bus_connection_disconnected (connection);
506 dbus_connection_unref (connection);
509 _dbus_assert (connections->n_incomplete == 0);
511 /* drop all real connections */
512 while (connections->completed != NULL)
514 DBusConnection *connection;
516 connection = connections->completed->data;
518 dbus_connection_ref (connection);
519 dbus_connection_disconnect (connection);
520 bus_connection_disconnected (connection);
521 dbus_connection_unref (connection);
524 _dbus_assert (connections->n_completed == 0);
526 bus_expire_list_free (connections->pending_replies);
528 _dbus_loop_remove_timeout (bus_context_get_loop (connections->context),
529 connections->expire_timeout,
530 call_timeout_callback, NULL);
532 _dbus_timeout_unref (connections->expire_timeout);
534 _dbus_hash_table_unref (connections->completed_by_user);
536 dbus_free (connections);
538 dbus_connection_free_data_slot (&connection_data_slot);
543 bus_connections_setup_connection (BusConnections *connections,
544 DBusConnection *connection)
546 BusConnectionData *d;
550 d = dbus_new0 (BusConnectionData, 1);
555 d->connections = connections;
556 d->connection = connection;
558 _dbus_get_current_time (&d->connection_tv_sec,
559 &d->connection_tv_usec);
561 _dbus_assert (connection_data_slot >= 0);
563 if (!dbus_connection_set_data (connection,
564 connection_data_slot,
565 d, free_connection_data))
573 dbus_error_init (&error);
574 d->selinux_id = bus_selinux_init_connection_id (connection,
576 if (dbus_error_is_set (&error))
578 /* This is a bit bogus because we pretend all errors
579 * are OOM; this is done because we know that in bus.c
580 * an OOM error disconnects the connection, which is
581 * the same thing we want on any other error.
583 dbus_error_free (&error);
587 if (!dbus_connection_set_watch_functions (connection,
588 add_connection_watch,
589 remove_connection_watch,
595 if (!dbus_connection_set_timeout_functions (connection,
596 add_connection_timeout,
597 remove_connection_timeout,
602 dbus_connection_set_unix_user_function (connection,
606 dbus_connection_set_dispatch_status_function (connection,
607 dispatch_status_function,
608 bus_context_get_loop (connections->context),
611 d->link_in_connection_list = _dbus_list_alloc_link (connection);
612 if (d->link_in_connection_list == NULL)
615 /* Setup the connection with the dispatcher */
616 if (!bus_dispatch_add_connection (connection))
619 if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
621 if (!_dbus_loop_queue_dispatch (bus_context_get_loop (connections->context), connection))
623 bus_dispatch_remove_connection (connection);
628 _dbus_list_append_link (&connections->incomplete, d->link_in_connection_list);
629 connections->n_incomplete += 1;
631 dbus_connection_ref (connection);
633 /* Note that we might disconnect ourselves here, but it only takes
634 * effect on return to the main loop. We call this to free up
635 * expired connections if possible, and to queue the timeout for our
638 bus_connections_expire_incomplete (connections);
640 /* And we might also disconnect ourselves here, but again it
641 * only takes effect on return to main loop.
643 if (connections->n_incomplete >
644 bus_context_get_max_incomplete_connections (connections->context))
646 _dbus_verbose ("Number of incomplete connections exceeds max, dropping oldest one\n");
648 _dbus_assert (connections->incomplete != NULL);
649 /* Disconnect the oldest unauthenticated connection. FIXME
650 * would it be more secure to drop a *random* connection? This
651 * algorithm seems to mean that if someone can create new
652 * connections quickly enough, they can keep anyone else from
653 * completing authentication. But random may or may not really
654 * help with that, a more elaborate solution might be required.
656 dbus_connection_disconnect (connections->incomplete->data);
665 bus_selinux_id_unref (d->selinux_id);
666 d->selinux_id = NULL;
668 if (!dbus_connection_set_watch_functions (connection,
672 _dbus_assert_not_reached ("setting watch functions to NULL failed");
674 if (!dbus_connection_set_timeout_functions (connection,
678 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
680 dbus_connection_set_unix_user_function (connection,
683 dbus_connection_set_dispatch_status_function (connection,
686 if (d->link_in_connection_list != NULL)
688 _dbus_assert (d->link_in_connection_list->next == NULL);
689 _dbus_assert (d->link_in_connection_list->prev == NULL);
690 _dbus_list_free_link (d->link_in_connection_list);
691 d->link_in_connection_list = NULL;
694 if (!dbus_connection_set_data (connection,
695 connection_data_slot,
697 _dbus_assert_not_reached ("failed to set connection data to null");
699 /* "d" has now been freed */
706 bus_connections_expire_incomplete (BusConnections *connections)
712 if (connections->incomplete != NULL)
714 long tv_sec, tv_usec;
718 _dbus_get_current_time (&tv_sec, &tv_usec);
719 auth_timeout = bus_context_get_auth_timeout (connections->context);
721 link = _dbus_list_get_first_link (&connections->incomplete);
724 DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
725 DBusConnection *connection;
726 BusConnectionData *d;
729 connection = link->data;
731 d = BUS_CONNECTION_DATA (connection);
733 _dbus_assert (d != NULL);
735 elapsed = ELAPSED_MILLISECONDS_SINCE (d->connection_tv_sec,
736 d->connection_tv_usec,
739 if (elapsed >= (double) auth_timeout)
741 _dbus_verbose ("Timing out authentication for connection %p\n", connection);
742 dbus_connection_disconnect (connection);
746 /* We can end the loop, since the connections are in oldest-first order */
747 next_interval = ((double)auth_timeout) - elapsed;
748 _dbus_verbose ("Connection %p authentication expires in %d milliseconds\n",
749 connection, next_interval);
758 bus_expire_timeout_set_interval (connections->expire_timeout,
763 expire_incomplete_timeout (void *data)
765 BusConnections *connections = data;
767 _dbus_verbose ("Running %s\n", _DBUS_FUNCTION_NAME);
769 /* note that this may remove the timeout */
770 bus_connections_expire_incomplete (connections);
776 bus_connection_get_groups (DBusConnection *connection,
777 unsigned long **groups,
781 BusConnectionData *d;
783 DBusUserDatabase *user_database;
785 d = BUS_CONNECTION_DATA (connection);
787 _dbus_assert (d != NULL);
789 user_database = bus_context_get_user_database (d->connections->context);
794 if (dbus_connection_get_unix_user (connection, &uid))
796 if (!_dbus_user_database_get_groups (user_database,
797 uid, groups, n_groups,
800 _DBUS_ASSERT_ERROR_IS_SET (error);
801 _dbus_verbose ("Did not get any groups for UID %lu\n",
807 _dbus_verbose ("Got %d groups for UID %lu\n",
813 return TRUE; /* successfully got 0 groups */
817 bus_connection_is_in_group (DBusConnection *connection,
821 unsigned long *group_ids;
824 if (!bus_connection_get_groups (connection, &group_ids, &n_group_ids,
829 while (i < n_group_ids)
831 if (group_ids[i] == gid)
833 dbus_free (group_ids);
839 dbus_free (group_ids);
844 bus_connection_get_policy (DBusConnection *connection)
846 BusConnectionData *d;
848 d = BUS_CONNECTION_DATA (connection);
850 _dbus_assert (d != NULL);
851 _dbus_assert (d->policy != NULL);
857 foreach_active (BusConnections *connections,
858 BusConnectionForeachFunction function,
863 link = _dbus_list_get_first_link (&connections->completed);
866 DBusConnection *connection = link->data;
867 DBusList *next = _dbus_list_get_next_link (&connections->completed, link);
869 if (!(* function) (connection, data))
879 foreach_inactive (BusConnections *connections,
880 BusConnectionForeachFunction function,
885 link = _dbus_list_get_first_link (&connections->incomplete);
888 DBusConnection *connection = link->data;
889 DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
891 if (!(* function) (connection, data))
901 * Calls function on each active connection; if the function returns
902 * #FALSE, stops iterating. Active connections are authenticated
903 * and have sent a Hello message.
905 * @param connections the connections object
906 * @param function the function
907 * @param data data to pass to it as a second arg
910 bus_connections_foreach_active (BusConnections *connections,
911 BusConnectionForeachFunction function,
914 foreach_active (connections, function, data);
918 * Calls function on each connection; if the function returns
919 * #FALSE, stops iterating.
921 * @param connections the connections object
922 * @param function the function
923 * @param data data to pass to it as a second arg
926 bus_connections_foreach (BusConnections *connections,
927 BusConnectionForeachFunction function,
930 if (!foreach_active (connections, function, data))
933 foreach_inactive (connections, function, data);
937 bus_connections_get_context (BusConnections *connections)
939 return connections->context;
943 * This is used to avoid covering the same connection twice when
944 * traversing connections. Note that it assumes we will
945 * bus_connection_mark_stamp() each connection at least once per
946 * INT_MAX increments of the global stamp, or wraparound would break
950 bus_connections_increment_stamp (BusConnections *connections)
952 connections->stamp += 1;
955 /* Mark connection with current stamp, return TRUE if it
956 * didn't already have that stamp
959 bus_connection_mark_stamp (DBusConnection *connection)
961 BusConnectionData *d;
963 d = BUS_CONNECTION_DATA (connection);
965 _dbus_assert (d != NULL);
967 if (d->stamp == d->connections->stamp)
971 d->stamp = d->connections->stamp;
977 bus_connection_get_context (DBusConnection *connection)
979 BusConnectionData *d;
981 d = BUS_CONNECTION_DATA (connection);
983 _dbus_assert (d != NULL);
985 return d->connections->context;
989 bus_connection_get_connections (DBusConnection *connection)
991 BusConnectionData *d;
993 d = BUS_CONNECTION_DATA (connection);
995 _dbus_assert (d != NULL);
997 return d->connections;
1001 bus_connection_get_registry (DBusConnection *connection)
1003 BusConnectionData *d;
1005 d = BUS_CONNECTION_DATA (connection);
1007 _dbus_assert (d != NULL);
1009 return bus_context_get_registry (d->connections->context);
1013 bus_connection_get_activation (DBusConnection *connection)
1015 BusConnectionData *d;
1017 d = BUS_CONNECTION_DATA (connection);
1019 _dbus_assert (d != NULL);
1021 return bus_context_get_activation (d->connections->context);
1025 bus_connection_get_matchmaker (DBusConnection *connection)
1027 BusConnectionData *d;
1029 d = BUS_CONNECTION_DATA (connection);
1031 _dbus_assert (d != NULL);
1033 return bus_context_get_matchmaker (d->connections->context);
1037 bus_connection_get_selinux_id (DBusConnection *connection)
1039 BusConnectionData *d;
1041 d = BUS_CONNECTION_DATA (connection);
1043 _dbus_assert (d != NULL);
1045 return d->selinux_id;
1049 * Checks whether the connection is registered with the message bus.
1051 * @param connection the connection
1052 * @returns #TRUE if we're an active message bus participant
1055 bus_connection_is_active (DBusConnection *connection)
1057 BusConnectionData *d;
1059 d = BUS_CONNECTION_DATA (connection);
1061 return d != NULL && d->name != NULL;
1065 bus_connection_preallocate_oom_error (DBusConnection *connection)
1067 DBusMessage *message;
1068 DBusPreallocatedSend *preallocated;
1069 BusConnectionData *d;
1071 d = BUS_CONNECTION_DATA (connection);
1073 _dbus_assert (d != NULL);
1075 if (d->oom_preallocated != NULL)
1078 preallocated = dbus_connection_preallocate_send (connection);
1079 if (preallocated == NULL)
1082 message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1084 if (message == NULL)
1086 dbus_connection_free_preallocated_send (connection, preallocated);
1090 /* d->name may be NULL, but that is OK */
1091 if (!dbus_message_set_error_name (message, DBUS_ERROR_NO_MEMORY) ||
1092 !dbus_message_set_destination (message, d->name) ||
1093 !dbus_message_set_sender (message,
1094 DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
1096 dbus_connection_free_preallocated_send (connection, preallocated);
1097 dbus_message_unref (message);
1101 /* set reply serial to placeholder value just so space is already allocated
1104 if (!dbus_message_set_reply_serial (message, 14))
1106 dbus_connection_free_preallocated_send (connection, preallocated);
1107 dbus_message_unref (message);
1111 d->oom_message = message;
1112 d->oom_preallocated = preallocated;
1118 bus_connection_send_oom_error (DBusConnection *connection,
1119 DBusMessage *in_reply_to)
1121 BusConnectionData *d;
1123 d = BUS_CONNECTION_DATA (connection);
1125 _dbus_assert (d != NULL);
1126 _dbus_assert (d->oom_message != NULL);
1128 /* should always succeed since we set it to a placeholder earlier */
1129 if (!dbus_message_set_reply_serial (d->oom_message,
1130 dbus_message_get_serial (in_reply_to)))
1131 _dbus_assert_not_reached ("Failed to set reply serial for preallocated oom message");
1133 _dbus_assert (dbus_message_get_sender (d->oom_message) != NULL);
1135 dbus_connection_send_preallocated (connection, d->oom_preallocated,
1136 d->oom_message, NULL);
1138 dbus_message_unref (d->oom_message);
1139 d->oom_message = NULL;
1140 d->oom_preallocated = NULL;
1144 bus_connection_add_match_rule_link (DBusConnection *connection,
1147 BusConnectionData *d;
1149 d = BUS_CONNECTION_DATA (connection);
1150 _dbus_assert (d != NULL);
1152 _dbus_list_append_link (&d->match_rules, link);
1154 d->n_match_rules += 1;
1158 bus_connection_add_match_rule (DBusConnection *connection,
1163 link = _dbus_list_alloc_link (rule);
1168 bus_connection_add_match_rule_link (connection, link);
1174 bus_connection_remove_match_rule (DBusConnection *connection,
1177 BusConnectionData *d;
1179 d = BUS_CONNECTION_DATA (connection);
1180 _dbus_assert (d != NULL);
1182 _dbus_list_remove_last (&d->match_rules, rule);
1184 d->n_match_rules -= 1;
1185 _dbus_assert (d->n_match_rules >= 0);
1189 bus_connection_get_n_match_rules (DBusConnection *connection)
1191 BusConnectionData *d;
1193 d = BUS_CONNECTION_DATA (connection);
1194 _dbus_assert (d != NULL);
1196 return d->n_match_rules;
1200 bus_connection_add_owned_service_link (DBusConnection *connection,
1203 BusConnectionData *d;
1205 d = BUS_CONNECTION_DATA (connection);
1206 _dbus_assert (d != NULL);
1208 _dbus_list_append_link (&d->services_owned, link);
1210 d->n_services_owned += 1;
1214 bus_connection_add_owned_service (DBusConnection *connection,
1215 BusService *service)
1219 link = _dbus_list_alloc_link (service);
1224 bus_connection_add_owned_service_link (connection, link);
1230 bus_connection_remove_owned_service (DBusConnection *connection,
1231 BusService *service)
1233 BusConnectionData *d;
1235 d = BUS_CONNECTION_DATA (connection);
1236 _dbus_assert (d != NULL);
1238 _dbus_list_remove_last (&d->services_owned, service);
1240 d->n_services_owned -= 1;
1241 _dbus_assert (d->n_services_owned >= 0);
1245 bus_connection_get_n_services_owned (DBusConnection *connection)
1247 BusConnectionData *d;
1249 d = BUS_CONNECTION_DATA (connection);
1250 _dbus_assert (d != NULL);
1252 return d->n_services_owned;
1256 bus_connection_complete (DBusConnection *connection,
1257 const DBusString *name,
1260 BusConnectionData *d;
1263 d = BUS_CONNECTION_DATA (connection);
1264 _dbus_assert (d != NULL);
1265 _dbus_assert (d->name == NULL);
1266 _dbus_assert (d->policy == NULL);
1268 _dbus_assert (!bus_connection_is_active (connection));
1270 if (!_dbus_string_copy_data (name, &d->name))
1272 BUS_SET_OOM (error);
1276 _dbus_assert (d->name != NULL);
1278 _dbus_verbose ("Name %s assigned to %p\n", d->name, connection);
1280 d->policy = bus_context_create_client_policy (d->connections->context,
1284 /* we may have a NULL policy on OOM or error getting list of
1285 * groups for a user. In the latter case we don't handle it so
1286 * well currently, as it will just keep failing over and over.
1289 if (d->policy == NULL)
1291 _dbus_verbose ("Failed to create security policy for connection %p\n",
1293 _DBUS_ASSERT_ERROR_IS_SET (error);
1294 dbus_free (d->name);
1299 if (dbus_connection_get_unix_user (connection, &uid))
1301 if (!adjust_connections_for_uid (d->connections,
1304 BUS_SET_OOM (error);
1305 dbus_free (d->name);
1311 /* Now the connection is active, move it between lists */
1312 _dbus_list_unlink (&d->connections->incomplete,
1313 d->link_in_connection_list);
1314 d->connections->n_incomplete -= 1;
1315 _dbus_list_append_link (&d->connections->completed,
1316 d->link_in_connection_list);
1317 d->connections->n_completed += 1;
1319 _dbus_assert (d->connections->n_incomplete >= 0);
1320 _dbus_assert (d->connections->n_completed > 0);
1322 /* See if we can remove the timeout */
1323 bus_connections_expire_incomplete (d->connections);
1325 _dbus_assert (bus_connection_is_active (connection));
1331 bus_connection_get_name (DBusConnection *connection)
1333 BusConnectionData *d;
1335 d = BUS_CONNECTION_DATA (connection);
1336 _dbus_assert (d != NULL);
1342 * Check whether completing the passed-in connection would
1343 * exceed limits, and if so set error and return #FALSE
1346 bus_connections_check_limits (BusConnections *connections,
1347 DBusConnection *requesting_completion,
1350 BusConnectionData *d;
1353 d = BUS_CONNECTION_DATA (requesting_completion);
1354 _dbus_assert (d != NULL);
1356 _dbus_assert (d->name == NULL);
1358 if (connections->n_completed >=
1359 bus_context_get_max_completed_connections (connections->context))
1361 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1362 "The maximum number of active connections has been reached");
1366 if (dbus_connection_get_unix_user (requesting_completion, &uid))
1368 if (get_connections_for_uid (connections, uid) >=
1369 bus_context_get_max_connections_per_user (connections->context))
1371 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1372 "The maximum number of active connections for UID %lu has been reached",
1382 bus_pending_reply_free (BusPendingReply *pending)
1384 _dbus_verbose ("Freeing pending reply %p, replier %p receiver %p serial %u\n",
1386 pending->will_send_reply,
1387 pending->will_get_reply,
1388 pending->reply_serial);
1390 dbus_free (pending);
1394 bus_pending_reply_send_no_reply (BusConnections *connections,
1395 BusTransaction *transaction,
1396 BusPendingReply *pending)
1398 DBusMessage *message;
1399 DBusMessageIter iter;
1405 message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1406 if (message == NULL)
1409 dbus_message_set_no_reply (message, TRUE);
1411 if (!dbus_message_set_reply_serial (message,
1412 pending->reply_serial))
1415 if (!dbus_message_set_error_name (message,
1416 DBUS_ERROR_NO_REPLY))
1419 errmsg = "Message did not receive a reply (timeout by message bus)";
1420 dbus_message_append_iter_init (message, &iter);
1421 if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &errmsg))
1424 if (!bus_transaction_send_from_driver (transaction, pending->will_get_reply,
1431 dbus_message_unref (message);
1436 bus_pending_reply_expired (BusExpireList *list,
1440 BusPendingReply *pending = link->data;
1441 BusConnections *connections = data;
1442 BusTransaction *transaction;
1444 /* No reply is forthcoming. So nuke it if we can. If not,
1445 * leave it in the list to try expiring again later when we
1449 _dbus_verbose ("Expiring pending reply %p, replier %p receiver %p serial %u\n",
1451 pending->will_send_reply,
1452 pending->will_get_reply,
1453 pending->reply_serial);
1455 transaction = bus_transaction_new (connections->context);
1456 if (transaction == NULL)
1459 if (!bus_pending_reply_send_no_reply (connections,
1463 bus_transaction_cancel_and_free (transaction);
1467 _dbus_list_remove_link (&connections->pending_replies->items,
1469 bus_pending_reply_free (pending);
1470 bus_transaction_execute_and_free (transaction);
1476 bus_connection_drop_pending_replies (BusConnections *connections,
1477 DBusConnection *connection)
1479 /* The DBusConnection is almost 100% finalized here, so you can't
1480 * do anything with it except check for pointer equality
1484 _dbus_verbose ("Dropping pending replies that involve connection %p\n",
1487 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1488 while (link != NULL)
1491 BusPendingReply *pending;
1493 next = _dbus_list_get_next_link (&connections->pending_replies->items,
1495 pending = link->data;
1497 if (pending->will_get_reply == connection)
1499 /* We don't need to track this pending reply anymore */
1501 _dbus_verbose ("Dropping pending reply %p, replier %p receiver %p serial %u\n",
1503 pending->will_send_reply,
1504 pending->will_get_reply,
1505 pending->reply_serial);
1507 _dbus_list_remove_link (&connections->pending_replies->items,
1509 bus_pending_reply_free (pending);
1511 else if (pending->will_send_reply == connection)
1513 /* The reply isn't going to be sent, so set things
1514 * up so it will be expired right away
1516 _dbus_verbose ("Will expire pending reply %p, replier %p receiver %p serial %u\n",
1518 pending->will_send_reply,
1519 pending->will_get_reply,
1520 pending->reply_serial);
1522 pending->will_send_reply = NULL;
1523 pending->expire_item.added_tv_sec = 0;
1524 pending->expire_item.added_tv_usec = 0;
1526 bus_expire_timeout_set_interval (connections->pending_replies->timeout,
1537 BusPendingReply *pending;
1538 BusConnections *connections;
1539 } CancelPendingReplyData;
1542 cancel_pending_reply (void *data)
1544 CancelPendingReplyData *d = data;
1546 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1548 if (!_dbus_list_remove (&d->connections->pending_replies->items,
1550 _dbus_assert_not_reached ("pending reply did not exist to be cancelled");
1552 bus_pending_reply_free (d->pending); /* since it's been cancelled */
1556 cancel_pending_reply_data_free (void *data)
1558 CancelPendingReplyData *d = data;
1560 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1562 /* d->pending should be either freed or still
1563 * in the list of pending replies (owned by someone
1571 * Record that a reply is allowed; return TRUE on success.
1574 bus_connections_expect_reply (BusConnections *connections,
1575 BusTransaction *transaction,
1576 DBusConnection *will_get_reply,
1577 DBusConnection *will_send_reply,
1578 DBusMessage *reply_to_this,
1581 BusPendingReply *pending;
1582 dbus_uint32_t reply_serial;
1584 CancelPendingReplyData *cprd;
1587 _dbus_assert (will_get_reply != NULL);
1588 _dbus_assert (will_send_reply != NULL);
1589 _dbus_assert (reply_to_this != NULL);
1591 if (dbus_message_get_no_reply (reply_to_this))
1592 return TRUE; /* we won't allow a reply, since client doesn't care for one. */
1594 reply_serial = dbus_message_get_serial (reply_to_this);
1596 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1598 while (link != NULL)
1600 pending = link->data;
1602 if (pending->reply_serial == reply_serial &&
1603 pending->will_get_reply == will_get_reply &&
1604 pending->will_send_reply == will_send_reply)
1606 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1607 "Message has the same reply serial as a currently-outstanding existing method call");
1611 link = _dbus_list_get_next_link (&connections->pending_replies->items,
1617 bus_context_get_max_replies_per_connection (connections->context))
1619 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1620 "The maximum number of pending replies per connection has been reached");
1624 pending = dbus_new0 (BusPendingReply, 1);
1625 if (pending == NULL)
1627 BUS_SET_OOM (error);
1631 #ifdef DBUS_ENABLE_VERBOSE_MODE
1632 /* so we can see a not-yet-added pending reply */
1633 pending->expire_item.added_tv_sec = 1;
1634 pending->expire_item.added_tv_usec = 1;
1637 pending->will_get_reply = will_get_reply;
1638 pending->will_send_reply = will_send_reply;
1639 pending->reply_serial = reply_serial;
1641 cprd = dbus_new0 (CancelPendingReplyData, 1);
1644 BUS_SET_OOM (error);
1645 bus_pending_reply_free (pending);
1649 if (!_dbus_list_prepend (&connections->pending_replies->items,
1652 BUS_SET_OOM (error);
1654 bus_pending_reply_free (pending);
1658 if (!bus_transaction_add_cancel_hook (transaction,
1659 cancel_pending_reply,
1661 cancel_pending_reply_data_free))
1663 BUS_SET_OOM (error);
1664 _dbus_list_remove (&connections->pending_replies->items, pending);
1666 bus_pending_reply_free (pending);
1670 cprd->pending = pending;
1671 cprd->connections = connections;
1673 _dbus_get_current_time (&pending->expire_item.added_tv_sec,
1674 &pending->expire_item.added_tv_usec);
1676 _dbus_verbose ("Added pending reply %p, replier %p receiver %p serial %u\n",
1678 pending->will_send_reply,
1679 pending->will_get_reply,
1680 pending->reply_serial);
1688 BusConnections *connections;
1689 } CheckPendingReplyData;
1692 cancel_check_pending_reply (void *data)
1694 CheckPendingReplyData *d = data;
1696 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1698 _dbus_list_prepend_link (&d->connections->pending_replies->items,
1704 check_pending_reply_data_free (void *data)
1706 CheckPendingReplyData *d = data;
1708 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1710 if (d->link != NULL)
1712 BusPendingReply *pending = d->link->data;
1714 _dbus_assert (_dbus_list_find_last (&d->connections->pending_replies->items,
1717 bus_pending_reply_free (pending);
1718 _dbus_list_free_link (d->link);
1725 * Check whether a reply is allowed, remove BusPendingReply
1726 * if so, return TRUE if so.
1729 bus_connections_check_reply (BusConnections *connections,
1730 BusTransaction *transaction,
1731 DBusConnection *sending_reply,
1732 DBusConnection *receiving_reply,
1736 CheckPendingReplyData *cprd;
1738 dbus_uint32_t reply_serial;
1740 _dbus_assert (sending_reply != NULL);
1741 _dbus_assert (receiving_reply != NULL);
1743 reply_serial = dbus_message_get_reply_serial (reply);
1745 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1746 while (link != NULL)
1748 BusPendingReply *pending = link->data;
1750 if (pending->reply_serial == reply_serial &&
1751 pending->will_get_reply == receiving_reply &&
1752 pending->will_send_reply == sending_reply)
1754 _dbus_verbose ("Found pending reply with serial %u\n", reply_serial);
1758 link = _dbus_list_get_next_link (&connections->pending_replies->items,
1764 _dbus_verbose ("No pending reply expected\n");
1769 cprd = dbus_new0 (CheckPendingReplyData, 1);
1772 BUS_SET_OOM (error);
1776 if (!bus_transaction_add_cancel_hook (transaction,
1777 cancel_check_pending_reply,
1779 check_pending_reply_data_free))
1781 BUS_SET_OOM (error);
1787 cprd->connections = connections;
1789 _dbus_list_unlink (&connections->pending_replies->items,
1792 _dbus_assert (_dbus_list_find_last (&connections->pending_replies->items,
1793 link->data) == NULL);
1801 * Note that this is fairly fragile; in particular, don't try to use
1802 * one transaction across any main loop iterations.
1807 BusTransaction *transaction;
1808 DBusMessage *message;
1809 DBusPreallocatedSend *preallocated;
1814 BusTransactionCancelFunction cancel_function;
1815 DBusFreeFunction free_data_function;
1819 struct BusTransaction
1821 DBusList *connections;
1822 BusContext *context;
1823 DBusList *cancel_hooks;
1827 message_to_send_free (DBusConnection *connection,
1828 MessageToSend *to_send)
1830 if (to_send->message)
1831 dbus_message_unref (to_send->message);
1833 if (to_send->preallocated)
1834 dbus_connection_free_preallocated_send (connection, to_send->preallocated);
1836 dbus_free (to_send);
1840 cancel_hook_cancel (void *element,
1843 CancelHook *ch = element;
1845 _dbus_verbose ("Running transaction cancel hook\n");
1847 if (ch->cancel_function)
1848 (* ch->cancel_function) (ch->data);
1852 cancel_hook_free (void *element,
1855 CancelHook *ch = element;
1857 if (ch->free_data_function)
1858 (* ch->free_data_function) (ch->data);
1864 free_cancel_hooks (BusTransaction *transaction)
1866 _dbus_list_foreach (&transaction->cancel_hooks,
1867 cancel_hook_free, NULL);
1869 _dbus_list_clear (&transaction->cancel_hooks);
1873 bus_transaction_new (BusContext *context)
1875 BusTransaction *transaction;
1877 transaction = dbus_new0 (BusTransaction, 1);
1878 if (transaction == NULL)
1881 transaction->context = context;
1887 bus_transaction_get_context (BusTransaction *transaction)
1889 return transaction->context;
1893 bus_transaction_get_connections (BusTransaction *transaction)
1895 return bus_context_get_connections (transaction->context);
1899 bus_transaction_send_from_driver (BusTransaction *transaction,
1900 DBusConnection *connection,
1901 DBusMessage *message)
1903 /* We have to set the sender to the driver, and have
1904 * to check security policy since it was not done in
1907 _dbus_verbose ("Sending %s %s %s from driver\n",
1908 dbus_message_get_interface (message) ?
1909 dbus_message_get_interface (message) : "(no interface)",
1910 dbus_message_get_member (message) ?
1911 dbus_message_get_member (message) : "(no member)",
1912 dbus_message_get_error_name (message) ?
1913 dbus_message_get_error_name (message) : "(no error name)");
1915 if (!dbus_message_set_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
1918 if (bus_connection_is_active (connection))
1920 if (!dbus_message_set_destination (message,
1921 bus_connection_get_name (connection)))
1925 /* bus driver never wants a reply */
1926 dbus_message_set_no_reply (message, TRUE);
1928 /* If security policy doesn't allow the message, we silently
1929 * eat it; the driver doesn't care about getting a reply.
1931 if (!bus_context_check_security_policy (bus_transaction_get_context (transaction),
1933 NULL, connection, connection, message, NULL))
1936 return bus_transaction_send (transaction, connection, message);
1940 bus_transaction_send (BusTransaction *transaction,
1941 DBusConnection *connection,
1942 DBusMessage *message)
1944 MessageToSend *to_send;
1945 BusConnectionData *d;
1948 _dbus_verbose (" trying to add %s interface=%s member=%s error=%s to transaction%s\n",
1949 dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR ? "error" :
1950 dbus_message_get_reply_serial (message) != 0 ? "reply" :
1952 dbus_message_get_interface (message) ?
1953 dbus_message_get_interface (message) : "(unset)",
1954 dbus_message_get_member (message) ?
1955 dbus_message_get_member (message) : "(unset)",
1956 dbus_message_get_error_name (message) ?
1957 dbus_message_get_error_name (message) : "(unset)",
1958 dbus_connection_get_is_connected (connection) ?
1959 "" : " (disconnected)");
1961 _dbus_assert (dbus_message_get_sender (message) != NULL);
1963 if (!dbus_connection_get_is_connected (connection))
1964 return TRUE; /* silently ignore disconnected connections */
1966 d = BUS_CONNECTION_DATA (connection);
1967 _dbus_assert (d != NULL);
1969 to_send = dbus_new (MessageToSend, 1);
1970 if (to_send == NULL)
1975 to_send->preallocated = dbus_connection_preallocate_send (connection);
1976 if (to_send->preallocated == NULL)
1978 dbus_free (to_send);
1982 dbus_message_ref (message);
1983 to_send->message = message;
1984 to_send->transaction = transaction;
1986 _dbus_verbose ("about to prepend message\n");
1988 if (!_dbus_list_prepend (&d->transaction_messages, to_send))
1990 message_to_send_free (connection, to_send);
1994 _dbus_verbose ("prepended message\n");
1996 /* See if we already had this connection in the list
1997 * for this transaction. If we have a pending message,
1998 * then we should already be in transaction->connections
2000 link = _dbus_list_get_first_link (&d->transaction_messages);
2001 _dbus_assert (link->data == to_send);
2002 link = _dbus_list_get_next_link (&d->transaction_messages, link);
2003 while (link != NULL)
2005 MessageToSend *m = link->data;
2006 DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
2008 if (m->transaction == transaction)
2016 if (!_dbus_list_prepend (&transaction->connections, connection))
2018 _dbus_list_remove (&d->transaction_messages, to_send);
2019 message_to_send_free (connection, to_send);
2028 connection_cancel_transaction (DBusConnection *connection,
2029 BusTransaction *transaction)
2032 BusConnectionData *d;
2034 d = BUS_CONNECTION_DATA (connection);
2035 _dbus_assert (d != NULL);
2037 link = _dbus_list_get_first_link (&d->transaction_messages);
2038 while (link != NULL)
2040 MessageToSend *m = link->data;
2041 DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
2043 if (m->transaction == transaction)
2045 _dbus_list_remove_link (&d->transaction_messages,
2048 message_to_send_free (connection, m);
2056 bus_transaction_cancel_and_free (BusTransaction *transaction)
2058 DBusConnection *connection;
2060 _dbus_verbose ("TRANSACTION: cancelled\n");
2062 while ((connection = _dbus_list_pop_first (&transaction->connections)))
2063 connection_cancel_transaction (connection, transaction);
2065 _dbus_assert (transaction->connections == NULL);
2067 _dbus_list_foreach (&transaction->cancel_hooks,
2068 cancel_hook_cancel, NULL);
2070 free_cancel_hooks (transaction);
2072 dbus_free (transaction);
2076 connection_execute_transaction (DBusConnection *connection,
2077 BusTransaction *transaction)
2080 BusConnectionData *d;
2082 d = BUS_CONNECTION_DATA (connection);
2083 _dbus_assert (d != NULL);
2085 /* Send the queue in order (FIFO) */
2086 link = _dbus_list_get_last_link (&d->transaction_messages);
2087 while (link != NULL)
2089 MessageToSend *m = link->data;
2090 DBusList *prev = _dbus_list_get_prev_link (&d->transaction_messages, link);
2092 if (m->transaction == transaction)
2094 _dbus_list_remove_link (&d->transaction_messages,
2097 _dbus_assert (dbus_message_get_sender (m->message) != NULL);
2099 dbus_connection_send_preallocated (connection,
2104 m->preallocated = NULL; /* so we don't double-free it */
2106 message_to_send_free (connection, m);
2114 bus_transaction_execute_and_free (BusTransaction *transaction)
2116 /* For each connection in transaction->connections
2119 DBusConnection *connection;
2121 _dbus_verbose ("TRANSACTION: executing\n");
2123 while ((connection = _dbus_list_pop_first (&transaction->connections)))
2124 connection_execute_transaction (connection, transaction);
2126 _dbus_assert (transaction->connections == NULL);
2128 free_cancel_hooks (transaction);
2130 dbus_free (transaction);
2134 bus_connection_remove_transactions (DBusConnection *connection)
2136 MessageToSend *to_send;
2137 BusConnectionData *d;
2139 d = BUS_CONNECTION_DATA (connection);
2140 _dbus_assert (d != NULL);
2142 while ((to_send = _dbus_list_get_first (&d->transaction_messages)))
2144 /* only has an effect for the first MessageToSend listing this transaction */
2145 _dbus_list_remove (&to_send->transaction->connections,
2148 _dbus_list_remove (&d->transaction_messages, to_send);
2149 message_to_send_free (connection, to_send);
2154 * Converts the DBusError to a message reply
2157 bus_transaction_send_error_reply (BusTransaction *transaction,
2158 DBusConnection *connection,
2159 const DBusError *error,
2160 DBusMessage *in_reply_to)
2164 _dbus_assert (error != NULL);
2165 _DBUS_ASSERT_ERROR_IS_SET (error);
2167 _dbus_verbose ("Sending error reply %s \"%s\"\n",
2168 error->name, error->message);
2170 reply = dbus_message_new_error (in_reply_to,
2176 if (!bus_transaction_send_from_driver (transaction, connection, reply))
2178 dbus_message_unref (reply);
2182 dbus_message_unref (reply);
2188 bus_transaction_add_cancel_hook (BusTransaction *transaction,
2189 BusTransactionCancelFunction cancel_function,
2191 DBusFreeFunction free_data_function)
2195 ch = dbus_new (CancelHook, 1);
2199 _dbus_verbose (" adding cancel hook function = %p data = %p\n",
2200 cancel_function, data);
2202 ch->cancel_function = cancel_function;
2204 ch->free_data_function = free_data_function;
2206 /* It's important that the hooks get run in reverse order that they
2209 if (!_dbus_list_prepend (&transaction->cancel_hooks, ch))