Date: Thu, 18 Nov 1999 19:14:35 +0300 (MSK) From: seva@mtelecom.ru To: FreeBSD-gnats-submit@freebsd.org Subject: kern/14979: select/poll handler for fifo is broken in FreeBSD-3.X Message-ID: <199911181614.TAA22164@p1.f434.n5020.z2.fidonet.org>
next in thread | raw e-mail | index | archive | help
>Number: 14979 >Category: kern >Synopsis: fifo's select(2)/poll(2) handler is broken in FreeBSD-3.X >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Nov 18 08:10:00 PST 1999 >Closed-Date: >Last-Modified: >Originator: Seva Semenov >Release: FreeBSD 3.2-RELEASE i386 >Organization: Seva's Bedroom >Environment: FreeBSD 3.3 RELEASE and FreeBSD 3.2 RELEASE >Description: when fifo (maden by mkfifo(1)) has select(2)ed or poll(2)ed select(2) and poll(2) returns without timeout even fifo has no bytes to read. In FreeBSD 2.X and NetBSD 1.4.1 there is timeout as expected. >How-To-Repeat: # mkfifo fifo # cat readfifo.select.c #include <fcntl.h> #include <err.h> #include <errno.h> #include <sys/types.h> #include <sys/time.h> #include <unistd.h> #include <stdio.h> #include <string.h> int main(int argc,char **argv) { int fd; char *fn="fifo"; if(argc>1) fn=*(argv+1); if((fd=open(fn,O_RDONLY|O_NONBLOCK))<0) err(errno,"can't open %s",fn); for(;;){ fd_set fds; int r; struct timeval tv; size_t sz; char b[64]; tv.tv_sec=5; tv.tv_usec=0; FD_ZERO(&fds); FD_SET(fd,&fds); r=select(FD_SETSIZE,&fds,NULL,NULL,&tv); if(r<0) err(errno,"select return %d ",r); if(r==0){ fputs("timeout\n",stderr); continue; } sz=read(fd,b,63); if(sz<0) err(errno,"read fifo return %d",sz); if(!sz){ fputs("read null bites\n",stderr); continue; } b[sz]='\0'; puts(b); fflush(stdout); } } # cat readfifo.poll.c #include <fcntl.h> #include <err.h> #include <errno.h> #include <sys/types.h> #include <sys/uio.h> #include <unistd.h> #include <poll.h> #include <stdio.h> int main(int argc,char **argv) { int fd; char *fn="fifo"; if(argc>1) fn=*(argv+1); fd=open(fn,O_RDONLY|O_NONBLOCK); if(fd<0) err(errno,"cannot open %s",fn); for(;;){ struct pollfd pfd; int pr; size_t sz; char b[64]; pfd.fd=fd; /*pfd.events=POLLRDNORM;*/ pfd.events=POLLIN; pr=poll(&pfd,1,5000); if(pr==-1) err(errno,"error in poll"); if(!pr){ fputs("timeout\n",stderr); continue; } puts("reading");fflush(stdout); sz=read(fd,b,63); if(sz<0) err(errno,"cannot read"); if(!sz){ fputs("read null bytes\n",stderr); continue; } b[sz]='\0'; puts(b); fflush(stdout); } } # make readfifo.select # make readfifo.poll # ./readfifo.select >Fix: I don't know. >Release-Note: >Audit-Trail: >Unformatted: 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?199911181614.TAA22164>