From toor@spotteswoode.yi.org  Sat May 12 09:34:35 2001
Return-Path: <toor@spotteswoode.yi.org>
Received: from mout1.freenet.de (mout1.freenet.de [194.97.50.132])
	by hub.freebsd.org (Postfix) with ESMTP id D9C8F37B43F
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 12 May 2001 09:34:34 -0700 (PDT)
	(envelope-from toor@spotteswoode.yi.org)
Received: from [194.97.50.135] (helo=mx2.freenet.de)
	by mout1.freenet.de with esmtp (Exim 3.22 #1)
	id 14ycLh-0006TH-00
	for FreeBSD-gnats-submit@freebsd.org; Sat, 12 May 2001 18:34:33 +0200
Received: from a103a.pppool.de ([213.6.16.58] helo=spotteswoode.yi.org)
	by mx2.freenet.de with asmtp (ID inode@freenet.de) (Exim 3.22 #1)
	id 14ycLg-0003Gm-00
	for FreeBSD-gnats-submit@freebsd.org; Sat, 12 May 2001 18:34:33 +0200
Received: (qmail 3790 invoked by uid 0); 12 May 2001 16:34:36 -0000
Message-Id: <20010512163436.3789.qmail@spotteswoode.yi.org>
Date: 12 May 2001 16:34:36 -0000
From: clemens fischer <ino-waiting@gmx.net>
To: FreeBSD-gnats-submit@freebsd.org
Subject: poll(2) returns 0 when POLLIN-ing ordinary files
X-Send-Pr-Version: 3.2

>Number:         27287
>Category:       kern
>Synopsis:       poll(2) returns 0 when POLLIN-ing ordinary files
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 12 09:40:01 PDT 2001
>Closed-Date:    Fri Jun 15 20:27:32 PDT 2001
>Last-Modified:  Sun Jan 13 03:10:00 PST 2002
>Originator:     Super
>Release:        FreeBSD 4.0-RELEASE i386
>Organization:
privat
>Environment:

the bug is in freebsd 4 and can be verified using the follwing code snipet.

>Description:

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


>How-To-Repeat:

see above.

>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.
>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: clemensF <rabat@web.de>
Cc: Jonathan Lemon <jlemon@flugsvamp.com>,
	freebsd-gnats-submit@FreeBSD.ORG, Bruce Guenter <bruceg@em.ca>
Subject: Re: kern/27287: poll(2) returns 0 when POLLIN-ing ordinary files
Date: Mon, 14 May 2001 21:08:01 +1000 (EST)

 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 
State-Changed-By: assar 
State-Changed-When: Fri Jun 15 20:27:32 PDT 2001 
State-Changed-Why:  
this was fixed in vfs_default.c:1.51 and 1.28.2.2 (on RELENG_4) 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27287 

From: clemensF <ino-waiting@gmx.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: kern/27287: poll(2) returns 0 when POLLIN-ing ordinary files
Date: Sun, 13 Jan 2002 12:05:37 +0100

 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
>Unformatted:
