From kenji@k2r.org  Fri Feb 18 19:49:48 2000
Return-Path: <kenji@k2r.org>
Received: from limmax.k2r.org (limmax.k2r.org [210.160.188.69])
	by hub.freebsd.org (Postfix) with SMTP id E9E7537BB52
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 18 Feb 2000 19:49:39 -0800 (PST)
	(envelope-from kenji@k2r.org)
Received: (qmail 75316 invoked by uid 1000); 19 Feb 2000 03:49:55 -0000
Message-Id: <20000219034955.75315.qmail@k2r.org>
Date: 19 Feb 2000 03:49:55 -0000
From: kenji.rikitake@acm.org
Sender: kenji@k2r.org
Reply-To: kenji.rikitake@acm.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: vop_stdpoll() in /sys/kern/vfs_default.c does not handle POLLIN/POLLOUT flags
X-Send-Pr-Version: 3.2

>Number:         16816
>Category:       kern
>Synopsis:       vop_stdpoll() in /sys/kern/vfs_default.c does not handle POLLIN/POLLOUT
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 18 19:50:01 PST 2000
>Closed-Date:    Wed Jun 6 13:46:09 PDT 2001
>Last-Modified:  Wed Jun 06 13:46:19 PDT 2001
>Originator:     Kenji Rikitake
>Release:        FreeBSD 3.4-RELEASE i386
>Organization:
K2 Research
>Environment:

	FreeBSD 3.4-RELEASE

>Description:

	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.

>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 */	

>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.
	
--- /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));
 }

	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).


>Release-Note:
>Audit-Trail:

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: kenji.rikitake@acm.org
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: kern/16816: vop_stdpoll() in /sys/kern/vfs_default.c does not handle POLLIN/POLLOUT flags
Date: Tue, 22 Feb 2000 10:29:44 -0500 (EST)

 <<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
 
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Wed Jun 6 13:46:09 PDT 2001 
State-Changed-Why:  
fixed. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=16816 
>Unformatted:
