Author: tilghman
Date: Wed Jul 28 17:41:18 2010
New Revision: 280301

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=280301
Log:
Allow test to be run at runtime, too.

Modified:
    team/tilghman/ast_select/configure
    team/tilghman/ast_select/configure.ac
    team/tilghman/ast_select/include/asterisk/autoconfig.h.in
    team/tilghman/ast_select/main/asterisk.c

Modified: team/tilghman/ast_select/configure.ac
URL: 
http://svnview.digium.com/svn/asterisk/team/tilghman/ast_select/configure.ac?view=diff&rev=280301&r1=280300&r2=280301
==============================================================================
--- team/tilghman/ast_select/configure.ac (original)
+++ team/tilghman/ast_select/configure.ac Wed Jul 28 17:41:18 2010
@@ -30,6 +30,7 @@
      darwin*)
      AC_PREFIX_DEFAULT([/usr/local])
      AC_DEFINE([AST_POLL_COMPAT], 1, [Define to 1 if internal poll should be 
used.])
+     AC_DEFINE([_DARWIN_UNLIMITED_SELECT], 1, [Define to 1 if running on 
Darwin.])
      ;;
      *)
      AC_PREFIX_DEFAULT([/usr])
@@ -475,6 +476,50 @@
        AC_MSG_RESULT(no),
        AC_MSG_RESULT(cross-compile)
 )
+
+ac_cv_have_variable_fdset=0
+AC_MSG_CHECKING(if we can increase the maximum select-able file descriptor)
+AC_RUN_IFELSE(
+AC_LANG_PROGRAM([
+#include <stdio.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+], [[
+       struct rlimit rlim = { FD_SETSIZE + 2, FD_SETSIZE + 2 };
+       int fd[[2]];
+       struct timeval tv = { 0, };
+       struct ast_fdset { long fds_bits[[1024]]; } fds = { { 0, } };
+       if (setrlimit(RLIMIT_NOFILE, &rlim)) { exit(1); }
+       if ((fd0 = open("/dev/null", O_RDONLY)) < 0) { exit(1); }
+       if (dup2(fd0, (fd1 = FD_SETSIZE + 1)) < 0) { exit(1); }
+       FD_SET(fd[[0]], (fd_set *) &fds);
+       FD_SET(fd[[1]], (fd_set *) &fds);
+       if (select(FD_SETSIZE + 2, (fd_set *) &fds, NULL, NULL, &tv) < 0) { 
exit(1); }
+       exit(0)]]),
+       AC_MSG_RESULT(yes)
+       ac_cv_have_variable_fdset=1
+       AC_DEFINE([HAVE_VARIABLE_FDSET], 1, [Define to 1 if your system can 
support larger than default select bitmasks.]),
+       AC_MSG_RESULT(no),
+       AC_MSG_RESULT(cross-compile)
+)
+
+if test "${ac_cv_have_variable_fdset}x" = "0x"; then
+       AC_RUN_IFELSE(
+               AC_LANG_PROGRAM([
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdlib.h>
+], [if (getuid() != 0) { exit(1); }]),
+               AC_DEFINE([CONFIGURE_RAN_AS_ROOT], 1, [Some configure tests 
will unexpectedly fail if configure is run by a non-root user.  These may be 
able to be tested at runtime.]))
+fi
 
 AST_GCC_ATTRIBUTE(pure)
 AST_GCC_ATTRIBUTE(malloc)

Modified: team/tilghman/ast_select/include/asterisk/autoconfig.h.in
URL: 
http://svnview.digium.com/svn/asterisk/team/tilghman/ast_select/include/asterisk/autoconfig.h.in?view=diff&rev=280301&r1=280300&r2=280301
==============================================================================
--- team/tilghman/ast_select/include/asterisk/autoconfig.h.in (original)
+++ team/tilghman/ast_select/include/asterisk/autoconfig.h.in Wed Jul 28 
17:41:18 2010
@@ -16,6 +16,10 @@
 
 /* Define to 1 if the `closedir' function returns void instead of `int'. */
 #undef CLOSEDIR_VOID
