Bug 16816

Summary: vop_stdpoll() in /sys/kern/vfs_default.c does not handle POLLIN/POLLOUT
Product: Base System Reporter: kenji.rikitake
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 3.4-RELEASE   
Hardware: Any   
OS: Any   

Description kenji.rikitake 2000-02-19 03:50:01 UTC
	When monitoring stdin using poll() with event POLLIN,
	it works when stdin is redirected to a pipe,
	but it does not when stdin is redirected to a local system file (vfs).
	I think this behavior is weird because POLLIN seems to work for
	all the other devices/socket/pipe/file-systems buf vfs.

Fix: This hasn't been tested yet, but I think changing the implementation
	of vop_stdpoll() in /sys/kern/vfs_default.c will solve this
	inconsistent behavior, by applying the following patch.
	


I would also like FreeBSD Development Team to clarify the difference
	of semantics between POLLIN and POLLRDNORM, or POLLOUT and POLLWRNORM,
	and put the definition clearly on poll(2).--hIL0KlGdPCIXf4ZIcjH05MTyI0fvzvD5bU7a9XNLqUqJ4DGV
Content-Type: text/plain; name="file.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="file.diff"

--- /sys/kern/vfs_default.c     Wed Jan 20 23:48:49 1999
+++ vfs_default.c       Sat Feb 19 12:44:43 2000
@@ -285,7 +285,8 @@
        } */ *ap;
 {
        if ((ap->a_events & ~POLLSTANDARD) == 0)
-               return (ap->a_events & (POLLRDNORM|POLLWRNORM));
+               return (ap->a_events & 
+                      (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
        return (vn_pollrecord(ap->a_vp, ap->a_p, ap->a_events));
 }
How-To-Repeat: 
cc -o poll-sample poll-sample.c
echo "127.0.0.1" > foo
cat ./foo | ./poll-sample
	retval = 1, revents=17
./poll-sample < ~/.foo
	retval = 0, revents=0 (after waiting 10 seconds)

when using POLLRDNORM for the value of x[0].events, the file redirection
works as:
	retval = 1, revents=64
	
/* poll-sample.c */
#include <stdio.h>
#include <poll.h>
#include <sys/types.h>

main()
{
        struct pollfd x[1];
        int i;

        x[0].fd = 0;
        x[0].events = POLLIN;

        i = poll(x, 1, 10000);
        printf("retval = %d, revents=%d\n", i, x[0].revents);
}
/* end of poll-sample.c */
Comment 1 Garrett A. Wollman 2000-02-22 15:29:44 UTC
<<On 19 Feb 2000 03:49:55 -0000, kenji.rikitake@acm.org said:

> --- /sys/kern/vfs_default.c     Wed Jan 20 23:48:49 1999
> +++ vfs_default.c       Sat Feb 19 12:44:43 2000
> @@ -285,7 +285,8 @@
>         } */ *ap;
>  {
>         if ((ap->a_events & ~POLLSTANDARD) == 0)
> -               return (ap->a_events & (POLLRDNORM|POLLWRNORM));
> +               return (ap->a_events & 
> +                      (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
>         return (vn_pollrecord(ap->a_vp, ap->a_p, ap->a_events));
>  }

Looks fine to me.

-GAWollman

--
Garrett A. Wollman   | O Siem / We are all family / O Siem / We're all the same
wollman@lcs.mit.edu  | O Siem / The fires of freedom 
Opinions not those of| Dance in the burning flame
MIT, LCS, CRS, or NSA|                     - Susan Aglukark and Chad Irschick
Comment 2 Poul-Henning Kamp freebsd_committer freebsd_triage 2001-06-06 21:46:09 UTC
State Changed
From-To: open->closed

fixed.