Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Jan 2002 01:50:01 -0800 (PST)
From:      Maxim Konovalov <maxim@macomnet.ru>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: kern/34020: poll(2) on fifos is broken
Message-ID:  <200201220950.g0M9o1F92222@freefall.freebsd.org>

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

From: Maxim Konovalov <maxim@macomnet.ru>
To: clemensF <ino-e31cbe40@spotteswoode.dnsalias.org>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/34020: poll(2) on fifos is broken
Date: Tue, 22 Jan 2002 12:42:01 +0300 (MSK)

 Here you are.
 
 Index: poll.h
 ===================================================================
 RCS file: /home/ncvs/src/sys/sys/poll.h,v
 retrieving revision 1.6.2.1
 diff -u -r1.6.2.1 poll.h
 --- poll.h	2000/08/21 12:25:58	1.6.2.1
 +++ poll.h	2002/01/22 09:37:31
 @@ -70,6 +70,8 @@
  #define	POLLATTRIB	0x0400		/* file attributes may have changed */
  #define	POLLNLINK	0x0800		/* (un)link/rename may have happened */
  #define	POLLWRITE	0x1000		/* file's contents may have changed */
 +/* General FreeBSD extensions (currently only supported for sockets): */
 +#define	POLLINIGNEOF	0x2000		/* POLLIN, except ignore EOF */
 
  /*
   * These events are set if they occur regardless of whether they were
 Index: fifo_vnops.c
 ===================================================================
 RCS file: /home/ncvs/src/sys/fs/fifofs/fifo_vnops.c,v
 retrieving revision 1.45.2.2
 diff -u -r1.45.2.2 fifo_vnops.c
 --- fifo_vnops.c	2001/02/26 04:23:20	1.45.2.2
 +++ fifo_vnops.c	2002/01/22 09:37:42
 @@ -446,18 +446,41 @@
  	} */ *ap;
  {
  	struct file filetmp;
 -	int revents = 0;
 +	int events, revents = 0;
 
 -	if (ap->a_events & (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND)) {
 +	events = ap->a_events &
 +	    (POLLIN | POLLINIGNEOF | POLLPRI | POLLRDNORM | POLLRDBAND);
 +	if (events) {
 +		/*
 +		 * Tell socket poll to ignore EOF so that we block if
 +		 * there is no writer (and no data).
 +		 */
 +		if (events & (POLLIN | POLLRDNORM)) {
 +			events &= ~(POLLIN | POLLRDNORM);
 +			events |= POLLINIGNEOF;
 +		}
  		filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_readsock;
  		if (filetmp.f_data)
 -			revents |= soo_poll(&filetmp, ap->a_events, ap->a_cred,
 +			revents |= soo_poll(&filetmp, events, ap->a_cred,
  			    ap->a_p);
 +
 +		/*
 +		 * If POLLIN or POLLRDNORM was requested and POLLINIGNEOF was
 +		 * not then convert POLLINIGNEOF back to POLLIN.
 +		 */
 +		events = ap->a_events & (POLLIN | POLLRDNORM | POLLINIGNEOF);
 +		if ((events & (POLLIN | POLLRDNORM)) &&
 +		    !(events & POLLINIGNEOF) &&
 +		    (revents & POLLINIGNEOF)) {
 +			revents &= ~POLLINIGNEOF;
 +			revents |= (events & (POLLIN | POLLRDNORM));
 +		}
  	}
 -	if (ap->a_events & (POLLOUT | POLLWRNORM | POLLWRBAND)) {
 +	events = ap->a_events & (POLLOUT | POLLWRNORM | POLLWRBAND);
 +	if (events) {
  		filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_writesock;
  		if (filetmp.f_data)
 -			revents |= soo_poll(&filetmp, ap->a_events, ap->a_cred,
 +			revents |= soo_poll(&filetmp, events, ap->a_cred,
  			    ap->a_p);
  	}
  	return (revents);
 Index: uipc_socket.c
 ===================================================================
 RCS file: /home/ncvs/src/sys/kern/uipc_socket.c,v
 retrieving revision 1.68.2.17
 diff -u -r1.68.2.17 uipc_socket.c
 --- uipc_socket.c	2001/12/01 21:32:42	1.68.2.17
 +++ uipc_socket.c	2002/01/22 09:37:54
 @@ -1518,6 +1518,11 @@
  		if (soreadable(so))
  			revents |= events & (POLLIN | POLLRDNORM);
 
 +	if (events & POLLINIGNEOF)
 +		if (so->so_rcv.sb_cc >= so->so_rcv.sb_lowat ||
 +		    !TAILQ_EMPTY(&so->so_comp) || so->so_error)
 +			revents |= POLLINIGNEOF;
 +
  	if (events & (POLLOUT | POLLWRNORM))
  		if (sowriteable(so))
  			revents |= events & (POLLOUT | POLLWRNORM);
 @@ -1527,7 +1532,9 @@
  			revents |= events & (POLLPRI | POLLRDBAND);
 
  	if (revents == 0) {
 -		if (events & (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND)) {
 +		if (events &
 +		    (POLLIN | POLLINIGNEOF | POLLPRI | POLLRDNORM |
 +		     POLLRDBAND)) {
  			selrecord(p, &so->so_rcv.sb_sel);
  			so->so_rcv.sb_flags |= SB_SEL;
  		}
 
 -- 
 Maxim Konovalov, MAcomnet, Internet-Intranet Dept., system engineer
 phone: +7 (095) 796-9079, mailto: maxim@macomnet.ru
 

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?200201220950.g0M9o1F92222>