Index: sys_generic.c =================================================================== RCS file: /home/ncvs/src/sys/kern/sys_generic.c,v retrieving revision 1.70 diff -u -r1.70 sys_generic.c --- sys_generic.c 2001/01/24 11:12:37 1.70 +++ sys_generic.c 2001/02/07 23:04:58 @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -857,14 +858,22 @@ caddr_t bits; char smallbits[32 * sizeof(struct pollfd)]; struct timeval atv, rtv, ttv; - int s, ncoll, error = 0, timo; + int s, ncoll, error = 0, timo, lim, nfds; size_t ni; - if (SCARG(uap, nfds) > p->p_fd->fd_nfiles) { + nfds = SCARG(uap, nfds); + /* + * This is kinda bogus. We have fd limits, but that doesn't + * map too well to the size of the pfd[] array. Make sure + * we let the process use at least FD_SETSIZE entries. + */ + lim = min((int)p->p_rlimit[RLIMIT_NOFILE].rlim_cur, maxfilesperproc); + lim = min(lim, FD_SETSIZE); + if (nfds > lim) { /* forgiving; slightly wrong */ - SCARG(uap, nfds) = p->p_fd->fd_nfiles; + nfds = lim; } - ni = SCARG(uap, nfds) * sizeof(struct pollfd); + ni = nfds * sizeof(struct pollfd); if (ni > sizeof(smallbits)) bits = malloc(ni, M_TEMP, M_WAITOK); else @@ -891,7 +900,7 @@ ncoll = nselcoll; p->p_flag |= P_SELECT; PROC_UNLOCK(p); - error = pollscan(p, (struct pollfd *)bits, SCARG(uap, nfds)); + error = pollscan(p, (struct pollfd *)bits, nfds); PROC_LOCK(p); if (error || p->p_retval[0]) goto done;