(lwpInitSelect): The code to query the system's limit on file

descriptors was not portable.  Simply use FD_SETSIZE instead.  The
lower of the two applies, so this wastes storage if the system's limit
is significantly below FD_SETSIZE.  Not an issue, as FD_SETSIZE is
fairly small.
(lwpSleepFd): Return if fd is too large.  Returning isn't nice,
but better than the buffer overruns in the old code.
(lwpSelect): Member nfile unused, remove.
This commit is contained in:
Markus Armbruster 2005-12-27 19:22:07 +00:00
parent 3aebb68ee7
commit 083f0ea350

View file

@ -41,11 +41,6 @@
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#ifdef hpux
#include <stdio.h>
#endif
#include "lwp.h" #include "lwp.h"
#include "lwpint.h" #include "lwpint.h"
@ -54,7 +49,6 @@
struct lwpSelect { struct lwpSelect {
int maxfd; int maxfd;
int nfds; int nfds;
int nfile;
fd_set readmask; fd_set readmask;
fd_set writemask; fd_set writemask;
struct lwpProc **wait; struct lwpProc **wait;
@ -69,14 +63,9 @@ lwpInitSelect(struct lwpProc *proc)
{ {
LwpSelect.maxfd = 0; LwpSelect.maxfd = 0;
LwpSelect.nfds = 0; LwpSelect.nfds = 0;
#ifdef hpux
LwpSelect.nfile = _NFILE;
#else
LwpSelect.nfile = getdtablesize();
#endif
FD_ZERO(&LwpSelect.readmask); FD_ZERO(&LwpSelect.readmask);
FD_ZERO(&LwpSelect.writemask); FD_ZERO(&LwpSelect.writemask);
LwpSelect.wait = calloc(LwpSelect.nfile, sizeof(char *)); LwpSelect.wait = calloc(FD_SETSIZE, sizeof(struct lwpProc *));
LwpSelect.delayq.head = 0; LwpSelect.delayq.head = 0;
LwpSelect.delayq.tail = 0; LwpSelect.delayq.tail = 0;
LwpSelect.proc = proc; LwpSelect.proc = proc;
@ -87,6 +76,8 @@ lwpSleepFd(int fd, int mask)
{ {
lwpStatus(LwpCurrent, "sleeping on fd %d for %d", fd, mask); lwpStatus(LwpCurrent, "sleeping on fd %d for %d", fd, mask);
if (CANT_HAPPEN(fd > FD_SETSIZE))
return;
if (LwpSelect.wait[fd] != 0) { if (LwpSelect.wait[fd] != 0) {
lwpStatus(LwpCurrent, lwpStatus(LwpCurrent,
"multiple sleeps attempted on file descriptor %d", fd); "multiple sleeps attempted on file descriptor %d", fd);