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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "connection.h"
31 #include "expirelist.h"
35 #include <dbus/dbus-list.h>
36 #include <dbus/dbus-hash.h>
37 #include <dbus/dbus-timeout.h>
38 #include <dbus/dbus-connection-internal.h>
39 #include <dbus/dbus-internals.h>
40 #include <dbus/dbus-message-internal.h>
41 #ifdef DBUS_ENABLE_CYNARA
43 #include <cynara-session.h>
47 /* Trim executed commands to this length; we want to keep logs readable */
48 #define MAX_LOG_COMMAND_LEN 50
50 static void bus_connection_remove_transactions (DBusConnection *connection);
54 BusExpireItem expire_item;
56 DBusConnection *will_get_reply;
57 DBusConnection *will_send_reply;
59 dbus_uint32_t reply_serial;
66 DBusList *completed; /**< List of all completed connections */
67 int n_completed; /**< Length of completed list */
68 DBusList *incomplete; /**< List of all not-yet-active connections */
69 int n_incomplete; /**< Length of incomplete list */
71 DBusHashTable *completed_by_user; /**< Number of completed connections for each UID */
72 DBusTimeout *expire_timeout; /**< Timeout for expiring incomplete connections. */
73 int stamp; /**< Incrementing number */
74 BusExpireList *pending_replies; /**< List of pending replies */
76 /** List of all monitoring connections, a subset of completed.
77 * Each member is a #DBusConnection. */
79 BusMatchmaker *monitor_matchmaker;
81 #ifdef DBUS_ENABLE_STATS
82 int total_match_rules;
84 int peak_match_rules_per_conn;
88 int peak_bus_names_per_conn;
92 static dbus_int32_t connection_data_slot = -1;
96 BusConnections *connections;
97 DBusList *link_in_connection_list;
98 DBusConnection *connection;
99 DBusList *services_owned;
100 int n_services_owned;
101 DBusList *match_rules;
104 DBusList *transaction_messages; /**< Stuff we need to send as part of a transaction */
105 DBusMessage *oom_message;
106 DBusPreallocatedSend *oom_preallocated;
107 BusClientPolicy *policy;
108 DBusList *deferred_messages; /**< Queue of messages deferred due to pending policy check */
110 char *cached_loginfo_string;
111 BusSELinuxID *selinux_id;
112 BusAppArmorConfinement *apparmor_confinement;
114 long connection_tv_sec; /**< Time when we connected (seconds component) */
115 long connection_tv_usec; /**< Time when we connected (microsec component) */
116 int stamp; /**< connections->stamp last time we were traversed */
118 #ifdef DBUS_ENABLE_STATS
119 int peak_match_rules;
121 int peak_pending_replies;
123 int n_pending_unix_fds;
124 DBusTimeout *pending_unix_fds_timeout;
126 /** non-NULL if and only if this is a monitor */
127 DBusList *link_in_monitors;
128 #ifdef DBUS_ENABLE_CYNARA
129 char *cynara_session_id;
133 static dbus_bool_t bus_pending_reply_expired (BusExpireList *list,
137 static void bus_connection_drop_pending_replies (BusConnections *connections,
138 DBusConnection *connection);
140 static dbus_bool_t expire_incomplete_timeout (void *data);
142 #define BUS_CONNECTION_DATA(connection) (dbus_connection_get_data ((connection), connection_data_slot))
145 bus_connection_get_loop (DBusConnection *connection)
147 BusConnectionData *d;
149 d = BUS_CONNECTION_DATA (connection);
150 _dbus_assert(d != NULL);
152 return bus_context_get_loop (d->connections->context);
157 get_connections_for_uid (BusConnections *connections,
163 /* val is NULL is 0 when it isn't in the hash yet */
165 val = _dbus_hash_table_lookup_uintptr (connections->completed_by_user,
168 current_count = _DBUS_POINTER_TO_INT (val);
170 return current_count;
174 adjust_connections_for_uid (BusConnections *connections,
180 current_count = get_connections_for_uid (connections, uid);
182 _dbus_verbose ("Adjusting connection count for UID " DBUS_UID_FORMAT
183 ": was %d adjustment %d making %d\n",
184 uid, current_count, adjustment, current_count + adjustment);
186 _dbus_assert (current_count >= 0);
188 current_count += adjustment;
190 _dbus_assert (current_count >= 0);
192 if (current_count == 0)
194 _dbus_hash_table_remove_uintptr (connections->completed_by_user, uid);
201 retval = _dbus_hash_table_insert_uintptr (connections->completed_by_user,
202 uid, _DBUS_INT_TO_POINTER (current_count));
204 /* only positive adjustment can fail as otherwise
205 * a hash entry should already exist
207 _dbus_assert (adjustment > 0 ||
208 (adjustment <= 0 && retval));
215 bus_connection_disconnected (DBusConnection *connection)
217 BusConnectionData *d;
219 BusMatchmaker *matchmaker;
221 d = BUS_CONNECTION_DATA (connection);
222 _dbus_assert (d != NULL);
224 _dbus_verbose ("%s disconnected, dropping all service ownership and releasing\n",
225 d->name ? d->name : "(inactive)");
227 /* Delete our match rules */
228 if (d->n_match_rules > 0)
230 matchmaker = bus_context_get_matchmaker (d->connections->context);
231 bus_matchmaker_disconnected (matchmaker, connection);
234 /* Drop any service ownership. Unfortunately, this requires
235 * memory allocation and there doesn't seem to be a good way to
236 * handle it other than sleeping; we can't "fail" the operation of
237 * disconnecting a client, and preallocating a broadcast "service is
238 * now gone" message for every client-service pair seems kind of
241 while ((service = _dbus_list_get_last (&d->services_owned)))
243 BusTransaction *transaction;
248 dbus_error_init (&error);
250 while ((transaction = bus_transaction_new (d->connections->context)) == NULL)
251 _dbus_wait_for_memory ();
253 if (!bus_service_remove_owner (service, connection,
254 transaction, &error))
256 _DBUS_ASSERT_ERROR_IS_SET (&error);
258 if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
260 dbus_error_free (&error);
261 bus_transaction_cancel_and_free (transaction);
262 _dbus_wait_for_memory ();
267 _dbus_verbose ("Failed to remove service owner: %s %s\n",
268 error.name, error.message);
269 _dbus_assert_not_reached ("Removing service owner failed for non-memory-related reason");
273 bus_transaction_execute_and_free (transaction);
276 bus_connection_clear_deferred_messages(connection);
278 bus_dispatch_remove_connection (connection);
280 /* no more watching */
281 if (!dbus_connection_set_watch_functions (connection,
285 _dbus_assert_not_reached ("setting watch functions to NULL failed");
287 if (!dbus_connection_set_timeout_functions (connection,
291 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
293 dbus_connection_set_unix_user_function (connection,
295 dbus_connection_set_windows_user_function (connection,
298 dbus_connection_set_dispatch_status_function (connection,
301 if (d->pending_unix_fds_timeout)
303 _dbus_loop_remove_timeout (bus_context_get_loop (d->connections->context),
304 d->pending_unix_fds_timeout);
305 _dbus_timeout_unref (d->pending_unix_fds_timeout);
307 d->pending_unix_fds_timeout = NULL;
308 _dbus_connection_set_pending_fds_function (connection, NULL, NULL);
310 bus_connection_remove_transactions (connection);
312 if (d->link_in_monitors != NULL)
314 BusMatchmaker *mm = d->connections->monitor_matchmaker;
317 bus_matchmaker_disconnected (mm, connection);
319 _dbus_list_remove_link (&d->connections->monitors, d->link_in_monitors);
320 d->link_in_monitors = NULL;
323 if (d->link_in_connection_list != NULL)
329 _dbus_list_remove_link (&d->connections->completed, d->link_in_connection_list);
330 d->link_in_connection_list = NULL;
331 d->connections->n_completed -= 1;
333 if (dbus_connection_get_unix_user (connection, &uid))
335 if (!adjust_connections_for_uid (d->connections,
337 _dbus_assert_not_reached ("adjusting downward should never fail");
342 _dbus_list_remove_link (&d->connections->incomplete, d->link_in_connection_list);
343 d->link_in_connection_list = NULL;
344 d->connections->n_incomplete -= 1;
346 /* If we have dropped below the max. number of incomplete
347 * connections, start accept()ing again */
348 bus_context_check_all_watches (d->connections->context);
351 _dbus_assert (d->connections->n_incomplete >= 0);
352 _dbus_assert (d->connections->n_completed >= 0);
355 bus_connection_drop_pending_replies (d->connections, connection);
357 /* frees "d" as side effect */
358 dbus_connection_set_data (connection,
359 connection_data_slot,
362 dbus_connection_unref (connection);
366 add_connection_watch (DBusWatch *watch,
369 DBusConnection *connection = data;
371 return _dbus_loop_add_watch (bus_connection_get_loop (connection), watch);
375 remove_connection_watch (DBusWatch *watch,
378 DBusConnection *connection = data;
380 _dbus_loop_remove_watch (bus_connection_get_loop (connection), watch);
384 toggle_connection_watch (DBusWatch *watch,
387 DBusConnection *connection = data;
389 _dbus_loop_toggle_watch (bus_connection_get_loop (connection), watch);
393 add_connection_timeout (DBusTimeout *timeout,
396 DBusConnection *connection = data;
398 return _dbus_loop_add_timeout (bus_connection_get_loop (connection), timeout);
402 remove_connection_timeout (DBusTimeout *timeout,
405 DBusConnection *connection = data;
407 _dbus_loop_remove_timeout (bus_connection_get_loop (connection), timeout);
411 dispatch_status_function (DBusConnection *connection,
412 DBusDispatchStatus new_status,
415 DBusLoop *loop = data;
417 if (new_status != DBUS_DISPATCH_COMPLETE)
419 while (!_dbus_loop_queue_dispatch (loop, connection))
420 _dbus_wait_for_memory ();
425 allow_unix_user_function (DBusConnection *connection,
429 BusConnectionData *d;
431 d = BUS_CONNECTION_DATA (connection);
433 _dbus_assert (d != NULL);
435 return bus_context_allow_unix_user (d->connections->context, uid);
439 free_connection_data (void *data)
441 BusConnectionData *d = data;
443 /* services_owned should be NULL since we should be disconnected */
444 _dbus_assert (d->services_owned == NULL);
445 _dbus_assert (d->n_services_owned == 0);
447 _dbus_assert (d->transaction_messages == NULL);
449 if (d->oom_preallocated)
450 dbus_connection_free_preallocated_send (d->connection, d->oom_preallocated);
453 dbus_message_unref (d->oom_message);
456 bus_client_policy_unref (d->policy);
458 if (d->apparmor_confinement)
459 bus_apparmor_confinement_unref (d->apparmor_confinement);
461 dbus_free (d->cached_loginfo_string);
465 #ifdef DBUS_ENABLE_CYNARA
466 free (d->cynara_session_id);
473 bus_connections_new (BusContext *context)
475 BusConnections *connections;
477 if (!dbus_connection_allocate_data_slot (&connection_data_slot))
480 connections = dbus_new0 (BusConnections, 1);
481 if (connections == NULL)
484 connections->completed_by_user = _dbus_hash_table_new (DBUS_HASH_UINTPTR,
486 if (connections->completed_by_user == NULL)
489 connections->expire_timeout = _dbus_timeout_new (100, /* irrelevant */
490 expire_incomplete_timeout,
492 if (connections->expire_timeout == NULL)
495 _dbus_timeout_disable (connections->expire_timeout);
497 connections->pending_replies = bus_expire_list_new (bus_context_get_loop (context),
498 bus_context_get_reply_timeout (context),
499 bus_pending_reply_expired,
501 if (connections->pending_replies == NULL)
504 if (!_dbus_loop_add_timeout (bus_context_get_loop (context),
505 connections->expire_timeout))
508 connections->refcount = 1;
509 connections->context = context;
514 bus_expire_list_free (connections->pending_replies);
516 _dbus_timeout_unref (connections->expire_timeout);
518 _dbus_hash_table_unref (connections->completed_by_user);
520 dbus_free (connections);
522 dbus_connection_free_data_slot (&connection_data_slot);
528 bus_connections_ref (BusConnections *connections)
530 _dbus_assert (connections->refcount > 0);
531 connections->refcount += 1;
537 bus_connections_unref (BusConnections *connections)
539 _dbus_assert (connections->refcount > 0);
540 connections->refcount -= 1;
541 if (connections->refcount == 0)
543 /* drop all incomplete */
544 while (connections->incomplete != NULL)
546 DBusConnection *connection;
548 connection = connections->incomplete->data;
550 dbus_connection_ref (connection);
551 dbus_connection_close (connection);
552 bus_connection_disconnected (connection);
553 dbus_connection_unref (connection);
556 _dbus_assert (connections->n_incomplete == 0);
558 /* drop all monitors */
559 _dbus_list_clear (&connections->monitors);
561 /* drop all real connections */
562 while (connections->completed != NULL)
564 DBusConnection *connection;
566 connection = connections->completed->data;
568 dbus_connection_ref (connection);
569 dbus_connection_close (connection);
570 bus_connection_disconnected (connection);
571 dbus_connection_unref (connection);
574 _dbus_assert (connections->n_completed == 0);
576 bus_expire_list_free (connections->pending_replies);
578 _dbus_loop_remove_timeout (bus_context_get_loop (connections->context),
579 connections->expire_timeout);
581 _dbus_timeout_unref (connections->expire_timeout);
583 _dbus_hash_table_unref (connections->completed_by_user);
585 if (connections->monitor_matchmaker != NULL)
586 bus_matchmaker_unref (connections->monitor_matchmaker);
588 dbus_free (connections);
590 dbus_connection_free_data_slot (&connection_data_slot);
595 is_context_type_session (BusConnectionData *d)
597 const char *context_type = bus_context_get_type (d->connections->context);
598 return context_type && !strcmp (context_type, "session");
601 /* Used for logging */
603 cache_peer_loginfo_string (BusConnectionData *d,
604 DBusConnection *connection)
606 DBusString loginfo_buf;
609 char *windows_sid = NULL, *security_label = NULL;
610 dbus_bool_t prev_added;
612 if (!_dbus_string_init (&loginfo_buf))
616 if (dbus_connection_get_unix_user (connection, &uid))
618 if (!_dbus_string_append_printf (&loginfo_buf, "uid=%ld", uid))
624 if (dbus_connection_get_unix_process_id (connection, &pid))
628 if (!_dbus_string_append_byte (&loginfo_buf, ' '))
631 if (!_dbus_string_append_printf (&loginfo_buf, "pid=%ld comm=\"", pid))
633 /* Ignore errors here; we may not have permissions to read the
635 * Don't even try it for the session daemon, to avoid cluttering logs with security error logs for
636 * accessing the proc file.
638 if (!is_context_type_session(d))
640 _dbus_command_for_pid (pid, &loginfo_buf, MAX_LOG_COMMAND_LEN, NULL);
644 if (!_dbus_string_append (&loginfo_buf, "<not-read>")) /* for session daemon just say that we didn't try */
647 if (!_dbus_string_append_byte (&loginfo_buf, '"'))
653 if (dbus_connection_get_windows_user (connection, &windows_sid))
655 dbus_bool_t did_append;
659 if (!_dbus_string_append_byte (&loginfo_buf, ' '))
663 did_append = _dbus_string_append_printf (&loginfo_buf,
664 "sid=\"%s\"", windows_sid);
665 dbus_free (windows_sid);
673 if (_dbus_connection_get_linux_security_label (connection, &security_label))
675 dbus_bool_t did_append;
679 if (!_dbus_string_append_byte (&loginfo_buf, ' '))
683 did_append = _dbus_string_append_printf (&loginfo_buf,
684 "label=\"%s\"", security_label);
685 dbus_free (security_label);
686 security_label = NULL;
693 if (!_dbus_string_steal_data (&loginfo_buf, &(d->cached_loginfo_string)))
696 _dbus_string_free (&loginfo_buf);
700 _dbus_string_free (&loginfo_buf);
701 if (security_label != NULL)
702 dbus_free (security_label);
703 if (windows_sid != NULL)
704 dbus_free (windows_sid);
710 check_pending_fds_cb (DBusConnection *connection)
712 BusConnectionData *d = BUS_CONNECTION_DATA (connection);
713 int n_pending_unix_fds_old;
714 int n_pending_unix_fds_new;
716 _dbus_assert(d != NULL);
718 n_pending_unix_fds_old = d->n_pending_unix_fds;
719 n_pending_unix_fds_new = _dbus_connection_get_pending_fds_count (connection);
721 _dbus_verbose ("Pending fds count changed on connection %p: %d -> %d\n",
722 connection, n_pending_unix_fds_old, n_pending_unix_fds_new);
724 if (n_pending_unix_fds_old == 0 && n_pending_unix_fds_new > 0)
726 _dbus_timeout_restart (d->pending_unix_fds_timeout,
727 bus_context_get_pending_fd_timeout (d->connections->context));
730 if (n_pending_unix_fds_old > 0 && n_pending_unix_fds_new == 0)
732 _dbus_timeout_disable (d->pending_unix_fds_timeout);
736 d->n_pending_unix_fds = n_pending_unix_fds_new;
740 pending_unix_fds_timeout_cb (void *data)
742 DBusConnection *connection = data;
743 BusConnectionData *d = BUS_CONNECTION_DATA (connection);
746 _dbus_assert (d != NULL);
747 limit = bus_context_get_pending_fd_timeout (d->connections->context);
748 bus_context_log (d->connections->context, DBUS_SYSTEM_LOG_WARNING,
749 "Connection \"%s\" (%s) has had Unix fds pending for too long, "
750 "closing it (pending_fd_timeout=%d ms)",
751 d->name != NULL ? d->name : "(null)",
752 bus_connection_get_loginfo (connection),
755 dbus_connection_close (connection);
760 bus_connections_setup_connection (BusConnections *connections,
761 DBusConnection *connection)
764 BusConnectionData *d = NULL;
767 d = dbus_new0 (BusConnectionData, 1);
772 d->connections = connections;
773 d->connection = connection;
775 _dbus_get_monotonic_time (&d->connection_tv_sec,
776 &d->connection_tv_usec);
778 _dbus_assert (connection_data_slot >= 0);
780 if (!dbus_connection_set_data (connection,
781 connection_data_slot,
782 d, free_connection_data))
784 /* We have to free d explicitly, because this is the only code
785 * path where it's non-NULL but dbus_connection_set_data() hasn't
786 * taken responsibility for freeing it. */
792 dbus_connection_set_route_peer_messages (connection, TRUE);
794 dbus_error_init (&error);
795 d->selinux_id = bus_selinux_init_connection_id (connection,
797 if (dbus_error_is_set (&error))
799 bus_context_log (connections->context, DBUS_SYSTEM_LOG_WARNING,
800 "Unable to set up new connection: %s", error.message);
801 dbus_error_free (&error);
805 d->apparmor_confinement = bus_apparmor_init_connection_confinement (connection,
807 if (dbus_error_is_set (&error))
809 bus_context_log (connections->context, DBUS_SYSTEM_LOG_WARNING,
810 "Unable to set up new connection: %s", error.message);
811 dbus_error_free (&error);
815 if (!dbus_connection_set_watch_functions (connection,
816 add_connection_watch,
817 remove_connection_watch,
818 toggle_connection_watch,
823 if (!dbus_connection_set_timeout_functions (connection,
824 add_connection_timeout,
825 remove_connection_timeout,
830 /* For now we don't need to set a Windows user function because
831 * there are no policies in the config file controlling what
832 * Windows users can connect. The default 'same user that owns the
833 * bus can connect' behavior of DBusConnection is fine on Windows.
835 dbus_connection_set_unix_user_function (connection,
836 allow_unix_user_function,
839 dbus_connection_set_dispatch_status_function (connection,
840 dispatch_status_function,
841 bus_context_get_loop (connections->context),
844 d->link_in_connection_list = _dbus_list_alloc_link (connection);
845 if (d->link_in_connection_list == NULL)
848 /* Setup the connection with the dispatcher */
849 if (!bus_dispatch_add_connection (connection))
852 if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
854 if (!_dbus_loop_queue_dispatch (bus_context_get_loop (connections->context), connection))
856 bus_dispatch_remove_connection (connection);
861 /* Setup pending fds timeout (see #80559) */
862 d->pending_unix_fds_timeout = _dbus_timeout_new (100, /* irrelevant */
863 pending_unix_fds_timeout_cb,
865 if (d->pending_unix_fds_timeout == NULL)
868 _dbus_timeout_disable (d->pending_unix_fds_timeout);
869 if (!_dbus_loop_add_timeout (bus_context_get_loop (connections->context),
870 d->pending_unix_fds_timeout))
873 _dbus_connection_set_pending_fds_function (connection,
874 (DBusPendingFdsChangeFunction) check_pending_fds_cb,
877 _dbus_list_append_link (&connections->incomplete, d->link_in_connection_list);
878 connections->n_incomplete += 1;
880 dbus_connection_ref (connection);
882 bus_connections_expire_incomplete (connections);
884 /* The listening socket is removed from the main loop,
885 * i.e. does not accept(), while n_incomplete is at its
886 * maximum value; so we shouldn't get here in that case */
887 _dbus_assert (connections->n_incomplete <=
888 bus_context_get_max_incomplete_connections (connections->context));
890 /* If we have the maximum number of incomplete connections,
891 * stop accept()ing any more, to avert a DoS. See fd.o #80919 */
892 bus_context_check_all_watches (d->connections->context);
897 bus_context_log (connections->context, DBUS_SYSTEM_LOG_WARNING,
898 "No memory to set up new connection");
903 d->selinux_id = NULL;
905 if (d->apparmor_confinement)
906 bus_apparmor_confinement_unref (d->apparmor_confinement);
907 d->apparmor_confinement = NULL;
909 if (!dbus_connection_set_watch_functions (connection,
913 _dbus_assert_not_reached ("setting watch functions to NULL failed");
915 if (!dbus_connection_set_timeout_functions (connection,
919 _dbus_assert_not_reached ("setting timeout functions to NULL failed");
921 dbus_connection_set_unix_user_function (connection,
924 dbus_connection_set_windows_user_function (connection,
927 dbus_connection_set_dispatch_status_function (connection,
930 if (d->pending_unix_fds_timeout)
931 _dbus_timeout_unref (d->pending_unix_fds_timeout);
933 d->pending_unix_fds_timeout = NULL;
935 _dbus_connection_set_pending_fds_function (connection, NULL, NULL);
937 if (d->link_in_connection_list != NULL)
939 _dbus_assert (d->link_in_connection_list->next == NULL);
940 _dbus_assert (d->link_in_connection_list->prev == NULL);
941 _dbus_list_free_link (d->link_in_connection_list);
942 d->link_in_connection_list = NULL;
945 if (!dbus_connection_set_data (connection,
946 connection_data_slot,
948 _dbus_assert_not_reached ("failed to set connection data to null");
950 /* "d" has now been freed */
957 bus_connections_expire_incomplete (BusConnections *connections)
963 if (connections->incomplete != NULL)
965 long tv_sec, tv_usec;
969 _dbus_get_monotonic_time (&tv_sec, &tv_usec);
970 auth_timeout = bus_context_get_auth_timeout (connections->context);
972 link = _dbus_list_get_first_link (&connections->incomplete);
975 DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
976 DBusConnection *connection;
977 BusConnectionData *d;
980 connection = link->data;
982 d = BUS_CONNECTION_DATA (connection);
984 _dbus_assert (d != NULL);
986 elapsed = ELAPSED_MILLISECONDS_SINCE (d->connection_tv_sec,
987 d->connection_tv_usec,
990 if (elapsed >= (double) auth_timeout)
992 /* Unfortunately, we can't identify the connection: it doesn't
993 * have a unique name yet, we don't know its uid/pid yet,
995 bus_context_log (connections->context, DBUS_SYSTEM_LOG_WARNING,
996 "Connection has not authenticated soon enough, closing it "
997 "(auth_timeout=%dms, elapsed: %.0fms)",
998 auth_timeout, elapsed);
1000 _dbus_verbose ("Timing out authentication for connection %p\n", connection);
1001 dbus_connection_close (connection);
1005 /* We can end the loop, since the connections are in oldest-first order */
1006 next_interval = ((double)auth_timeout) - elapsed;
1007 _dbus_verbose ("Connection %p authentication expires in %d milliseconds\n",
1008 connection, next_interval);
1017 bus_expire_timeout_set_interval (connections->expire_timeout,
1022 expire_incomplete_timeout (void *data)
1024 BusConnections *connections = data;
1026 _dbus_verbose ("Running\n");
1028 /* note that this may remove the timeout */
1029 bus_connections_expire_incomplete (connections);
1035 bus_connection_get_unix_groups (DBusConnection *connection,
1036 unsigned long **groups,
1045 if (dbus_connection_get_unix_user (connection, &uid))
1047 if (!_dbus_unix_groups_from_uid (uid, groups, n_groups))
1049 _dbus_verbose ("Did not get any groups for UID %lu\n",
1055 _dbus_verbose ("Got %d groups for UID %lu\n",
1061 return TRUE; /* successfully got 0 groups */
1065 bus_connection_is_in_unix_group (DBusConnection *connection,
1069 unsigned long *group_ids;
1072 if (!bus_connection_get_unix_groups (connection, &group_ids, &n_group_ids,
1077 while (i < n_group_ids)
1079 if (group_ids[i] == gid)
1081 dbus_free (group_ids);
1087 dbus_free (group_ids);
1092 bus_connection_get_loginfo (DBusConnection *connection)
1094 BusConnectionData *d;
1096 d = BUS_CONNECTION_DATA (connection);
1097 _dbus_assert(d != NULL);
1099 if (!bus_connection_is_active (connection))
1101 return d->cached_loginfo_string;
1105 bus_connection_get_policy (DBusConnection *connection)
1107 BusConnectionData *d;
1109 d = BUS_CONNECTION_DATA (connection);
1111 _dbus_assert (d != NULL);
1112 _dbus_assert (d->policy != NULL);
1117 #ifdef DBUS_ENABLE_CYNARA
1118 const char *bus_connection_get_cynara_session_id (DBusConnection *connection)
1120 BusConnectionData *d = BUS_CONNECTION_DATA (connection);
1121 _dbus_assert (d != NULL);
1123 if (d->cynara_session_id == NULL)
1126 if (dbus_connection_get_unix_process_id(connection, &pid))
1127 d->cynara_session_id = cynara_session_from_pid(pid);
1129 /* If client exits as soon as async call, cynara_session_from_pid() returns null.
1130 cynara_session_from_pid checks /proc/pid to verify process */
1131 if (d->cynara_session_id == NULL)
1132 asprintf (&d->cynara_session_id, "/proc/%ld", pid);
1134 return d->cynara_session_id;
1139 foreach_active (BusConnections *connections,
1140 BusConnectionForeachFunction function,
1145 link = _dbus_list_get_first_link (&connections->completed);
1146 while (link != NULL)
1148 DBusConnection *connection = link->data;
1149 DBusList *next = _dbus_list_get_next_link (&connections->completed, link);
1151 if (!(* function) (connection, data))
1161 foreach_inactive (BusConnections *connections,
1162 BusConnectionForeachFunction function,
1167 link = _dbus_list_get_first_link (&connections->incomplete);
1168 while (link != NULL)
1170 DBusConnection *connection = link->data;
1171 DBusList *next = _dbus_list_get_next_link (&connections->incomplete, link);
1173 if (!(* function) (connection, data))
1183 * Calls function on each active connection; if the function returns
1184 * #FALSE, stops iterating. Active connections are authenticated
1185 * and have sent a Hello message.
1187 * @param connections the connections object
1188 * @param function the function
1189 * @param data data to pass to it as a second arg
1192 bus_connections_foreach_active (BusConnections *connections,
1193 BusConnectionForeachFunction function,
1196 foreach_active (connections, function, data);
1200 * Calls function on each connection; if the function returns
1201 * #FALSE, stops iterating.
1203 * @param connections the connections object
1204 * @param function the function
1205 * @param data data to pass to it as a second arg
1208 bus_connections_foreach (BusConnections *connections,
1209 BusConnectionForeachFunction function,
1212 if (!foreach_active (connections, function, data))
1215 foreach_inactive (connections, function, data);
1219 bus_connections_get_context (BusConnections *connections)
1221 return connections->context;
1225 * This is used to avoid covering the same connection twice when
1226 * traversing connections. Note that it assumes we will
1227 * bus_connection_mark_stamp() each connection at least once per
1228 * INT_MAX increments of the global stamp, or wraparound would break
1232 bus_connections_increment_stamp (BusConnections *connections)
1234 connections->stamp += 1;
1237 /* Mark connection with current stamp, return TRUE if it
1238 * didn't already have that stamp
1241 bus_connection_mark_stamp (DBusConnection *connection)
1243 BusConnectionData *d;
1245 d = BUS_CONNECTION_DATA (connection);
1247 _dbus_assert (d != NULL);
1249 if (d->stamp == d->connections->stamp)
1253 d->stamp = d->connections->stamp;
1259 bus_connection_get_context (DBusConnection *connection)
1261 BusConnectionData *d;
1263 d = BUS_CONNECTION_DATA (connection);
1265 _dbus_assert (d != NULL);
1267 return d->connections->context;
1271 bus_connection_get_connections (DBusConnection *connection)
1273 BusConnectionData *d;
1275 d = BUS_CONNECTION_DATA (connection);
1277 _dbus_assert (d != NULL);
1279 return d->connections;
1283 bus_connection_get_registry (DBusConnection *connection)
1285 BusConnectionData *d;
1287 d = BUS_CONNECTION_DATA (connection);
1289 _dbus_assert (d != NULL);
1291 return bus_context_get_registry (d->connections->context);
1295 bus_connection_get_activation (DBusConnection *connection)
1297 BusConnectionData *d;
1299 d = BUS_CONNECTION_DATA (connection);
1301 _dbus_assert (d != NULL);
1303 return bus_context_get_activation (d->connections->context);
1307 bus_connection_get_matchmaker (DBusConnection *connection)
1309 BusConnectionData *d;
1311 d = BUS_CONNECTION_DATA (connection);
1313 _dbus_assert (d != NULL);
1315 return bus_context_get_matchmaker (d->connections->context);
1319 bus_connection_get_selinux_id (DBusConnection *connection)
1321 BusConnectionData *d;
1323 d = BUS_CONNECTION_DATA (connection);
1325 _dbus_assert (d != NULL);
1327 return d->selinux_id;
1330 BusAppArmorConfinement*
1331 bus_connection_dup_apparmor_confinement (DBusConnection *connection)
1333 BusConnectionData *d;
1335 d = BUS_CONNECTION_DATA (connection);
1337 _dbus_assert (d != NULL);
1339 bus_apparmor_confinement_ref (d->apparmor_confinement);
1340 return d->apparmor_confinement;
1344 * Checks whether the connection is registered with the message bus.
1346 * @param connection the connection
1347 * @returns #TRUE if we're an active message bus participant
1350 bus_connection_is_active (DBusConnection *connection)
1352 BusConnectionData *d;
1354 d = BUS_CONNECTION_DATA (connection);
1355 _dbus_assert(d != NULL);
1357 return d->name != NULL;
1361 bus_connection_preallocate_oom_error (DBusConnection *connection)
1363 DBusMessage *message;
1364 DBusPreallocatedSend *preallocated;
1365 BusConnectionData *d;
1367 d = BUS_CONNECTION_DATA (connection);
1369 _dbus_assert (d != NULL);
1371 if (d->oom_preallocated != NULL)
1374 preallocated = dbus_connection_preallocate_send (connection);
1375 if (preallocated == NULL)
1378 message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1380 if (message == NULL)
1382 dbus_connection_free_preallocated_send (connection, preallocated);
1386 /* d->name may be NULL, but that is OK */
1387 if (!dbus_message_set_error_name (message, DBUS_ERROR_NO_MEMORY) ||
1388 !dbus_message_set_destination (message, d->name) ||
1389 !dbus_message_set_sender (message,
1392 dbus_connection_free_preallocated_send (connection, preallocated);
1393 dbus_message_unref (message);
1397 /* set reply serial to placeholder value just so space is already allocated
1400 if (!dbus_message_set_reply_serial (message, 14))
1402 dbus_connection_free_preallocated_send (connection, preallocated);
1403 dbus_message_unref (message);
1407 d->oom_message = message;
1408 d->oom_preallocated = preallocated;
1414 bus_connection_send_oom_error (DBusConnection *connection,
1415 DBusMessage *in_reply_to)
1417 BusConnectionData *d;
1419 d = BUS_CONNECTION_DATA (connection);
1421 _dbus_assert (d != NULL);
1422 _dbus_assert (d->oom_message != NULL);
1424 bus_context_log (d->connections->context, DBUS_SYSTEM_LOG_WARNING,
1425 "dbus-daemon transaction failed (OOM), sending error to "
1426 "sender %s", bus_connection_get_loginfo (connection));
1428 /* should always succeed since we set it to a placeholder earlier */
1429 if (!dbus_message_set_reply_serial (d->oom_message,
1430 dbus_message_get_serial (in_reply_to)))
1431 _dbus_assert_not_reached ("Failed to set reply serial for preallocated oom message");
1433 _dbus_assert (dbus_message_get_sender (d->oom_message) != NULL);
1435 dbus_connection_send_preallocated (connection, d->oom_preallocated,
1436 d->oom_message, NULL);
1438 dbus_message_unref (d->oom_message);
1439 d->oom_message = NULL;
1440 d->oom_preallocated = NULL;
1443 #ifdef DBUS_ENABLE_STATS
1445 update_peak (int *peak,
1454 bus_connection_add_match_rule_link (DBusConnection *connection,
1457 BusConnectionData *d;
1459 d = BUS_CONNECTION_DATA (connection);
1460 _dbus_assert (d != NULL);
1462 _dbus_list_append_link (&d->match_rules, link);
1464 d->n_match_rules += 1;
1466 #ifdef DBUS_ENABLE_STATS
1467 update_peak (&d->peak_match_rules, d->n_match_rules);
1468 update_peak (&d->connections->peak_match_rules_per_conn, d->n_match_rules);
1470 d->connections->total_match_rules += 1;
1471 update_peak (&d->connections->peak_match_rules,
1472 d->connections->total_match_rules);
1477 bus_connection_add_match_rule (DBusConnection *connection,
1482 link = _dbus_list_alloc_link (rule);
1487 bus_connection_add_match_rule_link (connection, link);
1493 bus_connection_remove_match_rule (DBusConnection *connection,
1496 BusConnectionData *d;
1498 d = BUS_CONNECTION_DATA (connection);
1499 _dbus_assert (d != NULL);
1501 _dbus_list_remove_last (&d->match_rules, rule);
1503 d->n_match_rules -= 1;
1504 _dbus_assert (d->n_match_rules >= 0);
1506 #ifdef DBUS_ENABLE_STATS
1507 d->connections->total_match_rules -= 1;
1512 bus_connection_get_n_match_rules (DBusConnection *connection)
1514 BusConnectionData *d;
1516 d = BUS_CONNECTION_DATA (connection);
1517 _dbus_assert (d != NULL);
1519 return d->n_match_rules;
1523 bus_connection_is_service_owner_by_prefix (DBusConnection *connection,
1524 const char *name_prefix)
1526 BusConnectionData *d;
1529 d = BUS_CONNECTION_DATA (connection);
1530 _dbus_assert (d != NULL);
1532 link = _dbus_list_get_first_link (&d->services_owned);
1533 while (link != NULL)
1535 BusService *service = link->data;
1538 _dbus_string_init_const (&str, bus_service_get_name (service));
1540 if (_dbus_string_starts_with_words_c_str (&str, name_prefix, '.'))
1543 link = _dbus_list_get_next_link (&d->services_owned, link);
1550 bus_connection_get_owned_services_list (DBusConnection *connection)
1552 BusConnectionData *d;
1554 d = BUS_CONNECTION_DATA (connection);
1556 _dbus_assert (d != NULL);
1558 return d->services_owned;
1562 bus_connection_add_owned_service_link (DBusConnection *connection,
1565 BusConnectionData *d;
1567 d = BUS_CONNECTION_DATA (connection);
1568 _dbus_assert (d != NULL);
1570 _dbus_list_append_link (&d->services_owned, link);
1572 d->n_services_owned += 1;
1574 #ifdef DBUS_ENABLE_STATS
1575 update_peak (&d->peak_bus_names, d->n_services_owned);
1576 update_peak (&d->connections->peak_bus_names_per_conn,
1577 d->n_services_owned);
1579 d->connections->total_bus_names += 1;
1580 update_peak (&d->connections->peak_bus_names,
1581 d->connections->total_bus_names);
1586 bus_connection_add_owned_service (DBusConnection *connection,
1587 BusService *service)
1591 link = _dbus_list_alloc_link (service);
1596 bus_connection_add_owned_service_link (connection, link);
1602 bus_connection_remove_owned_service (DBusConnection *connection,
1603 BusService *service)
1605 BusConnectionData *d;
1607 d = BUS_CONNECTION_DATA (connection);
1608 _dbus_assert (d != NULL);
1610 _dbus_list_remove_last (&d->services_owned, service);
1612 d->n_services_owned -= 1;
1613 _dbus_assert (d->n_services_owned >= 0);
1615 #ifdef DBUS_ENABLE_STATS
1616 d->connections->total_bus_names -= 1;
1621 bus_connection_get_n_services_owned (DBusConnection *connection)
1623 BusConnectionData *d;
1625 d = BUS_CONNECTION_DATA (connection);
1626 _dbus_assert (d != NULL);
1628 return d->n_services_owned;
1632 bus_connection_complete (DBusConnection *connection,
1633 const DBusString *name,
1636 BusConnectionData *d;
1639 d = BUS_CONNECTION_DATA (connection);
1640 _dbus_assert (d != NULL);
1641 _dbus_assert (d->name == NULL);
1642 _dbus_assert (d->policy == NULL);
1644 _dbus_assert (!bus_connection_is_active (connection));
1646 if (!_dbus_string_copy_data (name, &d->name))
1648 BUS_SET_OOM (error);
1652 _dbus_assert (d->name != NULL);
1654 _dbus_verbose ("Name %s assigned to %p\n", d->name, connection);
1656 d->policy = bus_context_create_client_policy (d->connections->context,
1660 /* we may have a NULL policy on OOM or error getting list of
1661 * groups for a user. In the latter case we don't handle it so
1662 * well currently, as it will just keep failing over and over.
1665 if (d->policy == NULL)
1667 _dbus_verbose ("Failed to create security policy for connection %p\n",
1669 _DBUS_ASSERT_ERROR_IS_SET (error);
1670 dbus_free (d->name);
1675 if (dbus_connection_get_unix_user (connection, &uid))
1677 if (!adjust_connections_for_uid (d->connections,
1682 /* Create and cache a string which holds information about the
1683 * peer process; used for logging purposes.
1685 if (!cache_peer_loginfo_string (d, connection))
1688 /* Now the connection is active, move it between lists */
1689 _dbus_list_unlink (&d->connections->incomplete,
1690 d->link_in_connection_list);
1691 d->connections->n_incomplete -= 1;
1692 _dbus_list_append_link (&d->connections->completed,
1693 d->link_in_connection_list);
1694 d->connections->n_completed += 1;
1696 _dbus_assert (d->connections->n_incomplete >= 0);
1697 _dbus_assert (d->connections->n_completed > 0);
1699 /* If we have dropped below the max. number of incomplete
1700 * connections, start accept()ing again */
1701 bus_context_check_all_watches (d->connections->context);
1703 /* See if we can remove the timeout */
1704 bus_connections_expire_incomplete (d->connections);
1706 _dbus_assert (bus_connection_is_active (connection));
1710 BUS_SET_OOM (error);
1711 dbus_free (d->name);
1714 bus_client_policy_unref (d->policy);
1720 bus_connections_reload_policy (BusConnections *connections,
1723 BusConnectionData *d;
1724 DBusConnection *connection;
1727 _dbus_assert (connections != NULL);
1728 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1730 for (link = _dbus_list_get_first_link (&(connections->completed));
1732 link = _dbus_list_get_next_link (&(connections->completed), link))
1734 connection = link->data;
1735 d = BUS_CONNECTION_DATA (connection);
1736 _dbus_assert (d != NULL);
1737 _dbus_assert (d->policy != NULL);
1739 bus_client_policy_unref (d->policy);
1740 d->policy = bus_context_create_client_policy (connections->context,
1743 if (d->policy == NULL)
1745 _dbus_verbose ("Failed to create security policy for connection %p\n",
1747 _DBUS_ASSERT_ERROR_IS_SET (error);
1756 bus_connection_get_name (DBusConnection *connection)
1758 BusConnectionData *d;
1760 d = BUS_CONNECTION_DATA (connection);
1761 _dbus_assert (d != NULL);
1767 * Check whether completing the passed-in connection would
1768 * exceed limits, and if so set error and return #FALSE
1771 bus_connections_check_limits (BusConnections *connections,
1772 DBusConnection *requesting_completion,
1773 const char **limit_name_out,
1780 limit = bus_context_get_max_completed_connections (connections->context);
1782 if (connections->n_completed >= limit)
1784 if (limit_name_out != NULL)
1785 *limit_name_out = "max_completed_connections";
1787 if (limit_out != NULL)
1790 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1791 "The maximum number of active connections has been reached");
1795 if (dbus_connection_get_unix_user (requesting_completion, &uid))
1797 limit = bus_context_get_max_connections_per_user (connections->context);
1799 if (get_connections_for_uid (connections, uid) >= limit)
1801 if (limit_name_out != NULL)
1802 *limit_name_out = "max_connections_per_user";
1804 if (limit_out != NULL)
1807 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
1808 "The maximum number of active connections for UID %lu has been reached",
1818 bus_pending_reply_free (BusPendingReply *pending)
1820 _dbus_verbose ("Freeing pending reply %p, replier %p receiver %p serial %u\n",
1822 pending->will_send_reply,
1823 pending->will_get_reply,
1824 pending->reply_serial);
1826 dbus_free (pending);
1830 bus_pending_reply_send_no_reply (BusConnections *connections,
1831 BusTransaction *transaction,
1832 BusPendingReply *pending)
1834 DBusMessage *message;
1835 DBusMessageIter iter;
1841 message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
1842 if (message == NULL)
1845 dbus_message_set_no_reply (message, TRUE);
1847 if (!dbus_message_set_reply_serial (message,
1848 pending->reply_serial))
1851 if (!dbus_message_set_error_name (message,
1852 DBUS_ERROR_NO_REPLY))
1855 /* If you change these messages, adjust test/dbus-daemon.c to match */
1856 if (pending->will_send_reply == NULL)
1857 errmsg = "Message recipient disconnected from message bus without replying";
1859 errmsg = "Message did not receive a reply (timeout by message bus)";
1861 dbus_message_iter_init_append (message, &iter);
1862 if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &errmsg))
1865 if (!bus_transaction_send_from_driver (transaction, pending->will_get_reply,
1872 dbus_message_unref (message);
1877 bus_pending_reply_expired (BusExpireList *list,
1881 BusPendingReply *pending = link->data;
1882 BusConnections *connections = data;
1883 BusTransaction *transaction;
1885 /* No reply is forthcoming. So nuke it if we can. If not,
1886 * leave it in the list to try expiring again later when we
1890 _dbus_verbose ("Expiring pending reply %p, replier %p receiver %p serial %u\n",
1892 pending->will_send_reply,
1893 pending->will_get_reply,
1894 pending->reply_serial);
1896 transaction = bus_transaction_new (connections->context);
1897 if (transaction == NULL)
1900 if (!bus_pending_reply_send_no_reply (connections,
1904 bus_transaction_cancel_and_free (transaction);
1908 bus_expire_list_remove_link (connections->pending_replies, link);
1910 bus_pending_reply_free (pending);
1911 bus_transaction_execute_and_free (transaction);
1917 bus_connection_drop_pending_replies (BusConnections *connections,
1918 DBusConnection *connection)
1920 /* The DBusConnection is almost 100% finalized here, so you can't
1921 * do anything with it except check for pointer equality
1925 _dbus_verbose ("Dropping pending replies that involve connection %p\n",
1928 link = bus_expire_list_get_first_link (connections->pending_replies);
1929 while (link != NULL)
1932 BusPendingReply *pending;
1934 next = bus_expire_list_get_next_link (connections->pending_replies,
1936 pending = link->data;
1938 if (pending->will_get_reply == connection)
1940 /* We don't need to track this pending reply anymore */
1942 _dbus_verbose ("Dropping pending reply %p, replier %p receiver %p serial %u\n",
1944 pending->will_send_reply,
1945 pending->will_get_reply,
1946 pending->reply_serial);
1948 bus_expire_list_remove_link (connections->pending_replies,
1950 bus_pending_reply_free (pending);
1952 else if (pending->will_send_reply == connection)
1954 /* The reply isn't going to be sent, so set things
1955 * up so it will be expired right away
1957 _dbus_verbose ("Will expire pending reply %p, replier %p receiver %p serial %u\n",
1959 pending->will_send_reply,
1960 pending->will_get_reply,
1961 pending->reply_serial);
1963 pending->will_send_reply = NULL;
1964 pending->expire_item.added_tv_sec = 0;
1965 pending->expire_item.added_tv_usec = 0;
1967 bus_expire_list_recheck_immediately (connections->pending_replies);
1977 BusPendingReply *pending;
1978 BusConnections *connections;
1979 } CancelPendingReplyData;
1982 cancel_pending_reply (void *data)
1984 CancelPendingReplyData *d = data;
1986 _dbus_verbose ("d = %p\n", d);
1988 if (!bus_expire_list_remove (d->connections->pending_replies,
1989 &d->pending->expire_item))
1990 _dbus_assert_not_reached ("pending reply did not exist to be cancelled");
1992 bus_pending_reply_free (d->pending); /* since it's been cancelled */
1996 cancel_pending_reply_data_free (void *data)
1998 CancelPendingReplyData *d = data;
2000 _dbus_verbose ("d = %p\n", d);
2002 /* d->pending should be either freed or still
2003 * in the list of pending replies (owned by someone
2011 * Record that a reply is allowed; return TRUE on success.
2014 bus_connections_expect_reply (BusConnections *connections,
2015 BusTransaction *transaction,
2016 DBusConnection *will_get_reply,
2017 DBusConnection *will_send_reply,
2018 DBusMessage *reply_to_this,
2021 BusPendingReply *pending;
2022 dbus_uint32_t reply_serial;
2024 CancelPendingReplyData *cprd;
2028 _dbus_assert (will_get_reply != NULL);
2029 _dbus_assert (will_send_reply != NULL);
2030 _dbus_assert (reply_to_this != NULL);
2032 if (dbus_message_get_no_reply (reply_to_this))
2033 return TRUE; /* we won't allow a reply, since client doesn't care for one. */
2035 reply_serial = dbus_message_get_serial (reply_to_this);
2037 link = bus_expire_list_get_first_link (connections->pending_replies);
2039 while (link != NULL)
2041 pending = link->data;
2043 if (pending->reply_serial == reply_serial &&
2044 pending->will_get_reply == will_get_reply &&
2045 pending->will_send_reply == will_send_reply)
2047 dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
2048 "Message has the same reply serial as a currently-outstanding existing method call");
2052 link = bus_expire_list_get_next_link (connections->pending_replies,
2054 if (pending->will_get_reply == will_get_reply)
2058 limit = bus_context_get_max_replies_per_connection (connections->context);
2062 bus_context_log (connections->context, DBUS_SYSTEM_LOG_WARNING,
2063 "The maximum number of pending replies for "
2064 "\"%s\" (%s) has been reached "
2065 "(max_replies_per_connection=%d)",
2066 bus_connection_get_name (will_get_reply),
2067 bus_connection_get_loginfo (will_get_reply),
2070 dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
2071 "The maximum number of pending replies per connection has been reached");
2075 #ifdef DBUS_ENABLE_STATS
2077 BusConnectionData *d;
2079 d = BUS_CONNECTION_DATA (will_get_reply);
2080 _dbus_assert (d != NULL);
2082 update_peak(&d->peak_pending_replies, count);
2086 pending = dbus_new0 (BusPendingReply, 1);
2087 if (pending == NULL)
2089 BUS_SET_OOM (error);
2093 #ifdef DBUS_ENABLE_VERBOSE_MODE
2094 /* so we can see a not-yet-added pending reply */
2095 pending->expire_item.added_tv_sec = 1;
2096 pending->expire_item.added_tv_usec = 1;
2099 pending->will_get_reply = will_get_reply;
2100 pending->will_send_reply = will_send_reply;
2101 pending->reply_serial = reply_serial;
2103 cprd = dbus_new0 (CancelPendingReplyData, 1);
2106 BUS_SET_OOM (error);
2107 bus_pending_reply_free (pending);
2111 if (!bus_expire_list_add (connections->pending_replies,
2112 &pending->expire_item))
2114 BUS_SET_OOM (error);
2116 bus_pending_reply_free (pending);
2120 if (!bus_transaction_add_cancel_hook (transaction,
2121 cancel_pending_reply,
2123 cancel_pending_reply_data_free))
2125 BUS_SET_OOM (error);
2126 bus_expire_list_remove (connections->pending_replies, &pending->expire_item);
2128 bus_pending_reply_free (pending);
2132 cprd->pending = pending;
2133 cprd->connections = connections;
2135 _dbus_get_monotonic_time (&pending->expire_item.added_tv_sec,
2136 &pending->expire_item.added_tv_usec);
2138 _dbus_verbose ("Added pending reply %p, replier %p receiver %p serial %u\n",
2140 pending->will_send_reply,
2141 pending->will_get_reply,
2142 pending->reply_serial);
2150 BusConnections *connections;
2151 } CheckPendingReplyData;
2154 cancel_check_pending_reply (void *data)
2156 CheckPendingReplyData *d = data;
2158 _dbus_verbose ("d = %p\n",d);
2160 bus_expire_list_add_link (d->connections->pending_replies,
2166 check_pending_reply_data_free (void *data)
2168 CheckPendingReplyData *d = data;
2170 _dbus_verbose ("d = %p\n",d);
2172 if (d->link != NULL)
2174 BusPendingReply *pending = d->link->data;
2176 _dbus_assert (!bus_expire_list_contains_item (d->connections->pending_replies,
2177 &pending->expire_item));
2179 bus_pending_reply_free (pending);
2180 _dbus_list_free_link (d->link);
2187 * Check whether a reply is allowed, remove BusPendingReply
2188 * if so, return TRUE if so.
2191 bus_connections_check_reply (BusConnections *connections,
2192 BusTransaction *transaction,
2193 DBusConnection *sending_reply,
2194 DBusConnection *receiving_reply,
2198 CheckPendingReplyData *cprd;
2200 dbus_uint32_t reply_serial;
2202 _dbus_assert (sending_reply != NULL);
2203 _dbus_assert (receiving_reply != NULL);
2205 reply_serial = dbus_message_get_reply_serial (reply);
2207 link = bus_expire_list_get_first_link (connections->pending_replies);
2208 while (link != NULL)
2210 BusPendingReply *pending = link->data;
2212 if (pending->reply_serial == reply_serial &&
2213 pending->will_get_reply == receiving_reply &&
2214 pending->will_send_reply == sending_reply)
2216 _dbus_verbose ("Found pending reply with serial %u\n", reply_serial);
2220 link = bus_expire_list_get_next_link (connections->pending_replies,
2226 _dbus_verbose ("No pending reply expected\n");
2231 cprd = dbus_new0 (CheckPendingReplyData, 1);
2234 BUS_SET_OOM (error);
2238 if (!bus_transaction_add_cancel_hook (transaction,
2239 cancel_check_pending_reply,
2241 check_pending_reply_data_free))
2243 BUS_SET_OOM (error);
2249 cprd->connections = connections;
2251 bus_expire_list_unlink (connections->pending_replies,
2254 _dbus_assert (!bus_expire_list_contains_item (connections->pending_replies, link->data));
2262 * Note that this is fairly fragile; in particular, don't try to use
2263 * one transaction across any main loop iterations.
2268 BusTransaction *transaction;
2269 DBusMessage *message;
2270 DBusPreallocatedSend *preallocated;
2275 BusTransactionCancelFunction cancel_function;
2276 DBusFreeFunction free_data_function;
2280 struct BusTransaction
2282 DBusList *connections;
2283 BusContext *context;
2284 DBusList *cancel_hooks;
2288 message_to_send_free (DBusConnection *connection,
2289 MessageToSend *to_send)
2291 if (to_send->message)
2292 dbus_message_unref (to_send->message);
2294 if (to_send->preallocated)
2295 dbus_connection_free_preallocated_send (connection, to_send->preallocated);
2297 dbus_free (to_send);
2301 cancel_hook_cancel (void *element,
2304 CancelHook *ch = element;
2306 _dbus_verbose ("Running transaction cancel hook\n");
2308 if (ch->cancel_function)
2309 (* ch->cancel_function) (ch->data);
2313 cancel_hook_free (void *element,
2316 CancelHook *ch = element;
2318 if (ch->free_data_function)
2319 (* ch->free_data_function) (ch->data);
2325 free_cancel_hooks (BusTransaction *transaction)
2327 _dbus_list_foreach (&transaction->cancel_hooks,
2328 cancel_hook_free, NULL);
2330 _dbus_list_clear (&transaction->cancel_hooks);
2334 bus_transaction_new (BusContext *context)
2336 BusTransaction *transaction;
2338 transaction = dbus_new0 (BusTransaction, 1);
2339 if (transaction == NULL)
2342 transaction->context = context;
2348 bus_transaction_get_context (BusTransaction *transaction)
2350 return transaction->context;
2354 * Reserve enough memory to capture the given message if the
2355 * transaction goes through.
2358 bus_transaction_capture (BusTransaction *transaction,
2359 DBusConnection *sender,
2360 DBusConnection *addressed_recipient,
2361 DBusMessage *message)
2363 BusConnections *connections;
2366 DBusList *recipients = NULL;
2367 dbus_bool_t ret = FALSE;
2369 connections = bus_context_get_connections (transaction->context);
2371 /* shortcut: don't compose the message unless someone wants it */
2372 if (connections->monitors == NULL)
2375 mm = connections->monitor_matchmaker;
2376 /* This is non-null if there has ever been a monitor - we don't GC it.
2377 * There's little point, since there is up to 1 per process. */
2378 _dbus_assert (mm != NULL);
2380 if (!bus_matchmaker_get_recipients (mm, connections, sender,
2381 addressed_recipient, message, &recipients))
2384 for (link = _dbus_list_get_first_link (&recipients);
2386 link = _dbus_list_get_next_link (&recipients, link))
2388 DBusConnection *recipient = link->data;
2390 if (!bus_transaction_send (transaction, recipient, message, FALSE))
2397 _dbus_list_clear (&recipients);
2402 bus_transaction_capture_error_reply (BusTransaction *transaction,
2403 DBusConnection *addressed_recipient,
2404 const DBusError *error,
2405 DBusMessage *in_reply_to)
2407 BusConnections *connections;
2409 dbus_bool_t ret = FALSE;
2411 _dbus_assert (error != NULL);
2412 _DBUS_ASSERT_ERROR_IS_SET (error);
2414 connections = bus_context_get_connections (transaction->context);
2416 /* shortcut: don't compose the message unless someone wants it */
2417 if (connections->monitors == NULL)
2420 reply = dbus_message_new_error (in_reply_to,
2427 if (!dbus_message_set_sender (reply, DBUS_SERVICE_DBUS))
2430 ret = bus_transaction_capture (transaction, NULL, addressed_recipient, reply);
2433 dbus_message_unref (reply);
2438 bus_transaction_send_from_driver (BusTransaction *transaction,
2439 DBusConnection *connection,
2440 DBusMessage *message)
2442 DBusError error = DBUS_ERROR_INIT;
2443 BusDeferredMessage *deferred_message = NULL;
2445 /* We have to set the sender to the driver, and have
2446 * to check security policy since it was not done in
2449 _dbus_verbose ("Sending %s %s %s from driver\n",
2450 dbus_message_get_interface (message) ?
2451 dbus_message_get_interface (message) : "(no interface)",
2452 dbus_message_get_member (message) ?
2453 dbus_message_get_member (message) : "(no member)",
2454 dbus_message_get_error_name (message) ?
2455 dbus_message_get_error_name (message) : "(no error name)");
2457 if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
2460 if (bus_connection_is_active (connection))
2462 if (!dbus_message_set_destination (message,
2463 bus_connection_get_name (connection)))
2467 /* bus driver never wants a reply */
2468 dbus_message_set_no_reply (message, TRUE);
2470 /* Capture it for monitors, even if the real recipient's receive policy
2471 * does not allow it to receive this message from us (which would be odd).
2473 if (!bus_transaction_capture (transaction, NULL, connection, message))
2476 /* If security policy doesn't allow the message, we would silently
2477 * eat it; the driver doesn't care about getting a reply. However,
2478 * if we're actively capturing messages, it's nice to log that we
2479 * tried to send it and did not allow ourselves to do so.
2481 switch (bus_context_check_security_policy (bus_transaction_get_context (transaction),
2483 NULL, connection, connection,
2484 message, NULL, &error,
2487 case BUS_RESULT_TRUE:
2489 case BUS_RESULT_FALSE:
2490 if (!bus_transaction_capture_error_reply (transaction, connection,
2493 bus_context_log (transaction->context, DBUS_SYSTEM_LOG_WARNING,
2494 "message from dbus-daemon rejected but not enough "
2495 "memory to capture it");
2498 /* This is not fatal to the transaction so silently eat the disallowed
2499 * message (see reasoning above) */
2500 dbus_error_free (&error);
2503 case BUS_RESULT_LATER:
2504 if (!bus_deferred_message_queue_at_recipient(deferred_message, transaction, FALSE, FALSE))
2506 return TRUE; /* pretend to have sent it */
2509 return bus_transaction_send (transaction, connection, message, FALSE);
2513 bus_transaction_send (BusTransaction *transaction,
2514 DBusConnection *connection,
2515 DBusMessage *message,
2516 dbus_bool_t deferred_dispatch)
2518 MessageToSend *to_send;
2519 BusConnectionData *d;
2522 _dbus_verbose (" trying to add %s interface=%s member=%s error=%s to transaction%s\n",
2523 dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR ? "error" :
2524 dbus_message_get_reply_serial (message) != 0 ? "reply" :
2526 dbus_message_get_interface (message) ?
2527 dbus_message_get_interface (message) : "(unset)",
2528 dbus_message_get_member (message) ?
2529 dbus_message_get_member (message) : "(unset)",
2530 dbus_message_get_error_name (message) ?
2531 dbus_message_get_error_name (message) : "(unset)",
2532 dbus_connection_get_is_connected (connection) ?
2533 "" : " (disconnected)");
2535 _dbus_assert (dbus_message_get_sender (message) != NULL);
2537 if (!dbus_connection_get_is_connected (connection))
2538 return TRUE; /* silently ignore disconnected connections */
2540 d = BUS_CONNECTION_DATA (connection);
2541 _dbus_assert (d != NULL);
2543 if (!deferred_dispatch && d->deferred_messages != NULL)
2545 BusDeferredMessage *deferred_message;
2546 dbus_bool_t success;
2547 /* sender and addressed recipient are not required at this point as we only need to send message
2548 * to a single recipient without performing policy check. */
2549 deferred_message = bus_deferred_message_new (message,
2554 if (deferred_message == NULL)
2557 success = bus_deferred_message_queue_at_recipient(deferred_message, transaction,
2559 bus_deferred_message_unref(deferred_message);
2564 to_send = dbus_new (MessageToSend, 1);
2565 if (to_send == NULL)
2570 to_send->preallocated = dbus_connection_preallocate_send (connection);
2571 if (to_send->preallocated == NULL)
2573 dbus_free (to_send);
2577 dbus_message_ref (message);
2578 to_send->message = message;
2579 to_send->transaction = transaction;
2581 _dbus_verbose ("about to prepend message\n");
2583 if (!_dbus_list_prepend (&d->transaction_messages, to_send))
2585 message_to_send_free (connection, to_send);
2589 _dbus_verbose ("prepended message\n");
2591 /* See if we already had this connection in the list
2592 * for this transaction. If we have a pending message,
2593 * then we should already be in transaction->connections
2595 link = _dbus_list_get_first_link (&d->transaction_messages);
2596 _dbus_assert (link->data == to_send);
2597 link = _dbus_list_get_next_link (&d->transaction_messages, link);
2598 while (link != NULL)
2600 MessageToSend *m = link->data;
2601 DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
2603 if (m->transaction == transaction)
2611 if (!_dbus_list_prepend (&transaction->connections, connection))
2613 _dbus_list_remove (&d->transaction_messages, to_send);
2614 message_to_send_free (connection, to_send);
2623 transaction_free (BusTransaction *transaction)
2625 _dbus_assert (transaction->connections == NULL);
2627 free_cancel_hooks (transaction);
2629 dbus_free (transaction);
2633 connection_cancel_transaction (DBusConnection *connection,
2634 BusTransaction *transaction)
2637 BusConnectionData *d;
2639 d = BUS_CONNECTION_DATA (connection);
2640 _dbus_assert (d != NULL);
2642 link = _dbus_list_get_first_link (&d->transaction_messages);
2643 while (link != NULL)
2645 MessageToSend *m = link->data;
2646 DBusList *next = _dbus_list_get_next_link (&d->transaction_messages, link);
2648 if (m->transaction == transaction)
2650 _dbus_list_remove_link (&d->transaction_messages,
2653 message_to_send_free (connection, m);
2661 bus_transaction_cancel_and_free (BusTransaction *transaction)
2663 DBusConnection *connection;
2665 _dbus_verbose ("TRANSACTION: cancelled\n");
2667 while ((connection = _dbus_list_pop_first (&transaction->connections)))
2668 connection_cancel_transaction (connection, transaction);
2670 _dbus_list_foreach (&transaction->cancel_hooks,
2671 cancel_hook_cancel, NULL);
2673 transaction_free (transaction);
2677 connection_execute_transaction (DBusConnection *connection,
2678 BusTransaction *transaction)
2681 BusConnectionData *d;
2683 d = BUS_CONNECTION_DATA (connection);
2684 _dbus_assert (d != NULL);
2686 /* Send the queue in order (FIFO) */
2687 link = _dbus_list_get_last_link (&d->transaction_messages);
2688 while (link != NULL)
2690 MessageToSend *m = link->data;
2691 DBusList *prev = _dbus_list_get_prev_link (&d->transaction_messages, link);
2693 if (m->transaction == transaction)
2695 _dbus_list_remove_link (&d->transaction_messages,
2698 _dbus_assert (dbus_message_get_sender (m->message) != NULL);
2700 dbus_connection_send_preallocated (connection,
2705 m->preallocated = NULL; /* so we don't double-free it */
2707 message_to_send_free (connection, m);
2715 bus_transaction_execute_and_free (BusTransaction *transaction)
2717 /* For each connection in transaction->connections
2720 DBusConnection *connection;
2722 _dbus_verbose ("TRANSACTION: executing\n");
2724 while ((connection = _dbus_list_pop_first (&transaction->connections)))
2725 connection_execute_transaction (connection, transaction);
2727 transaction_free (transaction);
2731 bus_connection_remove_transactions (DBusConnection *connection)
2733 MessageToSend *to_send;
2734 BusConnectionData *d;
2736 d = BUS_CONNECTION_DATA (connection);
2737 _dbus_assert (d != NULL);
2739 while ((to_send = _dbus_list_get_first (&d->transaction_messages)))
2741 /* only has an effect for the first MessageToSend listing this transaction */
2742 _dbus_list_remove (&to_send->transaction->connections,
2745 _dbus_list_remove (&d->transaction_messages, to_send);
2746 message_to_send_free (connection, to_send);
2751 * Converts the DBusError to a message reply
2754 bus_transaction_send_error_reply (BusTransaction *transaction,
2755 DBusConnection *connection,
2756 const DBusError *error,
2757 DBusMessage *in_reply_to)
2761 _dbus_assert (error != NULL);
2762 _DBUS_ASSERT_ERROR_IS_SET (error);
2764 _dbus_verbose ("Sending error reply %s \"%s\"\n",
2765 error->name, error->message);
2767 reply = dbus_message_new_error (in_reply_to,
2773 if (!bus_transaction_send_from_driver (transaction, connection, reply))
2775 dbus_message_unref (reply);
2779 dbus_message_unref (reply);
2785 bus_transaction_add_cancel_hook (BusTransaction *transaction,
2786 BusTransactionCancelFunction cancel_function,
2788 DBusFreeFunction free_data_function)
2792 ch = dbus_new (CancelHook, 1);
2796 _dbus_verbose (" adding cancel hook function = %p data = %p\n",
2797 cancel_function, data);
2799 ch->cancel_function = cancel_function;
2801 ch->free_data_function = free_data_function;
2803 /* It's important that the hooks get run in reverse order that they
2806 if (!_dbus_list_prepend (&transaction->cancel_hooks, ch))
2816 bus_connection_dispatch_deferred (DBusConnection *connection)
2818 BusDeferredMessage *message;
2820 _dbus_return_if_fail (connection != NULL);
2822 while ((message = bus_connection_pop_deferred_message(connection)) != NULL)
2824 bus_deferred_message_dispatch(message);
2825 bus_deferred_message_unref(message);
2830 bus_connection_has_deferred_messages (DBusConnection *connection)
2832 BusConnectionData *d = BUS_CONNECTION_DATA(connection);
2834 _dbus_assert (d != NULL);
2836 return d->deferred_messages != NULL ? TRUE : FALSE;
2840 bus_connection_queue_deferred_message (DBusConnection *connection,
2841 BusDeferredMessage *message,
2842 dbus_bool_t prepend)
2844 BusConnectionData *d = BUS_CONNECTION_DATA(connection);
2845 dbus_bool_t success;
2847 _dbus_assert (d != NULL);
2850 success = _dbus_list_prepend(&d->deferred_messages, message);
2852 success = _dbus_list_append(&d->deferred_messages, message);
2856 bus_deferred_message_ref(message);
2863 BusDeferredMessage *
2864 bus_connection_pop_deferred_message (DBusConnection *connection)
2867 BusDeferredMessage *message;
2868 BusConnectionData *d = BUS_CONNECTION_DATA(connection);
2870 _dbus_assert (d != NULL);
2872 link =_dbus_list_get_first_link(&d->deferred_messages);
2875 message = link->data;
2876 if (!bus_deferred_message_waits_for_check(message))
2878 _dbus_list_remove_link(&d->deferred_messages, link);
2887 bus_connection_putback_deferred_message (DBusConnection *connection, BusDeferredMessage *message)
2889 BusConnectionData *d = BUS_CONNECTION_DATA(connection);
2891 _dbus_assert (d != NULL);
2893 if (_dbus_list_prepend(&d->deferred_messages, message))
2901 bus_connection_clear_deferred_messages (DBusConnection *connection)
2903 BusConnectionData *d = BUS_CONNECTION_DATA(connection);
2906 BusDeferredMessage *message;
2908 _dbus_assert (d != NULL);
2910 link =_dbus_list_get_first_link(&d->deferred_messages);
2911 while (link != NULL)
2913 next = _dbus_list_get_next_link (&d->deferred_messages, link);
2914 message = link->data;
2916 bus_deferred_message_unref(message);
2917 _dbus_list_remove_link(&d->deferred_messages, link);
2924 bus_connection_remove_deferred_message (DBusConnection *connection,
2925 BusDeferredMessage *message)
2927 BusConnectionData *d = BUS_CONNECTION_DATA(connection);
2929 _dbus_assert (d != NULL);
2931 if (_dbus_list_remove(&d->deferred_messages, message))
2932 bus_deferred_message_unref(message);
2936 bus_connections_get_n_active (BusConnections *connections)
2938 return connections->n_completed;
2942 bus_connections_get_n_incomplete (BusConnections *connections)
2944 return connections->n_incomplete;
2947 #ifdef DBUS_ENABLE_STATS
2949 bus_connections_get_total_match_rules (BusConnections *connections)
2951 return connections->total_match_rules;
2955 bus_connections_get_peak_match_rules (BusConnections *connections)
2957 return connections->peak_match_rules;
2961 bus_connections_get_peak_match_rules_per_conn (BusConnections *connections)
2963 return connections->peak_match_rules_per_conn;
2967 bus_connections_get_total_bus_names (BusConnections *connections)
2969 return connections->total_bus_names;
2973 bus_connections_get_peak_bus_names (BusConnections *connections)
2975 return connections->peak_bus_names;
2979 bus_connections_get_peak_bus_names_per_conn (BusConnections *connections)
2981 return connections->peak_bus_names_per_conn;
2985 bus_connection_get_peak_match_rules (DBusConnection *connection)
2987 BusConnectionData *d;
2989 d = BUS_CONNECTION_DATA (connection);
2990 _dbus_assert(d != NULL);
2992 return d->peak_match_rules;
2996 bus_connection_get_peak_bus_names (DBusConnection *connection)
2998 BusConnectionData *d;
3000 d = BUS_CONNECTION_DATA (connection);
3001 _dbus_assert(d != NULL);
3003 return d->peak_bus_names;
3006 int bus_connection_get_n_pending_replies (DBusConnection *connection)
3008 BusConnectionData *d;
3010 BusPendingReply *pending;
3013 d = BUS_CONNECTION_DATA (connection);
3014 _dbus_assert(d != NULL);
3016 link = bus_expire_list_get_first_link(d->connections->pending_replies);
3017 while (link != NULL)
3019 pending = link->data;
3020 link = bus_expire_list_get_next_link(d->connections->pending_replies,
3022 if (pending->will_get_reply == connection)
3030 bus_connection_get_peak_pending_replies (DBusConnection *connection)
3032 BusConnectionData *d;
3034 d = BUS_CONNECTION_DATA (connection);
3035 _dbus_assert (d != NULL);
3037 return d->peak_pending_replies;
3039 #endif /* DBUS_ENABLE_STATS */
3042 bus_connection_is_monitor (DBusConnection *connection)
3044 BusConnectionData *d;
3046 d = BUS_CONNECTION_DATA (connection);
3047 _dbus_assert(d != NULL);
3049 return d->link_in_monitors != NULL;
3053 bcd_add_monitor_rules (BusConnectionData *d,
3054 DBusConnection *connection,
3057 BusMatchmaker *mm = d->connections->monitor_matchmaker;
3062 mm = bus_matchmaker_new ();
3067 d->connections->monitor_matchmaker = mm;
3070 for (iter = _dbus_list_get_first_link (rules);
3072 iter = _dbus_list_get_next_link (rules, iter))
3074 if (!bus_matchmaker_add_rule (mm, iter->data))
3076 bus_matchmaker_disconnected (mm, connection);
3085 bcd_drop_monitor_rules (BusConnectionData *d,
3086 DBusConnection *connection)
3088 BusMatchmaker *mm = d->connections->monitor_matchmaker;
3091 bus_matchmaker_disconnected (mm, connection);
3095 bus_connection_be_monitor (DBusConnection *connection,
3096 BusTransaction *transaction,
3100 BusConnectionData *d;
3105 d = BUS_CONNECTION_DATA (connection);
3106 _dbus_assert (d != NULL);
3108 link = _dbus_list_alloc_link (connection);
3112 BUS_SET_OOM (error);
3116 if (!bcd_add_monitor_rules (d, connection, rules))
3118 _dbus_list_free_link (link);
3119 BUS_SET_OOM (error);
3123 /* release all its names */
3124 if (!_dbus_list_copy (&d->services_owned, &tmp))
3126 bcd_drop_monitor_rules (d, connection);
3127 _dbus_list_free_link (link);
3128 BUS_SET_OOM (error);
3132 for (iter = _dbus_list_get_first_link (&tmp);
3134 iter = _dbus_list_get_next_link (&tmp, iter))
3136 BusService *service = iter->data;
3138 /* This call is transactional: if there isn't enough memory to
3139 * do everything, then the service gets all its names back when
3140 * the transaction is cancelled due to OOM. */
3141 if (!bus_service_remove_owner (service, connection, transaction, error))
3143 bcd_drop_monitor_rules (d, connection);
3144 _dbus_list_free_link (link);
3145 _dbus_list_clear (&tmp);
3150 /* We have now done everything that can fail, so there is no problem
3151 * with doing the irrevocable stuff. */
3153 _dbus_list_clear (&tmp);
3155 bus_context_log (transaction->context, DBUS_SYSTEM_LOG_INFO,
3156 "Connection %s (%s) became a monitor.", d->name,
3157 d->cached_loginfo_string);
3159 if (d->n_match_rules > 0)
3163 mm = bus_context_get_matchmaker (d->connections->context);
3164 bus_matchmaker_disconnected (mm, connection);
3167 /* flag it as a monitor */
3168 d->link_in_monitors = link;
3169 _dbus_list_append_link (&d->connections->monitors, link);
3171 /* it isn't allowed to reply, and it is no longer relevant whether it
3172 * receives replies */
3173 bus_connection_drop_pending_replies (d->connections, connection);