[daemon-dev][lib-opt] Fix in freeing memory, cleanup, comments, renames
[platform/upstream/dbus.git] / bus / connection.c
index 512a231..1f2c955 100644 (file)
@@ -2,6 +2,7 @@
 /* connection.c  Client connections
  *
  * Copyright (C) 2003  Red Hat, Inc.
+ * Copyright (C) 2013  Samsung Electronics
  *
  * Licensed under the Academic Free License version 2.1
  * 
  * 
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
+
+#include <config.h>
 #include "connection.h"
 #include "dispatch.h"
 #include "policy.h"
@@ -32,6 +35,9 @@
 #include <dbus/dbus-hash.h>
 #include <dbus/dbus-timeout.h>
 
+/* Trim executed commands to this length; we want to keep logs readable */
+#define MAX_LOG_COMMAND_LEN 50
+
 static void bus_connection_remove_transactions (DBusConnection *connection);
 
 typedef struct
@@ -57,6 +63,16 @@ struct BusConnections
   DBusTimeout *expire_timeout; /**< Timeout for expiring incomplete connections. */
   int stamp;                   /**< Incrementing number */
   BusExpireList *pending_replies; /**< List of pending replies */
+
+#ifdef DBUS_ENABLE_STATS
+  int total_match_rules;
+  int peak_match_rules;
+  int peak_match_rules_per_conn;
+
+  int total_bus_names;
+  int peak_bus_names;
+  int peak_bus_names_per_conn;
+#endif
 };
 
 static dbus_int32_t connection_data_slot = -1;
@@ -76,11 +92,17 @@ typedef struct
   DBusPreallocatedSend *oom_preallocated;
   BusClientPolicy *policy;
 
+  char *cached_loginfo_string;
   BusSELinuxID *selinux_id;
 
   long connection_tv_sec;  /**< Time when we connected (seconds component) */
   long connection_tv_usec; /**< Time when we connected (microsec component) */
   int stamp;               /**< connections->stamp last time we were traversed */
