Fix select(2) for the Alpha. (!!) It was never returning true for
fd's in the range of 32-63, 96-127 etc. The first problem was the FD_*() macros were shifting a 32 bit integer "1" left by more than 32 bits. The same problem happened in selscan(). ffs() also takes an int argument and causes failure. For cases where int == long (ie: the usual case for x86, but not always as gcc can have long being a 64 bit quantity) ffs() could be used. Reported by: Marian Stagarescu <marian@bile.skycache.com> Reviewed by: dfr, gallatin (sys/types.h only) Approved by: jkh
This commit is contained in:
parent
c4d21ca229
commit
21e6913264
@ -730,9 +730,9 @@ selscan(p, ibits, obits, nfd)
|
||||
fd_mask **ibits, **obits;
|
||||
int nfd;
|
||||
{
|
||||
register struct filedesc *fdp = p->p_fd;
|
||||
register int msk, i, j, fd;
|
||||
register fd_mask bits;
|
||||
struct filedesc *fdp = p->p_fd;
|
||||
int msk, i, fd;
|
||||
fd_mask bits;
|
||||
struct file *fp;
|
||||
int n = 0;
|
||||
/* Note: backend also returns POLLHUP/POLLERR if appropriate. */
|
||||
@ -743,14 +743,16 @@ selscan(p, ibits, obits, nfd)
|
||||
continue;
|
||||
for (i = 0; i < nfd; i += NFDBITS) {
|
||||
bits = ibits[msk][i/NFDBITS];
|
||||
while ((j = ffs(bits)) && (fd = i + --j) < nfd) {
|
||||
bits &= ~(1 << j);
|
||||
/* ffs(int mask) not portable, fd_mask is long */
|
||||
for (fd = i; bits && fd < nfd; fd++, bits >>= 1) {
|
||||
if (!(bits & 1))
|
||||
continue;
|
||||
fp = fdp->fd_ofiles[fd];
|
||||
if (fp == NULL)
|
||||
return (EBADF);
|
||||
if (fo_poll(fp, flag[msk], fp->f_cred, p)) {
|
||||
obits[msk][(fd)/NFDBITS] |=
|
||||
(1 << ((fd) % NFDBITS));
|
||||
((fd_mask)1 << ((fd) % NFDBITS));
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
@ -178,9 +178,10 @@ typedef struct fd_set {
|
||||
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
|
||||
} fd_set;
|
||||
|
||||
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
|
||||
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
|
||||
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
|
||||
#define _fdset_mask(n) ((fd_mask)1 << ((n) % NFDBITS))
|
||||
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= _fdset_mask(n))
|
||||
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~_fdset_mask(n))
|
||||
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & _fdset_mask(n))
|
||||
#define FD_COPY(f, t) bcopy(f, t, sizeof(*(f)))
|
||||
#define FD_ZERO(p) bzero(p, sizeof(*(p)))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user