Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 May 2001 04:10:05 -0700 (PDT)
From:      Bruce Evans <bde@zeta.org.au>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: kern/27287: poll(2) returns 0 when POLLIN-ing ordinary files
Message-ID:  <200105141110.f4EBA5708618@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/27287; it has been noted by GNATS.

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
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200105141110.f4EBA5708618>