Date: Wed, 12 Jul 2000 18:46:01 +0200 From: petervd@vuurwerk.nl To: FreeBSD-gnats-submit@freebsd.org Subject: gnu/19871: select bug on named pipes Message-ID: <963420361.560147.96633.nullmailer@daemon.vuurwerk.nl>
next in thread | raw e-mail | index | archive | help
>Number: 19871 >Category: gnu >Synopsis: select on named pipes always returns 'available for reading' >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Jul 12 09:50:00 PDT 2000 >Closed-Date: >Last-Modified: >Originator: Peter van Dijk >Release: FreeBSD 4.0-STABLE i386 >Organization: Vuurwerk Internet, Haarlem, The Netherlands >Environment: Standard FreeBSD 4.0-STABLE kernel/world (last cvsup+new world/kernel around 3 months ago). >Description: When select()'ing on a named pipe for reading, it will *always* return immediately even if no data is waiting. *also* openening the pipe for writing will fix this behaviour. >How-To-Repeat: The following snippet of code is stolen from the qmail-1.03 sources and changed slightly to compile standalone: #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/time.h> #include <unistd.h> #define FN "temp-trynpbg1.fifo" void main() { int flagbug; struct timeval instant; fd_set rfds; flagbug = 0; if (mkfifo(FN,0600) != -1) { close(0); if (open(FN,O_RDONLY|O_NDELAY) == 0) { FD_ZERO(&rfds); FD_SET(0,&rfds); instant.tv_sec = instant.tv_usec = 0; if (select(1,&rfds,(fd_set *) 0,(fd_set *) 0,&instant) > 0) flagbug = 1; } unlink(FN); } _exit(!flagbug); } Compile with cc -o namedpipebug namedpipebug.c Run with './namedpipebug && echo buggy' Will echo 'buggy' on FreeBSD, and nothing on, for example, Linux. >Fix: The workaround is to also open the socket for writing, as can be seen in this piece of qmail-1.03 code (from trigger.c): static int fd = -1; #ifdef HASNAMEDPIPEBUG1 static int fdw = -1; #endif void trigger_set() { if (fd != -1) close(fd); #ifdef HASNAMEDPIPEBUG1 if (fdw != -1) close(fdw); #endif fd = open_read("lock/trigger"); #ifdef HASNAMEDPIPEBUG1 fdw = open_write("lock/trigger"); #endif } >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?963420361.560147.96633.nullmailer>