Log to syslog if max_completed_connections or max_connections_per_user are exceeded
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Fri, 1 Jul 2016 10:53:17 +0000 (11:53 +0100)
committerSimon McVittie <smcv@debian.org>
Tue, 16 Aug 2016 15:16:32 +0000 (16:16 +0100)
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=86442

bus/connection.c
bus/connection.h
bus/driver.c

index 67793ba..71168a5 100644 (file)
@@ -1633,13 +1633,23 @@ bus_connection_get_name (DBusConnection *connection)
 dbus_bool_t
 bus_connections_check_limits (BusConnections  *connections,
                               DBusConnection  *requesting_completion,
+                              const char     **limit_name_out,
+                              int             *limit_out,
                               DBusError       *error)
 {
   unsigned long uid;
+  int limit;
 
-  if (connections->n_completed >=
-      bus_context_get_max_completed_connections (connections->context))
+  limit = bus_context_get_max_completed_connections (connections->context);
+
+  if (connections->n_completed >= limit)
     {
+      if (limit_name_out != NULL)
+        *limit_name_out = "max_completed_connections";
+
+      if (limit_out != NULL)
+        *limit_out = limit;
+
       dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
                       "The maximum number of active connections has been reached");
       return FALSE;
@@ -1647,9 +1657,16 @@ bus_connections_check_limits (BusConnections  *connections,
   
   if (dbus_connection_get_unix_user (requesting_completion, &uid))
     {
-      if (get_connections_for_uid (connections, uid) >=
-          bus_context_get_max_connections_per_user (connections->context))
+      limit = bus_context_get_max_connections_per_user (connections->context);
+
+      if (get_connections_for_uid (connections, uid) >= limit)
         {
+          if (limit_name_out != NULL)
+            *limit_name_out = "max_connections_per_user";
+
+          if (limit_out != NULL)
+            *limit_out = limit;
+
           dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
                           "The maximum number of active connections for UID %lu has been reached",
                           uid);
index 746f4eb..9e253ae 100644 (file)
@@ -57,6 +57,8 @@ BusSELinuxID*   bus_connection_get_selinux_id     (DBusConnection
 BusAppArmorConfinement* bus_connection_dup_apparmor_confinement (DBusConnection *connection);
 dbus_bool_t     bus_connections_check_limits      (BusConnections               *connections,
                                                    DBusConnection               *requesting_completion,
+                                                   const char                  **limit_name_out,
+                                                   int                          *limit_out,
                                                    DBusError                    *error);
 void            bus_connections_expire_incomplete (BusConnections               *connections);
 
index 684c3d8..2d06abc 100644 (file)
@@ -428,6 +428,9 @@ bus_driver_handle_hello (DBusConnection *connection,
   dbus_bool_t retval;
   BusRegistry *registry;
   BusConnections *connections;
+  DBusError tmp_error;
+  int limit;
+  const char *limit_name;
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
@@ -445,11 +448,19 @@ bus_driver_handle_hello (DBusConnection *connection,
    * incomplete connections. It's even OK if the connection wants to
    * retry the hello message, we support that.
    */
+  dbus_error_init (&tmp_error);
   connections = bus_connection_get_connections (connection);
   if (!bus_connections_check_limits (connections, connection,
-                                     error))
+                                     &limit_name, &limit,
+                                     &tmp_error))
     {
-      _DBUS_ASSERT_ERROR_IS_SET (error);
+      BusContext *context;
+
+      _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
+      context = bus_connection_get_context (connection);
+      bus_context_log (context, DBUS_SYSTEM_LOG_WARNING, "%s (%s=%d)",
+          tmp_error.message, limit_name, limit);
+      dbus_move_error (&tmp_error, error);
       return FALSE;
     }