From owner-freebsd-bugs Fri Jan 18 1:50:18 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 4209B37B421 for ; Fri, 18 Jan 2002 01:50:01 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g0I9o1634326; Fri, 18 Jan 2002 01:50:01 -0800 (PST) (envelope-from gnats) Received: from mailout01.sul.t-online.com (mailout01.sul.t-online.com [194.25.134.80]) by hub.freebsd.org (Postfix) with ESMTP id 1C05937B402 for ; Fri, 18 Jan 2002 01:42:46 -0800 (PST) Received: from fwd06.sul.t-online.de by mailout01.sul.t-online.com with smtp id 16RVXp-0003qq-03; Fri, 18 Jan 2002 10:42:45 +0100 Received: from spotteswoode.dnsalias.org (520082050842-0001@[217.80.22.15]) by fmrl06.sul.t-online.com with smtp id 16RVXa-15RejYC; Fri, 18 Jan 2002 10:42:30 +0100 Received: (qmail 1721 invoked by uid 0); 18 Jan 2002 09:42:30 -0000 Message-Id: <20020118094230.GA968@spotteswoode.dnsalias.org> Date: Fri, 18 Jan 2002 10:42:30 +0100 From: clemensF To: FreeBSD-gnats-submit@freebsd.org Subject: kern/34020: poll(2) on fifos is broken Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 34020 >Category: kern >Synopsis: programs fail that poll(2) on fifos >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jan 18 01:50:00 PST 2002 >Closed-Date: >Last-Modified: >Originator: Tip Chap >Release: FreeBSD 4.3-RELEASE i386 >Organization: no >Environment: >Description: the programs below are meant to communicate a state change to multiple processes. the original idea is from paul jarc. several variants of the waiters were tested (selecting, blocking, polling). what's needed is this: readers on a fifo are supposed to wait until some writer opens it. this could be a portable, light-weight way of event- notification, where an unspecified number of readers can be realiably signalled, not loosing any signals even when they are not yet ready to receive them. it works in linux and openbsd. POSIX doesn't specify the situation (nobody does). the only alternative would be heavy machinery using SYSV-IPC or unix- signals, that would also put unbearable load on the system. >How-To-Repeat: 0 p1 root #./pipe-wait pipe & ./pipe-wait pipe & ./pipe-wait pipe & [1] 16768 [2] 16769 [3] 16770 [1] 16768 Running ./pipe-wait pipe & [2]- 16769 Running ./pipe-wait pipe & [3]+ 16770 Running ./pipe-wait pipe & 0 p1 root # [1] 16768 Done ./pipe-wait pipe [2]- 16769 Done ./pipe-wait pipe [3]+ 16770 Done ./pipe-wait pipe this behaviour is wrong, no matter which of the pipe-wait* programs is used. what i want to achieve is having any number of poll's wait until pipe-signal is invoked. this doesn't happen, as the waiters exit immediately with no error, as if data was immediately available, which is obviously wrong. 0 p1 root #ls -F pipe* pipe| pipe-wait* pipe-wait-poll* pipe-signal* pipe-wait-block* pipe-wait-poll.c* pipe-signal.c* pipe-wait-block.c* pipe-wait.c* 0 p1 root #ll pipe 29165 prw-r--r-- 1 root wheel - 0 13 Jan 18:32 pipe| 0 p1 root #./pipe-signal 1 p1 root #./pipe-signal pipe >Fix: the kernel for version 4.3 needs fixing. i am not sure if this issue has been resolved in -current. clemens fischer -------------------- 8< ----------------------- /* pipe-wait.c */ #include #include #include #include #include int main(int argc, char* argv[]) { int fd; fd_set set, empty; if (argc<2) return 1; fd=open(argv[1], O_RDONLY|O_NDELAY); if (fd<0) return 2; FD_ZERO(&empty); FD_ZERO(&set); FD_SET(fd, &set); if (select(fd+1, &set, &empty, &empty, NULL)!=1) return 3; return 0; } -------------------- 8< ----------------------- /* pipe-wait-block.c */ #include #include #include #include #include int main(int argc, char* argv[]) { int fd; fd_set set, empty; if (argc<2) return 1; fd=open(argv[1], O_RDONLY|O_NDELAY); if (fd<0) return 2; if (fcntl(fd, F_SETFL, O_RDONLY)!=0) return 3; FD_ZERO(&empty); FD_ZERO(&set); FD_SET(fd, &set); if (select(fd+1, &set, &empty, &empty, NULL)!=1) return 4; return 0; } -------------------- 8< ----------------------- /* pipe-wait-poll.c */ #include #include #include #include #include int main(int argc, char* argv[]) { int fd; struct pollfd x; if (argc<2) return 1; fd=open(argv[1], O_RDONLY|O_NDELAY); if (fd<0) return 2; if (fcntl(fd, F_SETFL, O_RDONLY)!=0) return 3; x.fd=fd; x.events=POLLIN; if (poll(&x, 1, -1)!=1) return 4; if (x.revents&POLLIN==0) return 5; return 0; } -------------------- 8< ----------------------- /* pipe-signal.c */ #include #include #include #include #include int main(int argc, char* argv[]) { if (argc<2) return 1; if (open(argv[1], O_WRONLY|O_NDELAY)<0 && errno!=ENXIO) return 2; return 0; } >Release-Note: >Audit-Trail: >Unformatted: >System: FreeBSD spotteswoode.dnsalias.org 4.3-RELEASE FreeBSD 4.3-RELEASE #13: Sun Jan 13 11:53:26 CET 2002 root@spotteswoode.dnsalias.org:/usr/src/sys/compile/n1 i386 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message