+
+/* Some configure tests will unexpectedly fail if configure is run by a
+   non-root user. These may be able to be tested at runtime. */
+#undef CONFIGURE_RAN_AS_ROOT
 
 /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
    systems. This function is required for `alloca.c' support on those systems.
@@ -720,6 +724,9 @@
 #ifndef _ALL_SOURCE
 # undef _ALL_SOURCE
 #endif
+
+/* Define to 1 if running on Darwin. */
+#undef _DARWIN_UNLIMITED_SELECT
 
 /* Number of bits in a file offset, on hosts where this is settable. */
 #undef _FILE_OFFSET_BITS

Modified: team/tilghman/ast_select/main/asterisk.c
URL: 
http://svnview.digium.com/svn/asterisk/team/tilghman/ast_select/main/asterisk.c?view=diff&rev=280301&r1=280300&r2=280301
==============================================================================
--- team/tilghman/ast_select/main/asterisk.c (original)
+++ team/tilghman/ast_select/main/asterisk.c Wed Jul 28 17:41:18 2010
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 1999 - 2009, Digium, Inc.
+ * Copyright (C) 1999 - 2010, Digium, Inc.
  *
  * Mark Spencer <marks...@digium.com>
  *
@@ -161,7 +161,6 @@
 
 double option_maxload;                         /*!< Max load avg on system */
 int option_maxcalls;                           /*!< Max number of active calls 
*/
-
 /*! @} */
 
 char record_cache_dir[AST_CACHE_DIR_LEN] = AST_TMP_DIR;
@@ -239,6 +238,8 @@
 extern const char *ast_build_os;
 extern const char *ast_build_date;
 extern const char *ast_build_user;
+
+unsigned int ast_FD_SETSIZE = FD_SETSIZE;
 
 static char *_argv[256];
 static int shuttingdown;
@@ -2734,6 +2735,7 @@
        int isroot = 1, rundir_exists = 0;
        char *buf;
        char *runuser = NULL, *rungroup = NULL;
+       struct rlimit l;
 
        /* Remember original args for restart */
        if (argc > sizeof(_argv) / sizeof(_argv[0]) - 1) {
@@ -2882,7 +2884,6 @@
        }
 
        if (ast_opt_dump_core) {
-               struct rlimit l;
                memset(&l, 0, sizeof(l));
                l.rlim_cur = RLIM_INFINITY;
                l.rlim_max = RLIM_INFINITY;
@@ -2890,6 +2891,44 @@
                        ast_log(LOG_WARNING, "Unable to disable core size 
resource limit: %s\n", strerror(errno));
                }
        }
+
+       if (getrlimit(RLIMIT_NOFILE, &l)) {
+               ast_log(LOG_WARNING, "Unable to check file descriptor limit: 
%s\n", strerror(errno));
+       }
+
+#if !defined(CONFIGURE_RAN_AS_ROOT)
+       /* Check if select(2) will run with more file descriptors */
+       do {
+               int fd, fd2;
+               ast_fdset readers;
+               struct timeval tv = { 0, };
+
+               if (l.rlim_cur <= FD_SETSIZE) {
+                       /* The limit of select()able FDs is irrelevant, because 
we'll never
+                        * open one that high. */
+                       break;
+               }
+
+               if (!(fd = open("/dev/null", O_RDONLY))) {
+                       ast_log(LOG_ERROR, "Cannot open a file descriptor at 
boot? %s\n", strerror(errno));
+                       break; /* XXX Should we exit() here? XXX */
+               }
+
+               fd2 = (l.rlim_cur > sizeof(readers) * 8 ? sizeof(readers) * 8 : 
l.rlim_cur) - 1;
+               if (dup2(fd, fd2)) {
+                       ast_log(LOG_WARNING, "Cannot open maximum file 
descriptor %d at boot? %s\n", fd2, strerror(errno));
+                       break;
+               }
+
+               FD_ZERO(&readers);
+               FD_SET(fd2, &readers);
+               if (ast_select(fd2 + 1, &readers, NULL, NULL, &tv) < 0) {
+                       ast_log(LOG_WARNING, "Maximum select()able file 
descriptor is %d\n", FD_SETSIZE);
+               }
+       } while (0);
+#elif defined(HAVE_VARIABLE_FDSET)
+       ast_FD_SETSIZE = l.rlim_cur;
+#endif /* !defined(CONFIGURE_RAN_AS_ROOT) */
 
        if ((!rungroup) && !ast_strlen_zero(ast_config_AST_RUN_GROUP))
                rungroup = ast_config_AST_RUN_GROUP;


-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

svn-commits mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/svn-commits

Reply via email to