[runtime] Use getrlimit () to obtain the size of the fd table instead of getdtablesiz...
authorZoltan Varga <vargaz@gmail.com>
Wed, 15 Oct 2014 20:45:19 +0000 (16:45 -0400)
committerZoltan Varga <vargaz@gmail.com>
Wed, 15 Oct 2014 20:45:19 +0000 (16:45 -0400)
configure.ac
mono/io-layer/handles.c

index 7b675e4a1ef0677bac36823ee4e4d23422332dba..b7898abe061a1d467733c9d5fd30223a7c0c407d 100644 (file)
@@ -1194,7 +1194,7 @@ if test x$target_win32 = xno; then
 
        AC_CHECK_HEADERS(execinfo.h)
 
-       AC_CHECK_HEADERS(sys/auxv.h)
+       AC_CHECK_HEADERS(sys/auxv.h sys/resource.h)
 
        AC_CHECK_FUNCS(getgrgid_r)
        AC_CHECK_FUNCS(getgrnam_r)
@@ -1213,6 +1213,7 @@ if test x$target_win32 = xno; then
        AC_CHECK_FUNCS(dl_iterate_phdr)
        AC_CHECK_FUNCS(dladdr)
        AC_CHECK_FUNCS(sysconf)
+       AC_CHECK_FUNCS(getrlimit)
 
        AC_CHECK_FUNCS(sched_setaffinity)
        AC_CHECK_FUNCS(sched_getcpu)
index 4e8c5223c755f87995c105d883b370425f93cac5..cb0033f5a1ba613a88c4f7a3b3b93f69ab764588 100644 (file)
@@ -29,6 +29,9 @@
 #  include <dirent.h>
 #endif
 #include <sys/stat.h>
+#ifdef HAVE_SYS_RESOURCE_H
+#  include <sys/resource.h>
+#endif
 
 #include <mono/io-layer/wapi.h>
 #include <mono/io-layer/wapi-private.h>
@@ -224,7 +227,18 @@ wapi_init (void)
        g_assert ((sizeof (handle_ops) / sizeof (handle_ops[0]))
                  == WAPI_HANDLE_COUNT);
        
+#ifdef HAVE_GETRLIMIT
+       {
+               struct rlimit limit;
+               int res;
+
+               res = getrlimit (RLIMIT_NOFILE, &limit);
+               g_assert (res == 0);
+               _wapi_fd_reserve = limit.rlim_cur;
+       }
+#else
        _wapi_fd_reserve = getdtablesize();
+#endif
 
        /* This is needed by the code in _wapi_handle_new_internal */
        _wapi_fd_reserve = (_wapi_fd_reserve + (_WAPI_HANDLE_INITIAL_COUNT - 1)) & ~(_WAPI_HANDLE_INITIAL_COUNT - 1);