Set default maximum number of Unix fds according to OS
authorMatt Fischer <matt.fischer@garmin.com>
Wed, 20 Feb 2013 21:23:42 +0000 (15:23 -0600)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Thu, 11 Apr 2013 12:34:55 +0000 (13:34 +0100)
QNX has an arbitrary limit to the number of file descriptors
which may be passed in a message, which is smaller than the
current default.  This patch therefore changes the default from
a hardcoded constant to a macro, which is determined at configure
time by looking at the host operating system.

[This reduces the limit from 4096 (session)/1024 (system) to 128 fds
per message on QNX, and 1024 fds per message on other operating systems.
I think the reduced session bus limit on other OSs is a reasonable change
too, given that the default hard/soft ulimits in Linux are only 4096/1024
fds per process. -smcv]

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=61176
Reviewed-by: Simon McVittie <simon.mcvittie.collabora.co.uk>
bus/config-parser.c
bus/session.conf.in
cmake/config.h.cmake
configure.ac
dbus/dbus-message.c

index 1d1b8bf..ff73ed0 100644 (file)
@@ -420,9 +420,9 @@ bus_config_parser_new (const DBusString      *basedir,
       maximum number of file descriptors we can receive. Picking a
       high value here thus translates directly to more memory
       allocation. */
-      parser->limits.max_incoming_unix_fds = 1024*4;
-      parser->limits.max_outgoing_unix_fds = 1024*4;
-      parser->limits.max_message_unix_fds = 1024;
+      parser->limits.max_incoming_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS*4;
+      parser->limits.max_outgoing_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS*4;
+      parser->limits.max_message_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS;
       
       /* Making this long means the user has to wait longer for an error
        * message if something screws up, but making it too short means
index 716b5e7..bb6f70b 100644 (file)
@@ -49,7 +49,7 @@
   <limit name="max_outgoing_bytes">1000000000</limit>
   <limit name="max_outgoing_unix_fds">250000000</limit>
   <limit name="max_message_size">1000000000</limit>
-  <limit name="max_message_unix_fds">4096</limit>
+  <limit name="max_message_unix_fds">@default_message_unix_fds@</limit>
   <limit name="service_start_timeout">120000</limit>  
   <limit name="auth_timeout">240000</limit>
   <limit name="max_completed_connections">100000</limit>  
index 76ccb86..b0dde3d 100644 (file)
@@ -82,6 +82,8 @@
 # define DBUS_ENABLE_X11_AUTOLAUNCH 1
 #endif
 
+#define DBUS_DEFAULT_MESSAGE_UNIX_FDS 1024
+
 #define _DBUS_VA_COPY_ASSIGN(a1,a2) { a1 = a2; }
 
 #cmakedefine DBUS_VA_COPY_FUNC
index aff812e..c55ced7 100644 (file)
@@ -1296,6 +1296,17 @@ if test x$with_valgrind != xno; then
   AC_DEFINE([WITH_VALGRIND], [1], [Define to add Valgrind instrumentation])
 fi
 
+# Determine maximum number of Unix fds which may be passed
+AS_CASE([$host_os],
+  [*qnx*],
+    [default_message_unix_fds=256],
+  [*],
+    [default_message_unix_fds=1024])
+AC_DEFINE_UNQUOTED([DBUS_DEFAULT_MESSAGE_UNIX_FDS],
+  [$default_message_unix_fds],
+  [Default for dbus_connection_get_max_message_unix_fds()])
+AC_SUBST([default_message_unix_fds])
+
 #### Set up final flags
 LIBDBUS_LIBS="$THREAD_LIBS $NETWORK_libs"
 AC_SUBST([LIBDBUS_LIBS])
index 71bcee6..619bc69 100644 (file)
@@ -3802,7 +3802,7 @@ _dbus_message_loader_new (void)
   SCM_RIGHTS works we need to preallocate an fd array of the maximum
   number of unix fds we want to receive in advance. A
   try-and-reallocate loop is not possible. */
-  loader->max_message_unix_fds = 1024;
+  loader->max_message_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS;
 
   if (!_dbus_string_init (&loader->data))
     {