+
+#ifdef DBUS_ENABLE_STATS
+  int peak_match_rules;
+  int peak_bus_names;
+#endif
 } BusConnectionData;
 
 static dbus_bool_t bus_pending_reply_expired (BusExpireList *list,
@@ -114,7 +136,7 @@ get_connections_for_uid (BusConnections *connections,
 
   /* val is NULL is 0 when it isn't in the hash yet */
   
-  val = _dbus_hash_table_lookup_ulong (connections->completed_by_user,
+  val = _dbus_hash_table_lookup_uintptr (connections->completed_by_user,
                                        uid);
 
   current_count = _DBUS_POINTER_TO_INT (val);
@@ -143,14 +165,14 @@ adjust_connections_for_uid (BusConnections *connections,
 
   if (current_count == 0)
     {
-      _dbus_hash_table_remove_ulong (connections->completed_by_user, uid);
+      _dbus_hash_table_remove_uintptr (connections->completed_by_user, uid);
       return TRUE;
     }
   else
     {
       dbus_bool_t retval;
       
-      retval = _dbus_hash_table_insert_ulong (connections->completed_by_user,
+      retval = _dbus_hash_table_insert_uintptr (connections->completed_by_user,
                                               uid, _DBUS_INT_TO_POINTER (current_count));
 
       /* only positive adjustment can fail as otherwise
@@ -169,6 +191,9 @@ bus_connection_disconnected (DBusConnection *connection)
   BusConnectionData *d;
   BusService *service;
   BusMatchmaker *matchmaker;
+#ifdef ENABLE_KDBUS_TRANSPORT
+  dbus_bool_t is_phantom = FALSE;
+#endif
   
   d = BUS_CONNECTION_DATA (connection);
   _dbus_assert (d != NULL);
@@ -176,6 +201,11 @@ bus_connection_disconnected (DBusConnection *connection)
   _dbus_verbose ("%s disconnected, dropping all service ownership and releasing\n",
                  d->name ? d->name : "(inactive)");
 
+#ifdef ENABLE_KDBUS_TRANSPORT
+  if(bus_context_is_kdbus(d->connections->context) && (strcmp(bus_connection_get_name(connection), ":1.1")))
+      is_phantom = TRUE;
+#endif
+
   /* Delete our match rules */
   if (d->n_match_rules > 0)
     {
@@ -284,24 +314,13 @@ bus_connection_disconnected (DBusConnection *connection)
   dbus_connection_set_data (connection,
                             connection_data_slot,
                             NULL, NULL);
-  
-  dbus_connection_unref (connection);
-}
 
-static dbus_bool_t
-connection_watch_callback (DBusWatch     *watch,
-                           unsigned int   condition,
-                           void          *data)
-{
- /* FIXME this can be done in dbus-mainloop.c
-  * if the code in activation.c for the babysitter
-  * watch handler is fixed.
-  */
-  
-#if 0
-  _dbus_verbose ("Calling handle_watch\n");
+#ifdef ENABLE_KDBUS_TRANSPORT
+  if(is_phantom)
+      dbus_connection_unref_phantom(connection);
+  else
 #endif
-  return dbus_watch_handle (watch, condition);
+      dbus_connection_unref (connection);
 }
 
 static dbus_bool_t
@@ -310,9 +329,7 @@ add_connection_watch (DBusWatch      *watch,
 {
   DBusConnection *connection = data;
 
-  return _dbus_loop_add_watch (connection_get_loop (connection),
-                               watch, connection_watch_callback, connection,
-                               NULL);
+  return _dbus_loop_add_watch (connection_get_loop (connection), watch);
 }
 
 static void
@@ -321,18 +338,16 @@ remove_connection_watch (DBusWatch      *watch,
 {
   DBusConnection *connection = data;
   
-  _dbus_loop_remove_watch (connection_get_loop (connection),
-                           watch, connection_watch_callback, connection);
+  _dbus_loop_remove_watch (connection_get_loop (connection), watch);
 }
 
 static void
-connection_timeout_callback (DBusTimeout   *timeout,
-                             void          *data)
+toggle_connection_watch (DBusWatch      *watch,
+                         void           *data)
 {
-  /* DBusConnection *connection = data; */
+  DBusConnection *connection = data;
 
-  /* can return FALSE on OOM but we just let it fire again later */
-  dbus_timeout_handle (timeout);
+  _dbus_loop_toggle_watch (connection_get_loop (connection), watch);
 }
 
 static dbus_bool_t
@@ -341,8 +356,7 @@ add_connection_timeout (DBusTimeout    *timeout,
 {
   DBusConnection *connection = data;
   
-  return _dbus_loop_add_timeout (connection_get_loop (connection),
-                                 timeout, connection_timeout_callback, connection, NULL);
+  return _dbus_loop_add_timeout (connection_get_loop (connection), timeout);
 }
 
 static void
@@ -351,8 +365,7 @@ remove_connection_timeout (DBusTimeout    *timeout,
 {
   DBusConnection *connection = data;
   
-  _dbus_loop_remove_timeout (connection_get_loop (connection),
-                             timeout, connection_timeout_callback, connection);
+  _dbus_loop_remove_timeout (connection_get_loop (connection), timeout);
 }
 
 static void
@@ -406,19 +419,13 @@ free_connection_data (void *data)
   if (d->selinux_id)
     bus_selinux_id_unref (d->selinux_id);
   
+  dbus_free (d->cached_loginfo_string);
+  
   dbus_free (d->name);
   
   dbus_free (d);
 }
 
-static void
-call_timeout_callback (DBusTimeout   *timeout,
-                       void          *data)
-{
-  /* can return FALSE on OOM but we just let it fire again later */
-  dbus_timeout_handle (timeout);
-}
-
 BusConnections*
 bus_connections_new (BusContext *context)
 {
@@ -431,7 +438,7 @@ bus_connections_new (BusContext *context)
   if (connections == NULL)
     goto failed_1;
 
-  connections->completed_by_user = _dbus_hash_table_new (DBUS_HASH_ULONG,
+  connections->completed_by_user = _dbus_hash_table_new (DBUS_HASH_UINTPTR,
                                                          NULL, NULL);
   if (connections->completed_by_user == NULL)
     goto failed_2;
@@ -452,8 +459,7 @@ bus_connections_new (BusContext *context)
     goto failed_4;
   
   if (!_dbus_loop_add_timeout (bus_context_get_loop (context),
-                               connections->expire_timeout,
-                               call_timeout_callback, NULL, NULL))
+                               connections->expire_timeout))
     goto failed_5;
   
   connections->refcount = 1;
@@ -524,8 +530,7 @@ bus_connections_unref (BusConnections *connections)
       bus_expire_list_free (connections->pending_replies);
       
       _dbus_loop_remove_timeout (bus_context_get_loop (connections->context),
-                                 connections->expire_timeout,
-                                 call_timeout_callback, NULL);
+                                 connections->expire_timeout);
       
       _dbus_timeout_unref (connections->expire_timeout);
       
@@ -537,13 +542,75 @@ bus_connections_unref (BusConnections *connections)
     }
 }
 
+/* Used for logging */
+static dbus_bool_t
+cache_peer_loginfo_string (BusConnectionData *d, 
+                           DBusConnection    *connection)
+{
+  DBusString loginfo_buf;
+  unsigned long uid;
+  unsigned long pid;
+  char *windows_sid;
+  dbus_bool_t prev_added;
+
+  if (!_dbus_string_init (&loginfo_buf))
+    return FALSE;
+  
+  prev_added = FALSE;
+  if (dbus_connection_get_unix_user (connection, &uid))
+    {
+      if (!_dbus_string_append_printf (&loginfo_buf, "uid=%ld", uid))
+        goto oom;
+      else
+        prev_added = TRUE;
+    }
+
+  if (dbus_connection_get_unix_process_id (connection, &pid))
+    {
+      if (prev_added)
+        {
+          if (!_dbus_string_append_byte (&loginfo_buf, ' '))
+            goto oom;
+        }
+      if (!_dbus_string_append_printf (&loginfo_buf, "pid=%ld comm=\"", pid))
+        goto oom;
+      /* Ignore errors here; we may not have permissions to read the
+       * proc file. */
+      _dbus_command_for_pid (pid, &loginfo_buf, MAX_LOG_COMMAND_LEN, NULL);
+      if (!_dbus_string_append_byte (&loginfo_buf, '"'))
+        goto oom;
+    }
+
+  if (dbus_connection_get_windows_user (connection, &windows_sid))
+    {
+      dbus_bool_t did_append;
+      did_append = _dbus_string_append_printf (&loginfo_buf,
+                                               "sid=\"%s\" ", windows_sid);
+      dbus_free (windows_sid);
+      if (!did_append)
+        goto oom;
+    }
+
+  if (!_dbus_string_steal_data (&loginfo_buf, &(d->cached_loginfo_string)))
+    goto oom;
+
+  _dbus_string_free (&loginfo_buf); 
+
+  return TRUE;
+oom:
+   _dbus_string_free (&loginfo_buf);
+   return FALSE;
+}
+
 dbus_bool_t
 bus_connections_setup_connection (BusConnections *connections,
                                   DBusConnection *connection)
 {
+
   BusConnectionData *d;
   dbus_bool_t retval;
   DBusError error;
+
   
   d = dbus_new0 (BusConnectionData, 1);
   
@@ -553,8 +620,8 @@ bus_connections_setup_connection (BusConnections *connections,
   d->connections = connections;
   d->connection = connection;
   
-  _dbus_get_current_time (&d->connection_tv_sec,
-                          &d->connection_tv_usec);
+  _dbus_get_monotonic_time (&d->connection_tv_sec,
+                            &d->connection_tv_usec);
   
   _dbus_assert (connection_data_slot >= 0);
   
@@ -583,11 +650,11 @@ bus_connections_setup_connection (BusConnections *connections,
       dbus_error_free (&error);
       goto out;
     }
-  
+
   if (!dbus_connection_set_watch_functions (connection,
                                             add_connection_watch,
                                             remove_connection_watch,
-                                            NULL,
+                                            toggle_connection_watch,
                                             connection,
                                             NULL))
     goto out;
@@ -723,7 +790,7 @@ bus_connections_expire_incomplete (BusConnections *connections)
       DBusList *link;
       int auth_timeout;
       
-      _dbus_get_current_time (&tv_sec, &tv_usec);
+      _dbus_get_monotonic_time (&tv_sec, &tv_usec);
       auth_timeout = bus_context_get_auth_timeout (connections->context);
   
       link = _dbus_list_get_first_link (&connections->incomplete);
@@ -772,7 +839,7 @@ expire_incomplete_timeout (void *data)
 {
   BusConnections *connections = data;
 
-  _dbus_verbose ("Running %s\n", _DBUS_FUNCTION_NAME);
+  _dbus_verbose ("Running\n");
   
   /* note that this may remove the timeout */
   bus_connections_expire_incomplete (connections);
@@ -786,12 +853,7 @@ bus_connection_get_unix_groups  (DBusConnection   *connection,
                                  int              *n_groups,
                                  DBusError        *error)
 {
-  BusConnectionData *d;
   unsigned long uid;
-  
-  d = BUS_CONNECTION_DATA (connection);
-
-  _dbus_assert (d != NULL);
 
   *groups = NULL;
   *n_groups = 0;
@@ -842,6 +904,18 @@ bus_connection_is_in_unix_group (DBusConnection *connection,
   return FALSE;
 }
 
+const char *
+bus_connection_get_loginfo (DBusConnection        *connection)
+{
+  BusConnectionData *d;
+    
+  d = BUS_CONNECTION_DATA (connection);
+
+  if (!bus_connection_is_active (connection))
+    return "inactive";
+  return d->cached_loginfo_string;  
+}
+
 BusClientPolicy*
 bus_connection_get_policy (DBusConnection *connection)
 {
@@ -935,6 +1009,28 @@ bus_connections_foreach (BusConnections               *connections,
   foreach_inactive (connections, function, data);
 }
 
+#ifdef ENABLE_KDBUS_TRANSPORT
+DBusConnection*
+bus_connections_find_conn_by_name(BusConnections *connections, const char* name)
+{
+    DBusList *link;
+
+    link = _dbus_list_get_first_link (&connections->completed);
+    while (link != NULL)
+      {
+        DBusConnection *connection = link->data;
+        DBusList *next = _dbus_list_get_next_link (&connections->completed, link);
+
+        if (!strcmp(bus_connection_get_name(connection), name))
+          return connection;
+
+        link = next;
+      }
+
+    return NULL;
+}
+#endif
+
 BusContext*
 bus_connections_get_context (BusConnections *connections)
 {
@@ -1142,6 +1238,16 @@ bus_connection_send_oom_error (DBusConnection *connection,
   d->oom_preallocated = NULL;
 }
 
+#ifdef DBUS_ENABLE_STATS
+static void
+update_peak (int *peak,
+             int n)
+{
+  if (*peak < n)
+    *peak = n;
+}
+#endif
+
 void
 bus_connection_add_match_rule_link (DBusConnection *connection,
                                     DBusList       *link)
@@ -1154,6 +1260,15 @@ bus_connection_add_match_rule_link (DBusConnection *connection,
   _dbus_list_append_link (&d->match_rules, link);
 
   d->n_match_rules += 1;
+
+#ifdef DBUS_ENABLE_STATS
+  update_peak (&d->peak_match_rules, d->n_match_rules);
+  update_peak (&d->connections->peak_match_rules_per_conn, d->n_match_rules);
+
+  d->connections->total_match_rules += 1;
+  update_peak (&d->connections->peak_match_rules,
+               d->connections->total_match_rules);
+#endif
 }
 
 dbus_bool_t
@@ -1185,6 +1300,10 @@ bus_connection_remove_match_rule (DBusConnection *connection,
 
   d->n_match_rules -= 1;
   _dbus_assert (d->n_match_rules >= 0);
+
+#ifdef DBUS_ENABLE_STATS
+  d->connections->total_match_rules -= 1;
+#endif
 }
 
 int
@@ -1210,6 +1329,16 @@ bus_connection_add_owned_service_link (DBusConnection *connection,
   _dbus_list_append_link (&d->services_owned, link);
 
   d->n_services_owned += 1;
+
+#ifdef DBUS_ENABLE_STATS
+  update_peak (&d->peak_bus_names, d->n_services_owned);
+  update_peak (&d->connections->peak_bus_names_per_conn,
+               d->n_services_owned);
+
+  d->connections->total_bus_names += 1;
+  update_peak (&d->connections->peak_bus_names,
+               d->connections->total_bus_names);
+#endif
 }
 
 dbus_bool_t
@@ -1241,6 +1370,10 @@ bus_connection_remove_owned_service (DBusConnection *connection,
 
   d->n_services_owned -= 1;
   _dbus_assert (d->n_services_owned >= 0);
+
+#ifdef DBUS_ENABLE_STATS
+  d->connections->total_bus_names -= 1;
+#endif
 }
 
 int
@@ -1254,6 +1387,18 @@ bus_connection_get_n_services_owned (DBusConnection *connection)
   return d->n_services_owned;
 }
 
+#ifdef ENABLE_KDBUS_TRANSPORT
+DBusList**
+bus_connection_get_services_owned (DBusConnection *connection)
+{
+    BusConnectionData *d;
+    d = BUS_CONNECTION_DATA (connection);
+    _dbus_assert (d != NULL);
+
+    return &d->services_owned;
+}
+#endif
+
 dbus_bool_t
 bus_connection_complete (DBusConnection   *connection,
                         const DBusString *name,
@@ -1302,16 +1447,15 @@ bus_connection_complete (DBusConnection   *connection,
     {
       if (!adjust_connections_for_uid (d->connections,
                                        uid, 1))
-        {
-          BUS_SET_OOM (error);
-          dbus_free (d->name);
-          d->name = NULL;
-          bus_client_policy_unref (d->policy);
-          d->policy = NULL;
-          return FALSE;
-        }
+        goto fail;
     }
-  
+
+  /* Create and cache a string which holds information about the 
+   * peer process; used for logging purposes.
+   */
+  if (!cache_peer_loginfo_string (d, connection))
+    goto fail;
+
   /* Now the connection is active, move it between lists */
   _dbus_list_unlink (&d->connections->incomplete,
                      d->link_in_connection_list);
@@ -1329,6 +1473,14 @@ bus_connection_complete (DBusConnection   *connection,
   _dbus_assert (bus_connection_is_active (connection));
   
   return TRUE;
+fail:
+  BUS_SET_OOM (error);
+  dbus_free (d->name);
+  d->name = NULL;
+  if (d->policy)
+    bus_client_policy_unref (d->policy);
+  d->policy = NULL;
+  return FALSE;
 }
 
 const char *
@@ -1351,13 +1503,7 @@ bus_connections_check_limits (BusConnections  *connections,
                               DBusConnection  *requesting_completion,
                               DBusError       *error)
 {
-  BusConnectionData *d;
   unsigned long uid;
-  
-  d = BUS_CONNECTION_DATA (requesting_completion);
-  _dbus_assert (d != NULL);
-
-  _dbus_assert (d->name == NULL);
 
   if (connections->n_completed >=
       bus_context_get_max_completed_connections (connections->context))
@@ -1467,9 +1613,9 @@ bus_pending_reply_expired (BusExpireList *list,
       bus_transaction_cancel_and_free (transaction);
       return FALSE;
     }
-  
-  _dbus_list_remove_link (&connections->pending_replies->items,
-                          link);
+
+  bus_expire_list_remove_link (connections->pending_replies, link);
+
   bus_pending_reply_free (pending);
   bus_transaction_execute_and_free (transaction);
 
@@ -1488,14 +1634,14 @@ bus_connection_drop_pending_replies (BusConnections  *connections,
   _dbus_verbose ("Dropping pending replies that involve connection %p\n",
                  connection);
   
-  link = _dbus_list_get_first_link (&connections->pending_replies->items);
+  link = bus_expire_list_get_first_link (connections->pending_replies);
   while (link != NULL)
     {
       DBusList *next;
       BusPendingReply *pending;
 
-      next = _dbus_list_get_next_link (&connections->pending_replies->items,
-                                       link);
+      next = bus_expire_list_get_next_link (connections->pending_replies,
+                                            link);
       pending = link->data;
 
       if (pending->will_get_reply == connection)
@@ -1508,8 +1654,8 @@ bus_connection_drop_pending_replies (BusConnections  *connections,
                          pending->will_get_reply,
                          pending->reply_serial);
           
-          _dbus_list_remove_link (&connections->pending_replies->items,
-                                  link);
+          bus_expire_list_remove_link (connections->pending_replies,
+                                       link);
           bus_pending_reply_free (pending);
         }
       else if (pending->will_send_reply == connection)
@@ -1527,8 +1673,7 @@ bus_connection_drop_pending_replies (BusConnections  *connections,
           pending->expire_item.added_tv_sec = 0;
           pending->expire_item.added_tv_usec = 0;
 
-          bus_expire_timeout_set_interval (connections->pending_replies->timeout,
-                                           0);
+          bus_expire_list_recheck_immediately (connections->pending_replies);
         }
       
       link = next;
@@ -1547,10 +1692,10 @@ cancel_pending_reply (void *data)
 {
   CancelPendingReplyData *d = data;
 
-  _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
+  _dbus_verbose ("d = %p\n", d);
   
-  if (!_dbus_list_remove (&d->connections->pending_replies->items,
-                          d->pending))
+  if (!bus_expire_list_remove (d->connections->pending_replies,
+                               &d->pending->expire_item))
     _dbus_assert_not_reached ("pending reply did not exist to be cancelled");
 
   bus_pending_reply_free (d->pending); /* since it's been cancelled */
@@ -1561,7 +1706,7 @@ cancel_pending_reply_data_free (void *data)
 {
   CancelPendingReplyData *d = data;
 
-  _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
+  _dbus_verbose ("d = %p\n", d);
   
   /* d->pending should be either freed or still
    * in the list of pending replies (owned by someone
@@ -1597,7 +1742,7 @@ bus_connections_expect_reply (BusConnections  *connections,
   
   reply_serial = dbus_message_get_serial (reply_to_this);
 
-  link = _dbus_list_get_first_link (&connections->pending_replies->items);
+  link = bus_expire_list_get_first_link (connections->pending_replies);
   count = 0;
   while (link != NULL)
     {
@@ -1612,8 +1757,8 @@ bus_connections_expect_reply (BusConnections  *connections,
           return FALSE;
         }
       
-      link = _dbus_list_get_next_link (&connections->pending_replies->items,
-                                       link);
+      link = bus_expire_list_get_next_link (connections->pending_replies,
+                                            link);
       if (pending->will_get_reply == will_get_reply)
         ++count;
     }
@@ -1651,8 +1796,8 @@ bus_connections_expect_reply (BusConnections  *connections,
       return FALSE;
     }
   
-  if (!_dbus_list_prepend (&connections->pending_replies->items,
-                           pending))
+  if (!bus_expire_list_add (connections->pending_replies,
+                            &pending->expire_item))
     {
       BUS_SET_OOM (error);
       dbus_free (cprd);
@@ -1666,7 +1811,7 @@ bus_connections_expect_reply (BusConnections  *connections,
                                         cancel_pending_reply_data_free))
     {
       BUS_SET_OOM (error);
-      _dbus_list_remove (&connections->pending_replies->items, pending);
+      bus_expire_list_remove (connections->pending_replies, &pending->expire_item);
       dbus_free (cprd);
       bus_pending_reply_free (pending);
       return FALSE;
@@ -1675,8 +1820,8 @@ bus_connections_expect_reply (BusConnections  *connections,
   cprd->pending = pending;
   cprd->connections = connections;
   
-  _dbus_get_current_time (&pending->expire_item.added_tv_sec,
-                          &pending->expire_item.added_tv_usec);
+  _dbus_get_monotonic_time (&pending->expire_item.added_tv_sec,
+                            &pending->expire_item.added_tv_usec);
 
   _dbus_verbose ("Added pending reply %p, replier %p receiver %p serial %u\n",
                  pending,
@@ -1698,10 +1843,10 @@ cancel_check_pending_reply (void *data)
 {
   CheckPendingReplyData *d = data;
 
-  _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
-  
-  _dbus_list_prepend_link (&d->connections->pending_replies->items,
-                           d->link);
+  _dbus_verbose ("d = %p\n",d);
+
+  bus_expire_list_add_link (d->connections->pending_replies,
+                            d->link);
   d->link = NULL;
 }
 
@@ -1710,14 +1855,14 @@ check_pending_reply_data_free (void *data)
 {
   CheckPendingReplyData *d = data;
 
-  _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
+  _dbus_verbose ("d = %p\n",d);
   
   if (d->link != NULL)
     {
       BusPendingReply *pending = d->link->data;
       
-      _dbus_assert (_dbus_list_find_last (&d->connections->pending_replies->items,
-                                          pending) == NULL);
+      _dbus_assert (!bus_expire_list_contains_item (d->connections->pending_replies,
+                                                    &pending->expire_item));
       
       bus_pending_reply_free (pending);
       _dbus_list_free_link (d->link);
@@ -1747,7 +1892,7 @@ bus_connections_check_reply (BusConnections *connections,
 
   reply_serial = dbus_message_get_reply_serial (reply);
 
-  link = _dbus_list_get_first_link (&connections->pending_replies->items);
+  link = bus_expire_list_get_first_link (connections->pending_replies);
   while (link != NULL)
     {
       BusPendingReply *pending = link->data;
@@ -1760,8 +1905,8 @@ bus_connections_check_reply (BusConnections *connections,
           break;
         }
       
-      link = _dbus_list_get_next_link (&connections->pending_replies->items,
-                                       link);
+      link = bus_expire_list_get_next_link (connections->pending_replies,
+                                            link);
     }
 
   if (link == NULL)
@@ -1791,11 +1936,10 @@ bus_connections_check_reply (BusConnections *connections,
   cprd->link = link;
   cprd->connections = connections;
   
-  _dbus_list_unlink (&connections->pending_replies->items,
-                     link);
+  bus_expire_list_unlink (connections->pending_replies,
+                          link);
   
-  _dbus_assert (_dbus_list_find_last (&connections->pending_replies->items,
-                                      link->data) == NULL);
+  _dbus_assert (!bus_expire_list_contains_item (connections->pending_replies, link->data));
 
   return TRUE;
 }
@@ -1920,7 +2064,10 @@ bus_transaction_send_from_driver (BusTransaction *transaction,
   if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
     return FALSE;
 
-  if (bus_connection_is_active (connection))
+#ifdef ENABLE_KDBUS_TRANSPORT
+  if(!bus_context_is_kdbus(bus_transaction_get_context (transaction))) /* we can't set destination on the basis of connection when on kdbus*/
+#endif
+    if (bus_connection_is_active (connection))
     {
       if (!dbus_message_set_destination (message,
                                          bus_connection_get_name (connection)))
@@ -2219,3 +2366,71 @@ bus_transaction_add_cancel_hook (BusTransaction               *transaction,
 
   return TRUE;
 }
+
+#ifdef DBUS_ENABLE_STATS
+int
+bus_connections_get_n_active (BusConnections *connections)
+{
+  return connections->n_completed;
+}
+
+int
+bus_connections_get_n_incomplete (BusConnections *connections)
+{
+  return connections->n_incomplete;
+}
+
+int
+bus_connections_get_total_match_rules (BusConnections *connections)
+{
+  return connections->total_match_rules;
+}
+
+int
+bus_connections_get_peak_match_rules (BusConnections *connections)
+{
+  return connections->peak_match_rules;
+}
+
+int
+bus_connections_get_peak_match_rules_per_conn (BusConnections *connections)
+{
+  return connections->peak_match_rules_per_conn;
+}
+
+int
+bus_connections_get_total_bus_names (BusConnections *connections)
+{
+  return connections->total_bus_names;
+}
+
+int
+bus_connections_get_peak_bus_names (BusConnections *connections)
+{
+  return connections->peak_bus_names;
+}
+
+int
+bus_connections_get_peak_bus_names_per_conn (BusConnections *connections)
+{
+  return connections->peak_bus_names_per_conn;
+}
+
+int
+bus_connection_get_peak_match_rules (DBusConnection *connection)
+{
+  BusConnectionData *d;
+
+  d = BUS_CONNECTION_DATA (connection);
+  return d->peak_match_rules;
+}
+
+int
+bus_connection_get_peak_bus_names (DBusConnection *connection)
+{
+  BusConnectionData *d;
+
+  d = BUS_CONNECTION_DATA (connection);
+  return d->peak_bus_names;
+}
+#endif /* DBUS_ENABLE_STATS */