| Summary: | poll(2) returns 0 when POLLIN-ing ordinary files | ||
|---|---|---|---|
| Product: | Base System | Reporter: | clemens fischer <ino-waiting> |
| Component: | kern | Assignee: | freebsd-bugs (Nobody) <bugs> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 4.0-RELEASE | ||
| Hardware: | Any | ||
| OS: | Any | ||
On Mon, 14 May 2001, clemensF wrote:
> > Jonathan Lemon:
>
> > > x.fd = open("trypoll.c",O_RDONLY);
> > > if (x.fd == -1) _exit(111);
> > > x.events = POLLIN;
> > > if (poll(&x,1,10) == -1) _exit(1);
> > > if (x.revents != POLLIN) _exit(1);
> >
> >
> > If you change "POLLIN" to "POLLRDNORM", then this will work as
> > you expect. Hoever, it's fairly pointless to poll() on a file,
> > since it will always return true, no matter what, so the code
> > above is fairly pointless.
> >
> > If you really want to poll a file for readability, use kqueue.
>
> the code snippet is part of "trypoll.c", which tests for a working poll(2) to
> autoconfigure a software-package. and it doesn't seem that pointless,
> because, as stated in the original PR, freebsd's poll(2) *does not* return
> true on an existing (local) file; it returns zero both as it's return- value
> and in x.revents, which is *wrong*.
>
> said package recognizes the deficiency, throws in it's workaround and
> proceeds (cvm-0.6). note that i'm not the author, which is bruce guenter
> <bruceg@em.ca>, but he build the programs on a linux system. i was the one
> who discovered the bug within freebsd 4.
Untested fix for -current, including style fixes.
Index: vfs_default.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/vfs_default.c,v
retrieving revision 1.50
diff -c -2 -r1.50 vfs_default.c
*** vfs_default.c 2001/05/06 17:40:22 1.50
--- vfs_default.c 2001/05/12 18:46:44
***************
*** 331,337 ****
} */ *ap;
{
! if ((ap->a_events & ~POLLSTANDARD) == 0)
! return (ap->a_events & (POLLRDNORM|POLLWRNORM));
! return (vn_pollrecord(ap->a_vp, ap->a_p, ap->a_events));
}
--- 331,339 ----
} */ *ap;
{
!
! if (ap->a_events & ~POLLSTANDARD)
! return (vn_pollrecord(ap->a_vp, ap->a_p, ap->a_events));
! /* PR27287: */
! return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
}
Bruce
State Changed From-To: open->closed this was fixed in vfs_default.c:1.51 and 1.28.2.2 (on RELENG_4) the code-fix proposed in the PR didn't make it into 4.3, although it is neccessary to get "real" programs running. the fix *has to* go into -stable! clemens fischer |
given a file "trypoll.c" (for relevant lines see below), poll does not see that input is ready immediately. the following code-snipet returns 0 for the return value and also 0 in x.revents. x.fd = open("trypoll.c",O_RDONLY); if (x.fd == -1) _exit(111); x.events = POLLIN; if (poll(&x,1,10) == -1) _exit(1); if (x.revents != POLLIN) _exit(1); Fix: there is a workaround for poll(2) based on select(2). it is contained in iopoll.c of the package cvm-0.6 (Credential Verification Module) by bruce guenther. How-To-Repeat: see above.