1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
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,
245 dbus_connection_set_windows_user_function (connection,
248 dbus_connection_set_dispatch_status_function (connection,
251 bus_connection_remove_transactions (connection);
253 if (d->link_in_connection_list != NULL)
259 _dbus_list_remove_link (&d->connections->completed, d->link_in_connection_list);
260 d->link_in_connection_list = NULL;
261 d->connections->n_completed -= 1;
263 if (dbus_connection_get_unix_user (connection, &uid))
265 if (!adjust_connections_for_uid (d->connections,
267 _dbus_assert_not_reached ("adjusting downward should never fail");
272 _dbus_list_remove_link (&d->connections->incomplete, d->link_in_connection_list);
273 d->link_in_connection_list = NULL;
274 d->connections->n_incomplete -= 1;
277 _dbus_assert (d->connections->n_incomplete >= 0);
278 _dbus_assert (d->connections->n_completed >= 0);
281 bus_connection_drop_pending_replies (d->connections, connection);
283 /* frees "d" as side effect */
284 dbus_connection_set_data (connection,
285 connection_data_slot,
288 dbus_connection_unref (connection);
292 connection_watch_callback (DBusWatch *watch,
293 unsigned int condition,
296 /* FIXME this can be done in dbus-mainloop.c
297 * if the code in activation.c for the babysitter
298 * watch handler is fixed.
302 _dbus_verbose ("Calling handle_watch\n");
304 return dbus_watch_handle (watch, condition);
308 add_connection_watch (DBusWatch *watch,
311 DBusConnection *connection = data;
313 return _dbus_loop_add_watch (connection_get_loop (connection),
314 watch, connection_watch_callback, connection,
319 remove_connection_watch (DBusWatch *watch,
322 DBusConnection *connection = data;
324 _dbus_loop_remove_watch (connection_get_loop (connection),
325 watch, connection_watch_callback, connection);
329 connection_timeout_callback (DBusTimeout *timeout,
332 /* DBusConnection *connection = data; */
334 /* can return FALSE on OOM but we just let it fire again later */
335 dbus_timeout_handle (timeout);
339 add_connection_timeout (DBusTimeout *timeout,
342 DBusConnection *connection = data;
344 return _dbus_loop_add_timeout (connection_get_loop (connection),
345 timeout, connection_timeout_callback, connection, NULL);
349 remove_connection_timeout (DBusTimeout *timeout,
352 DBusConnection *connection = data;
354 _dbus_loop_remove_timeout (connection_get_loop (connection),
355 timeout, connection_timeout_callback, connection);
359 dispatch_status_function (DBusConnection *connection,
360 DBusDispatchStatus new_status,
363 DBusLoop *loop = data;
365 if (new_status != DBUS_DISPATCH_COMPLETE)
367 while (!_dbus_loop_queue_dispatch (loop, connection))
368 _dbus_wait_for_memory ();
373 allow_unix_user_function (DBusConnection *connection,
377 BusConnectionData *d;
379 d = BUS_CONNECTION_DATA (connection);
381 _dbus_assert (d != NULL);
383 return bus_context_allow_unix_user (d->connections->context, uid);
387 free_connection_data (void *data)
389 BusConnectionData *d = data;
391 /* services_owned should be NULL since we should be disconnected */
392 _dbus_assert (d->services_owned == NULL);
393 _dbus_assert (d->n_services_owned == 0);
395 _dbus_assert (d->transaction_messages == NULL);
397 if (d->oom_preallocated)
398 dbus_connection_free_preallocated_send (d->connection, d->oom_preallocated);
401 dbus_message_unref (d->oom_message);
404 bus_client_policy_unref (d->policy);
407 bus_selinux_id_unref (d->selinux_id);
415 call_timeout_callback (DBusTimeout *timeout,
418 /* can return FALSE on OOM but we just let it fire again later */
419 dbus_timeout_handle (timeout);
423 bus_connections_new (BusContext *context)
425 BusConnections *connections;
427 if (!dbus_connection_allocate_data_slot (&connection_data_slot))
430 connections = dbus_new0 (BusConnections, 1);
431 if (connections == NULL)
434 connections->completed_by_user = _dbus_hash_table_new (DBUS_HASH_ULONG,
436 if (connections->completed_by_user == NULL)
439 connections->expire_timeout = _dbus_timeout_new (100, /* irrelevant */
440 expire_incomplete_timeout,
442 if (connections->expire_timeout == NULL)
445 _dbus_timeout_set_enabled (connections->expire_timeout, FALSE);
447 connections->pending_replies = bus_expire_list_new (bus_context_get_loop (context),
448 bus_context_get_reply_timeout (context),
449 bus_pending_reply_expired,
451 if (connections->pending_replies == NULL)
454 if (!_dbus_loop_add_timeout (bus_context_get_loop (context),
455 connections->expire_timeout,
456 call_timeout_callback, NULL, NULL))
459 connections->refcount = 1;
460 connections->context = context;
465 bus_expire_list_free (connections->pending_replies);
467 _dbus_timeout_unref (connections->expire_timeout);
469 _dbus_hash_table_unref (connections->completed_by_user);
471 dbus_free (connections);
473 dbus_connection_free_data_slot (&connection_data_slot);
479 bus_connections_ref (BusConnections *connections)
481 _dbus_assert (connections->refcount > 0);
482 connections->refcount += 1;
488 bus_connections_unref (BusConnections *connections)
490 _dbus_assert (connections->refcount > 0);
491 connections->refcount -= 1;
492 if (connections->refcount == 0)
494 /* drop all incomplete */
495 while (connections->incomplete != NULL)
497 DBusConnection *connection;
499 connection = connections->incomplete->data;
501 dbus_connection_ref (connection);
502 dbus_connection_close (connection);
503 bus_connection_disconnected (connection);
504 dbus_connection_unref (connection);
507 _dbus_assert (connections->n_incomplete == 0);
509 /* drop all real connections */
510 while (connections->completed != NULL)
512 DBusConnection *connection;
514 connection = connections->completed->data;
516 dbus_connection_ref (connection);
517 dbus_connection_close (connection);
518 bus_connection_disconnected (connection);
519 dbus_connection_unref (connection);
522 _dbus_assert (connections->n_completed == 0);
524 bus_expire_list_free (connections->pending_replies);
526 _dbus_loop_remove_timeout (bus_context_get_loop (connections->context),
527 connections->expire_timeout,
528 call_timeout_callback, NULL);
530 _dbus_timeout_unref (connections->expire_timeout);
532 _dbus_hash_table_unref (connections->completed_by_user);
534 dbus_free (connections);
536 dbus_connection_free_data_slot (&connection_data_slot);
541 bus_connections_setup_connection (BusConnections *connections,
542 DBusConnection *connection)
544 BusConnectionData *d;
548 d = dbus_new0 (BusConnectionData, 1);
553 d->connections = connections;
554 d->connection = connection;
556 _dbus_get_current_time (&d->connection_tv_sec,
557 &d->connection_tv_usec);
559 _dbus_assert (connection_data_slot >= 0);
561 if (!dbus_connection_set_data (connection,
562 connection_data_slot,
563 d, free_connection_data))
569 dbus_connection_set_route_peer_messages (connection, TRUE);
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 /* For now we don't need to set a Windows user function because
603 * there are no policies in the config file controlling what
604 * Windows users can connect. The default 'same user that owns the
605 * bus can connect' behavior of DBusConnection is fine on Windows.
607 dbus_connection_set_unix_user_function (connection,
608 allow_unix_user_function,
611 dbus_connection_set_dispatch_status_function (connection,
612 dispatch_status_function,
613 bus_context_get_loop (connections->context),
616 d->link_in_connection_list = _dbus_list_alloc_link (connection);
617 if (d->link_in_connection_list == NULL)
620 /* Setup the connection with the dispatcher */
621 if (!bus_dispatch_add_connection (connection))
624 if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
626 if (!_dbus_loop_queue_dispatch (bus_context_get_loop (connections->context), connection))
628 bus_dispatch_remove_connection (connection);
633 _dbus_list_append_link (&connections->incomplete, d->link_in_connection_list);
634 connections->n_incomplete += 1;
636 dbus_connection_ref (connection);
638 /* Note that we might disconnect ourselves here, but it only takes
639 * effect on return to the main loop. We call this to free up
640 * expired connections if possible, and to queue the timeout for our
643 bus_connections_expire_incomplete (connections);
645 /* And we might also disconnect ourselves here, but again it
646 * only takes effect on return to main loop.
648 if (connections->n_incomplete >
649 bus_context_get_max_incomplete_connections (connections->context))
651 _dbus_verbose ("Number of incomplete connections exceeds max, dropping oldest one\n");
653 _dbus_assert (connections->incomplete != NULL);
654 /* Disconnect the oldest unauthenticated connection. FIXME
655 * would it be more secure to drop a *random* connection? This
656 * algorithm seems to mean that if someone can create new
657 * connections quickly enough, they can keep anyone else from
658 * completing authentication. But random may or may not really
659 * help with that, a more elaborate solution might be required.
661 dbus_connection_close (connections->incomplete->data);
670 bus_selinux_id_unref (d->selinux_id);
671 d->selinux_id = NULL;
673 if (!dbus_connection_set_watch_functions (connection,
677 _dbus_assert_not_reached ("setting watch functions to NULL failed");
679 if (!dbus_connection_set_timeout_functions (connection,
683 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
685 dbus_connection_set_unix_user_function (connection,
688 dbus_connection_set_windows_user_function (connection,
691 dbus_connection_set_dispatch_status_function (connection,
694 if (d->link_in_connection_list != NULL)
696 _dbus_assert (d->link_in_connection_list->next == NULL);
697 _dbus_assert (d->link_in_connection_list->prev == NULL);
698 _dbus_list_free_link (d->link_in_connection_list);
699 d->link_in_connection_list = NULL;
702 if (!dbus_connection_set_data (connection,
703 connection_data_slot,
705 _dbus_assert_not_reached ("failed to set connection data to null");
707 /* "d" has now been freed */
714 bus_connections_expire_incomplete (BusConnections *connections)
720 if (connections->incomplete != NULL)
722 long tv_sec, tv_usec;
726 _dbus_get_current_time (&tv_sec, &tv_usec);
727 auth_timeout = bus_context_get_auth_timeout (connections->context);
729 link = _dbus_list_get_first_link (&connections->incomplete);
732 DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
733 DBusConnection *connection;
734 BusConnectionData *d;
737 connection = link->data;
739 d = BUS_CONNECTION_DATA (connection);
741 _dbus_assert (d != NULL);
743 elapsed = ELAPSED_MILLISECONDS_SINCE (d->connection_tv_sec,
744 d->connection_tv_usec,
747 if (elapsed >= (double) auth_timeout)
749 _dbus_verbose ("Timing out authentication for connection %p\n", connection);
750 dbus_connection_close (connection);
754 /* We can end the loop, since the connections are in oldest-first order */
755 next_interval = ((double)auth_timeout) - elapsed;
756 _dbus_verbose ("Connection %p authentication expires in %d milliseconds\n",
757 connection, next_interval);
766 bus_expire_timeout_set_interval (connections->expire_timeout,
771 expire_incomplete_timeout (void *data)
773 BusConnections *connections = data;
775 _dbus_verbose ("Running %s\n", _DBUS_FUNCTION_NAME);
777 /* note that this may remove the timeout */
778 bus_connections_expire_incomplete (connections);
784 bus_connection_get_unix_groups (DBusConnection *connection,
785 unsigned long **groups,
789 BusConnectionData *d;
792 d = BUS_CONNECTION_DATA (connection);
794 _dbus_assert (d != NULL);
799 if (dbus_connection_get_unix_user (connection, &uid))
801 if (!_dbus_unix_groups_from_uid (uid, groups, n_groups))
803 _dbus_verbose ("Did not get any groups for UID %lu\n",
809 _dbus_verbose ("Got %d groups for UID %lu\n",
815 return TRUE; /* successfully got 0 groups */
819 bus_connection_is_in_unix_group (DBusConnection *connection,
823 unsigned long *group_ids;
826 if (!bus_connection_get_unix_groups (connection, &group_ids, &n_group_ids,
831 while (i < n_group_ids)
833 if (group_ids[i] == gid)
835 dbus_free (group_ids);
841 dbus_free (group_ids);
846 bus_connection_get_policy (DBusConnection *connection)
848 BusConnectionData *d;
850 d = BUS_CONNECTION_DATA (connection);
852 _dbus_assert (d != NULL);
853 _dbus_assert (d->policy != NULL);
859 foreach_active (BusConnections *connections,
860 BusConnectionForeachFunction function,
865 link = _dbus_list_get_first_link (&connections->completed);
868 DBusConnection *connection = link->data;
869 DBusList *next = _dbus_list_get_next_link (&connections->completed, link);
871 if (!(* function) (connection, data))
881 foreach_inactive (BusConnections *connections,
882 BusConnectionForeachFunction function,
887 link = _dbus_list_get_first_link (&connections->incomplete);
890 DBusConnection *connection = link->data;
891 DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
893 if (!(* function) (connection, data))
903 * Calls function on each active connection; if the function returns
904 * #FALSE, stops iterating. Active connections are authenticated
905 * and have sent a Hello message.
907 * @param connections the connections object
908 * @param function the function
909 * @param data data to pass to it as a second arg
912 bus_connections_foreach_active (BusConnections *connections,
913 BusConnectionForeachFunction function,
916 foreach_active (connections, function, data);
920 * Calls function on each connection; if the function returns
921 * #FALSE, stops iterating.
923 * @param connections the connections object
924 * @param function the function
925 * @param data data to pass to it as a second arg
928 bus_connections_foreach (BusConnections *connections,
929 BusConnectionForeachFunction function,
932 if (!foreach_active (connections, function, data))
935 foreach_inactive (connections, function, data);
939 bus_connections_get_context (BusConnections *connections)
941 return connections->context;
945 * This is used to avoid covering the same connection twice when
946 * traversing connections. Note that it assumes we will
947 * bus_connection_mark_stamp() each connection at least once per
948 * INT_MAX increments of the global stamp, or wraparound would break
952 bus_connections_increment_stamp (BusConnections *connections)
954 connections->stamp += 1;
957 /* Mark connection with current stamp, return TRUE if it
958 * didn't already have that stamp
961 bus_connection_mark_stamp (DBusConnection *connection)
963 BusConnectionData *d;
965 d = BUS_CONNECTION_DATA (connection);
967 _dbus_assert (d != NULL);
969 if (d->stamp == d->connections->stamp)
973 d->stamp = d->connections->stamp;
979 bus_connection_get_context (DBusConnection *connection)
981 BusConnectionData *d;
983 d = BUS_CONNECTION_DATA (connection);
985 _dbus_assert (d != NULL);
987 return d->connections->context;
991 bus_connection_get_connections (DBusConnection *connection)
993 BusConnectionData *d;
995 d = BUS_CONNECTION_DATA (connection);
997 _dbus_assert (d != NULL);
999 return d->connections;
1003 bus_connection_get_registry (DBusConnection *connection)
1005 BusConnectionData *d;
1007 d = BUS_CONNECTION_DATA (connection);
1009 _dbus_assert (d != NULL);
1011 return bus_context_get_registry (d->connections->context);
1015 bus_connection_get_activation (DBusConnection *connection)
1017 BusConnectionData *d;
1019 d = BUS_CONNECTION_DATA (connection);
1021 _dbus_assert (d != NULL);
1023 return bus_context_get_activation (d->connections->context);
1027 bus_connection_get_matchmaker (DBusConnection *connection)
1029 BusConnectionData *d;
1031 d = BUS_CONNECTION_DATA (connection);
1033 _dbus_assert (d != NULL);
1035 return bus_context_get_matchmaker (d->connections->context);
1039 bus_connection_get_selinux_id (DBusConnection *connection)
1041 BusConnectionData *d;
1043 d = BUS_CONNECTION_DATA (connection);
1045 _dbus_assert (d != NULL);
1047 return d->selinux_id;
1051 * Checks whether the connection is registered with the message bus.
1053 * @param connection the connection
1054 * @returns #TRUE if we're an active message bus participant
1057 bus_connection_is_active (DBusConnection *connection)
1059 BusConnectionData *d;
1061 d = BUS_CONNECTION_DATA (connection);
1063 return d != NULL && d->name != NULL;
1067 bus_connection_preallocate_oom_error (DBusConnection *connection)
1069 DBusMessage *message;
1070 DBusPreallocatedSend *preallocated;
1071 BusConnectionData *d;
1073 d = BUS_CONNECTION_DATA (connection);
1075 _dbus_assert (d != NULL);
1077 if (d->oom_preallocated != NULL)
1080 preallocated = dbus_connection_preallocate_send (connection);
1081 if (preallocated == NULL)
1084 message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1086 if (message == NULL)
1088 dbus_connection_free_preallocated_send (connection, preallocated);
1092 /* d->name may be NULL, but that is OK */
1093 if (!dbus_message_set_error_name (message, DBUS_ERROR_NO_MEMORY) ||
1094 !dbus_message_set_destination (message, d->name) ||
1095 !dbus_message_set_sender (message,
1098 dbus_connection_free_preallocated_send (connection, preallocated);
1099 dbus_message_unref (message);
1103 /* set reply serial to placeholder value just so space is already allocated
1106 if (!dbus_message_set_reply_serial (message, 14))
1108 dbus_connection_free_preallocated_send (connection, preallocated);
1109 dbus_message_unref (message);
1113 d->oom_message = message;
1114 d->oom_preallocated = preallocated;
1120 bus_connection_send_oom_error (DBusConnection *connection,
1121 DBusMessage *in_reply_to)
1123 BusConnectionData *d;
1125 d = BUS_CONNECTION_DATA (connection);
1127 _dbus_assert (d != NULL);
1128 _dbus_assert (d->oom_message != NULL);
1130 /* should always succeed since we set it to a placeholder earlier */
1131 if (!dbus_message_set_reply_serial (d->oom_message,
1132 dbus_message_get_serial (in_reply_to)))
1133 _dbus_assert_not_reached ("Failed to set reply serial for preallocated oom message");
1135 _dbus_assert (dbus_message_get_sender (d->oom_message) != NULL);
1137 dbus_connection_send_preallocated (connection, d->oom_preallocated,
1138 d->oom_message, NULL);
1140 dbus_message_unref (d->oom_message);
1141 d->oom_message = NULL;
1142 d->oom_preallocated = NULL;
1146 bus_connection_add_match_rule_link (DBusConnection *connection,
1149 BusConnectionData *d;
1151 d = BUS_CONNECTION_DATA (connection);
1152 _dbus_assert (d != NULL);
1154 _dbus_list_append_link (&d->match_rules, link);
1156 d->n_match_rules += 1;
1160 bus_connection_add_match_rule (DBusConnection *connection,
1165 link = _dbus_list_alloc_link (rule);
1170 bus_connection_add_match_rule_link (connection, link);
1176 bus_connection_remove_match_rule (DBusConnection *connection,
1179 BusConnectionData *d;
1181 d = BUS_CONNECTION_DATA (connection);
1182 _dbus_assert (d != NULL);
1184 _dbus_list_remove_last (&d->match_rules, rule);
1186 d->n_match_rules -= 1;
1187 _dbus_assert (d->n_match_rules >= 0);
1191 bus_connection_get_n_match_rules (DBusConnection *connection)
1193 BusConnectionData *d;
1195 d = BUS_CONNECTION_DATA (connection);
1196 _dbus_assert (d != NULL);
1198 return d->n_match_rules;
1202 bus_connection_add_owned_service_link (DBusConnection *connection,
1205 BusConnectionData *d;
1207 d = BUS_CONNECTION_DATA (connection);
1208 _dbus_assert (d != NULL);
1210 _dbus_list_append_link (&d->services_owned, link);
1212 d->n_services_owned += 1;
1216 bus_connection_add_owned_service (DBusConnection *connection,
1217 BusService *service)
1221 link = _dbus_list_alloc_link (service);
1226 bus_connection_add_owned_service_link (connection, link);
1232 bus_connection_remove_owned_service (DBusConnection *connection,
1233 BusService *service)
1235 BusConnectionData *d;
1237 d = BUS_CONNECTION_DATA (connection);
1238 _dbus_assert (d != NULL);
1240 _dbus_list_remove_last (&d->services_owned, service);
1242 d->n_services_owned -= 1;
1243 _dbus_assert (d->n_services_owned >= 0);
1247 bus_connection_get_n_services_owned (DBusConnection *connection)
1249 BusConnectionData *d;
1251 d = BUS_CONNECTION_DATA (connection);
1252 _dbus_assert (d != NULL);
1254 return d->n_services_owned;
1258 bus_connection_complete (DBusConnection *connection,
1259 const DBusString *name,
1262 BusConnectionData *d;
1265 d = BUS_CONNECTION_DATA (connection);
1266 _dbus_assert (d != NULL);
1267 _dbus_assert (d->name == NULL);
1268 _dbus_assert (d->policy == NULL);
1270 _dbus_assert (!bus_connection_is_active (connection));
1272 if (!_dbus_string_copy_data (name, &d->name))
1274 BUS_SET_OOM (error);
1278 _dbus_assert (d->name != NULL);
1280 _dbus_verbose ("Name %s assigned to %p\n", d->name, connection);
1282 d->policy = bus_context_create_client_policy (d->connections->context,
1286 /* we may have a NULL policy on OOM or error getting list of
1287 * groups for a user. In the latter case we don't handle it so
1288 * well currently, as it will just keep failing over and over.
1291 if (d->policy == NULL)
1293 _dbus_verbose ("Failed to create security policy for connection %p\n",
1295 _DBUS_ASSERT_ERROR_IS_SET (error);
1296 dbus_free (d->name);
1301 if (dbus_connection_get_unix_user (connection, &uid))
1303 if (!adjust_connections_for_uid (d->connections,
1306 BUS_SET_OOM (error);
1307 dbus_free (d->name);
1309 bus_client_policy_unref (d->policy);
1315 /* Now the connection is active, move it between lists */
1316 _dbus_list_unlink (&d->connections->incomplete,
1317 d->link_in_connection_list);
1318 d->connections->n_incomplete -= 1;
1319 _dbus_list_append_link (&d->connections->completed,
1320 d->link_in_connection_list);
1321 d->connections->n_completed += 1;
1323 _dbus_assert (d->connections->n_incomplete >= 0);
1324 _dbus_assert (d->connections->n_completed > 0);
1326 /* See if we can remove the timeout */
1327 bus_connections_expire_incomplete (d->connections);
1329 _dbus_assert (bus_connection_is_active (connection));
1335 bus_connection_get_name (DBusConnection *connection)
1337 BusConnectionData *d;
1339 d = BUS_CONNECTION_DATA (connection);
1340 _dbus_assert (d != NULL);
1346 * Check whether completing the passed-in connection would
1347 * exceed limits, and if so set error and return #FALSE
1350 bus_connections_check_limits (BusConnections *connections,
1351 DBusConnection *requesting_completion,
1354 BusConnectionData *d;
1357 d = BUS_CONNECTION_DATA (requesting_completion);
1358 _dbus_assert (d != NULL);
1360 _dbus_assert (d->name == NULL);
1362 if (connections->n_completed >=
1363 bus_context_get_max_completed_connections (connections->context))
1365 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1366 "The maximum number of active connections has been reached");
1370 if (dbus_connection_get_unix_user (requesting_completion, &uid))
1372 if (get_connections_for_uid (connections, uid) >=
1373 bus_context_get_max_connections_per_user (connections->context))
1375 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1376 "The maximum number of active connections for UID %lu has been reached",
1386 bus_pending_reply_free (BusPendingReply *pending)
1388 _dbus_verbose ("Freeing pending reply %p, replier %p receiver %p serial %u\n",
1390 pending->will_send_reply,
1391 pending->will_get_reply,
1392 pending->reply_serial);
1394 dbus_free (pending);
1398 bus_pending_reply_send_no_reply (BusConnections *connections,
1399 BusTransaction *transaction,
1400 BusPendingReply *pending)
1402 DBusMessage *message;
1403 DBusMessageIter iter;
1409 message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1410 if (message == NULL)
1413 dbus_message_set_no_reply (message, TRUE);
1415 if (!dbus_message_set_reply_serial (message,
1416 pending->reply_serial))
1419 if (!dbus_message_set_error_name (message,
1420 DBUS_ERROR_NO_REPLY))
1423 errmsg = "Message did not receive a reply (timeout by message bus)";
1424 dbus_message_iter_init_append (message, &iter);
1425 if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &errmsg))
1428 if (!bus_transaction_send_from_driver (transaction, pending->will_get_reply,
1435 dbus_message_unref (message);
1440 bus_pending_reply_expired (BusExpireList *list,
1444 BusPendingReply *pending = link->data;
1445 BusConnections *connections = data;
1446 BusTransaction *transaction;
1448 /* No reply is forthcoming. So nuke it if we can. If not,
1449 * leave it in the list to try expiring again later when we
1453 _dbus_verbose ("Expiring pending reply %p, replier %p receiver %p serial %u\n",
1455 pending->will_send_reply,
1456 pending->will_get_reply,
1457 pending->reply_serial);
1459 transaction = bus_transaction_new (connections->context);
1460 if (transaction == NULL)
1463 if (!bus_pending_reply_send_no_reply (connections,
1467 bus_transaction_cancel_and_free (transaction);
1471 _dbus_list_remove_link (&connections->pending_replies->items,
1473 bus_pending_reply_free (pending);
1474 bus_transaction_execute_and_free (transaction);
1480 bus_connection_drop_pending_replies (BusConnections *connections,
1481 DBusConnection *connection)
1483 /* The DBusConnection is almost 100% finalized here, so you can't
1484 * do anything with it except check for pointer equality
1488 _dbus_verbose ("Dropping pending replies that involve connection %p\n",
1491 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1492 while (link != NULL)
1495 BusPendingReply *pending;
1497 next = _dbus_list_get_next_link (&connections->pending_replies->items,
1499 pending = link->data;
1501 if (pending->will_get_reply == connection)
1503 /* We don't need to track this pending reply anymore */
1505 _dbus_verbose ("Dropping pending reply %p, replier %p receiver %p serial %u\n",
1507 pending->will_send_reply,
1508 pending->will_get_reply,
1509 pending->reply_serial);
1511 _dbus_list_remove_link (&connections->pending_replies->items,
1513 bus_pending_reply_free (pending);
1515 else if (pending->will_send_reply == connection)
1517 /* The reply isn't going to be sent, so set things
1518 * up so it will be expired right away
1520 _dbus_verbose ("Will expire pending reply %p, replier %p receiver %p serial %u\n",
1522 pending->will_send_reply,
1523 pending->will_get_reply,
1524 pending->reply_serial);
1526 pending->will_send_reply = NULL;
1527 pending->expire_item.added_tv_sec = 0;
1528 pending->expire_item.added_tv_usec = 0;
1530 bus_expire_timeout_set_interval (connections->pending_replies->timeout,
1541 BusPendingReply *pending;
1542 BusConnections *connections;
1543 } CancelPendingReplyData;
1546 cancel_pending_reply (void *data)
1548 CancelPendingReplyData *d = data;
1550 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1552 if (!_dbus_list_remove (&d->connections->pending_replies->items,
1554 _dbus_assert_not_reached ("pending reply did not exist to be cancelled");
1556 bus_pending_reply_free (d->pending); /* since it's been cancelled */
1560 cancel_pending_reply_data_free (void *data)
1562 CancelPendingReplyData *d = data;
1564 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1566 /* d->pending should be either freed or still
1567 * in the list of pending replies (owned by someone
1575 * Record that a reply is allowed; return TRUE on success.
1578 bus_connections_expect_reply (BusConnections *connections,
1579 BusTransaction *transaction,
1580 DBusConnection *will_get_reply,
1581 DBusConnection *will_send_reply,
1582 DBusMessage *reply_to_this,
1585 BusPendingReply *pending;
1586 dbus_uint32_t reply_serial;
1588 CancelPendingReplyData *cprd;
1591 _dbus_assert (will_get_reply != NULL);
1592 _dbus_assert (will_send_reply != NULL);
1593 _dbus_assert (reply_to_this != NULL);
1595 if (dbus_message_get_no_reply (reply_to_this))
1596 return TRUE; /* we won't allow a reply, since client doesn't care for one. */
1598 reply_serial = dbus_message_get_serial (reply_to_this);
1600 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1602 while (link != NULL)
1604 pending = link->data;
1606 if (pending->reply_serial == reply_serial &&
1607 pending->will_get_reply == will_get_reply &&
1608 pending->will_send_reply == will_send_reply)
1610 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
1611 "Message has the same reply serial as a currently-outstanding existing method call");
1615 link = _dbus_list_get_next_link (&connections->pending_replies->items,
1617 if (pending->will_get_reply == will_get_reply)
1622 bus_context_get_max_replies_per_connection (connections->context))
1624 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1625 "The maximum number of pending replies per connection has been reached");
1629 pending = dbus_new0 (BusPendingReply, 1);
1630 if (pending == NULL)
1632 BUS_SET_OOM (error);
1636 #ifdef DBUS_ENABLE_VERBOSE_MODE
1637 /* so we can see a not-yet-added pending reply */
1638 pending->expire_item.added_tv_sec = 1;
1639 pending->expire_item.added_tv_usec = 1;
1642 pending->will_get_reply = will_get_reply;
1643 pending->will_send_reply = will_send_reply;
1644 pending->reply_serial = reply_serial;
1646 cprd = dbus_new0 (CancelPendingReplyData, 1);
1649 BUS_SET_OOM (error);
1650 bus_pending_reply_free (pending);
1654 if (!_dbus_list_prepend (&connections->pending_replies->items,
1657 BUS_SET_OOM (error);
1659 bus_pending_reply_free (pending);
1663 if (!bus_transaction_add_cancel_hook (transaction,
1664 cancel_pending_reply,
1666 cancel_pending_reply_data_free))
1668 BUS_SET_OOM (error);
1669 _dbus_list_remove (&connections->pending_replies->items, pending);
1671 bus_pending_reply_free (pending);
1675 cprd->pending = pending;
1676 cprd->connections = connections;
1678 _dbus_get_current_time (&pending->expire_item.added_tv_sec,
1679 &pending->expire_item.added_tv_usec);
1681 _dbus_verbose ("Added pending reply %p, replier %p receiver %p serial %u\n",
1683 pending->will_send_reply,
1684 pending->will_get_reply,
1685 pending->reply_serial);
1693 BusConnections *connections;
1694 } CheckPendingReplyData;
1697 cancel_check_pending_reply (void *data)
1699 CheckPendingReplyData *d = data;
1701 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1703 _dbus_list_prepend_link (&d->connections->pending_replies->items,
1709 check_pending_reply_data_free (void *data)
1711 CheckPendingReplyData *d = data;
1713 _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
1715 if (d->link != NULL)
1717 BusPendingReply *pending = d->link->data;
1719 _dbus_assert (_dbus_list_find_last (&d->connections->pending_replies->items,
1722 bus_pending_reply_free (pending);
1723 _dbus_list_free_link (d->link);
1730 * Check whether a reply is allowed, remove BusPendingReply
1731 * if so, return TRUE if so.
1734 bus_connections_check_reply (BusConnections *connections,
1735 BusTransaction *transaction,
1736 DBusConnection *sending_reply,
1737 DBusConnection *receiving_reply,
1741 CheckPendingReplyData *cprd;
1743 dbus_uint32_t reply_serial;
1745 _dbus_assert (sending_reply != NULL);
1746 _dbus_assert (receiving_reply != NULL);
1748 reply_serial = dbus_message_get_reply_serial (reply);
1750 link = _dbus_list_get_first_link (&connections->pending_replies->items);
1751 while (link != NULL)
1753 BusPendingReply *pending = link->data;
1755 if (pending->reply_serial == reply_serial &&
1756 pending->will_get_reply == receiving_reply &&
1757 pending->will_send_reply == sending_reply)
1759 _dbus_verbose ("Found pending reply with serial %u\n", reply_serial);
1763 link = _dbus_list_get_next_link (&connections->pending_replies->items,
1769 _dbus_verbose ("No pending reply expected\n");
1774 cprd = dbus_new0 (CheckPendingReplyData, 1);
1777 BUS_SET_OOM (error);
1781 if (!bus_transaction_add_cancel_hook (transaction,
1782 cancel_check_pending_reply,
1784 check_pending_reply_data_free))
1786 BUS_SET_OOM (error);
1792 cprd->connections = connections;
1794 _dbus_list_unlink (&connections->pending_replies->items,
1797 _dbus_assert (_dbus_list_find_last (&connections->pending_replies->items,
1798 link->data) == NULL);
1806 * Note that this is fairly fragile; in particular, don't try to use
1807 * one transaction across any main loop iterations.
1812 BusTransaction *transaction;
1813 DBusMessage *message;
1814 DBusPreallocatedSend *preallocated;
1819 BusTransactionCancelFunction cancel_function;
1820 DBusFreeFunction free_data_function;
1824 struct BusTransaction
1826 DBusList *connections;
1827 BusContext *context;
1828 DBusList *cancel_hooks;
1832 message_to_send_free (DBusConnection *connection,
1833 MessageToSend *to_send)
1835 if (to_send->message)
1836 dbus_message_unref (to_send->message);
1838 if (to_send->preallocated)
1839 dbus_connection_free_preallocated_send (connection, to_send->preallocated);
1841 dbus_free (to_send);
1845 cancel_hook_cancel (void *element,
1848 CancelHook *ch = element;
1850 _dbus_verbose ("Running transaction cancel hook\n");
1852 if (ch->cancel_function)
1853 (* ch->cancel_function) (ch->data);
1857 cancel_hook_free (void *element,
1860 CancelHook *ch = element;
1862 if (ch->free_data_function)
1863 (* ch->free_data_function) (ch->data);
1869 free_cancel_hooks (BusTransaction *transaction)
1871 _dbus_list_foreach (&transaction->cancel_hooks,
1872 cancel_hook_free, NULL);
1874 _dbus_list_clear (&transaction->cancel_hooks);
1878 bus_transaction_new (BusContext *context)
1880 BusTransaction *transaction;
1882 transaction = dbus_new0 (BusTransaction, 1);
1883 if (transaction == NULL)
1886 transaction->context = context;
1892 bus_transaction_get_context (BusTransaction *transaction)
1894 return transaction->context;
1898 bus_transaction_get_connections (BusTransaction *transaction)
1900 return bus_context_get_connections (transaction->context);
1904 bus_transaction_send_from_driver (BusTransaction *transaction,
1905 DBusConnection *connection,
1906 DBusMessage *message)
1908 /* We have to set the sender to the driver, and have
1909 * to check security policy since it was not done in
1912 _dbus_verbose ("Sending %s %s %s from driver\n",
1913 dbus_message_get_interface (message) ?
1914 dbus_message_get_interface (message) : "(no interface)",
1915 dbus_message_get_member (message) ?
1916 dbus_message_get_member (message) : "(no member)",
1917 dbus_message_get_error_name (message) ?
1918 dbus_message_get_error_name (message) : "(no error name)");
1920 if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
1923 if (bus_connection_is_active (connection))
1925 if (!dbus_message_set_destination (message,
1926 bus_connection_get_name (connection)))
1930 /* bus driver never wants a reply */
1931 dbus_message_set_no_reply (message, TRUE);
1933 /* If security policy doesn't allow the message, we silently
1934 * eat it; the driver doesn't care about getting a reply.
1936 if (!bus_context_check_security_policy (bus_transaction_get_context (transaction),
1938 NULL, connection, connection, message, NULL))
1941 return bus_transaction_send (transaction, connection, message);
1945 bus_transaction_send (BusTransaction *transaction,
1946 DBusConnection *connection,
1947 DBusMessage *message)
1949 MessageToSend *to_send;
1950 BusConnectionData *d;
1953 _dbus_verbose (" trying to add %s interface=%s member=%s error=%s to transaction%s\n",
1954 dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR ? "error" :
1955 dbus_message_get_reply_serial (message) != 0 ? "reply" :
1957 dbus_message_get_interface (message) ?
1958 dbus_message_get_interface (message) : "(unset)",
1959 dbus_message_get_member (message) ?
1960 dbus_message_get_member (message) : "(unset)",
1961 dbus_message_get_error_name (message) ?
1962 dbus_message_get_error_name (message) : "(unset)",
1963 dbus_connection_get_is_connected (connection) ?
1964 "" : " (disconnected)");
1966 _dbus_assert (dbus_message_get_sender (message) != NULL);
1968 if (!dbus_connection_get_is_connected (connection))
1969 return TRUE; /* silently ignore disconnected connections */
1971 d = BUS_CONNECTION_DATA (connection);
1972 _dbus_assert (d != NULL);
1974 to_send = dbus_new (MessageToSend, 1);
1975 if (to_send == NULL)
1980 to_send->preallocated = dbus_connection_preallocate_send (connection);
1981 if (to_send->preallocated == NULL)
1983 dbus_free (to_send);
1987 dbus_message_ref (message);
1988 to_send->message = message;
1989 to_send->transaction = transaction;
1991 _dbus_verbose ("about to prepend message\n");
1993 if (!_dbus_list_prepend (&d->transaction_messages, to_send))
1995 message_to_send_free (connection, to_send);
1999 _dbus_verbose ("prepended message\n");
2001 /* See if we already had this connection in the list
2002 * for this transaction. If we have a pending message,
2003 * then we should already be in transaction->connections
2005 link = _dbus_list_get_first_link (&d->transaction_messages);
2006 _dbus_assert (link->data == to_send);
2007 link = _dbus_list_get_next_link (&d->transaction_messages, link);
2008 while (link != NULL)
2010 MessageToSend *m = link->data;
2011 DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
2013 if (m->transaction == transaction)
2021 if (!_dbus_list_prepend (&transaction->connections, connection))
2023 _dbus_list_remove (&d->transaction_messages, to_send);
2024 message_to_send_free (connection, to_send);
2033 connection_cancel_transaction (DBusConnection *connection,
2034 BusTransaction *transaction)
2037 BusConnectionData *d;
2039 d = BUS_CONNECTION_DATA (connection);
2040 _dbus_assert (d != NULL);
2042 link = _dbus_list_get_first_link (&d->transaction_messages);
2043 while (link != NULL)
2045 MessageToSend *m = link->data;
2046 DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
2048 if (m->transaction == transaction)
2050 _dbus_list_remove_link (&d->transaction_messages,
2053 message_to_send_free (connection, m);
2061 bus_transaction_cancel_and_free (BusTransaction *transaction)
2063 DBusConnection *connection;
2065 _dbus_verbose ("TRANSACTION: cancelled\n");
2067 while ((connection = _dbus_list_pop_first (&transaction->connections)))
2068 connection_cancel_transaction (connection, transaction);
2070 _dbus_assert (transaction->connections == NULL);
2072 _dbus_list_foreach (&transaction->cancel_hooks,
2073 cancel_hook_cancel, NULL);
2075 free_cancel_hooks (transaction);
2077 dbus_free (transaction);
2081 connection_execute_transaction (DBusConnection *connection,
2082 BusTransaction *transaction)
2085 BusConnectionData *d;
2087 d = BUS_CONNECTION_DATA (connection);
2088 _dbus_assert (d != NULL);
2090 /* Send the queue in order (FIFO) */
2091 link = _dbus_list_get_last_link (&d->transaction_messages);
2092 while (link != NULL)
2094 MessageToSend *m = link->data;
2095 DBusList *prev = _dbus_list_get_prev_link (&d->transaction_messages, link);
2097 if (m->transaction == transaction)
2099 _dbus_list_remove_link (&d->transaction_messages,
2102 _dbus_assert (dbus_message_get_sender (m->message) != NULL);
2104 dbus_connection_send_preallocated (connection,
2109 m->preallocated = NULL; /* so we don't double-free it */
2111 message_to_send_free (connection, m);
2119 bus_transaction_execute_and_free (BusTransaction *transaction)
2121 /* For each connection in transaction->connections
2124 DBusConnection *connection;
2126 _dbus_verbose ("TRANSACTION: executing\n");
2128 while ((connection = _dbus_list_pop_first (&transaction->connections)))
2129 connection_execute_transaction (connection, transaction);
2131 _dbus_assert (transaction->connections == NULL);
2133 free_cancel_hooks (transaction);
2135 dbus_free (transaction);
2139 bus_connection_remove_transactions (DBusConnection *connection)
2141 MessageToSend *to_send;
2142 BusConnectionData *d;
2144 d = BUS_CONNECTION_DATA (connection);
2145 _dbus_assert (d != NULL);
2147 while ((to_send = _dbus_list_get_first (&d->transaction_messages)))
2149 /* only has an effect for the first MessageToSend listing this transaction */
2150 _dbus_list_remove (&to_send->transaction->connections,
2153 _dbus_list_remove (&d->transaction_messages, to_send);
2154 message_to_send_free (connection, to_send);
2159 * Converts the DBusError to a message reply
2162 bus_transaction_send_error_reply (BusTransaction *transaction,
2163 DBusConnection *connection,
2164 const DBusError *error,
2165 DBusMessage *in_reply_to)
2169 _dbus_assert (error != NULL);
2170 _DBUS_ASSERT_ERROR_IS_SET (error);
2172 _dbus_verbose ("Sending error reply %s \"%s\"\n",
2173 error->name, error->message);
2175 reply = dbus_message_new_error (in_reply_to,
2181 if (!bus_transaction_send_from_driver (transaction, connection, reply))
2183 dbus_message_unref (reply);
2187 dbus_message_unref (reply);
2193 bus_transaction_add_cancel_hook (BusTransaction *transaction,
2194 BusTransactionCancelFunction cancel_function,
2196 DBusFreeFunction free_data_function)
2200 ch = dbus_new (CancelHook, 1);
2204 _dbus_verbose (" adding cancel hook function = %p data = %p\n",
2205 cancel_function, data);
2207 ch->cancel_function = cancel_function;
2209 ch->free_data_function = free_data_function;
2211 /* It's important that the hooks get run in reverse order that they
2214 if (!_dbus_list_prepend (&transaction->cancel_hooks, ch))