Index: include/asterisk/select.h =================================================================== --- include/asterisk/select.h (revision 310416) +++ include/asterisk/select.h (working copy) @@ -37,8 +37,9 @@ #if !defined(HAVE_VARIABLE_FDSET) && defined(CONFIGURE_RAN_AS_ROOT) #define ast_fdset fd_set #else +#define ast_FDMAX 32768 typedef struct { - TYPEOF_FD_SET_FDS_BITS fds_bits[4096 / SIZEOF_FD_SET_FDS_BITS]; /* 32768 bits */ + TYPEOF_FD_SET_FDS_BITS fds_bits[ast_FDMAX / 8 / SIZEOF_FD_SET_FDS_BITS]; /* 32768 bits */ } ast_fdset; #undef FD_ZERO Index: main/asterisk.c =================================================================== --- main/asterisk.c (revision 310416) +++ main/asterisk.c (working copy) @@ -2932,6 +2932,7 @@ fd2 = (l.rlim_cur > sizeof(readers) * 8 ? sizeof(readers) * 8 : l.rlim_cur) - 1; if (dup2(fd, fd2) < 0) { ast_log(LOG_WARNING, "Cannot open maximum file descriptor %d at boot? %s\n", fd2, strerror(errno)); + close(fd); break; } @@ -2940,9 +2941,12 @@ if (ast_select(fd2 + 1, &readers, NULL, NULL, &tv) < 0) { ast_log(LOG_WARNING, "Maximum select()able file descriptor is %d\n", FD_SETSIZE); } + ast_FD_SETSIZE = l.rlim_cur > ast_FDMAX ? ast_FDMAX : l.rlim_cur; + close(fd); + close(fd2); } while (0); #elif defined(HAVE_VARIABLE_FDSET) - ast_FD_SETSIZE = l.rlim_cur; + ast_FD_SETSIZE = l.rlim_cur > ast_FDMAX ? ast_FDMAX : l.rlim_cur; #endif /* !defined(CONFIGURE_RAN_AS_ROOT) */ if ((!rungroup) && !ast_strlen_zero(ast_config_AST_RUN_GROUP))