From owner-freebsd-bugs Fri Mar 22 14: 0:54 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 6EDBB37B632 for ; Fri, 22 Mar 2002 14:00:01 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g2MM01V28911; Fri, 22 Mar 2002 14:00:01 -0800 (PST) (envelope-from gnats) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 123E837B419 for ; Fri, 22 Mar 2002 13:51:37 -0800 (PST) Received: (from nobody@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g2MLpb221186; Fri, 22 Mar 2002 13:51:37 -0800 (PST) (envelope-from nobody) Message-Id: <200203222151.g2MLpb221186@freefall.freebsd.org> Date: Fri, 22 Mar 2002 13:51:37 -0800 (PST) From: Lev Walkin To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: kern/36219: poll() behaves erratic on BPF file descriptors. 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: 36219 >Category: kern >Synopsis: poll() behaves erratic on BPF file descriptors. >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Mar 22 14:00:01 PST 2002 >Closed-Date: >Last-Modified: >Originator: Lev Walkin >Release: FreeBSD-4.5 >Organization: Netli, Inc. >Environment: FreeBSD shelty.netli.lan 4.5-RELEASE FreeBSD 4.5-RELEASE #5: Fri Mar 22 13:29:20 PST 2002 root@shelty.netli.lan:/usr/src/sys/compile/BSD i386 Previous versions of FreeBSD does not have this problem. >Description: poll() and select() system calls constantly returning POLLIN or POLLRDNORM on BPF file descriptors, even if there is no data available. Subsequent read() would return EAGAIN. This behaviour breaks multithreaded programs (using standart user-level threads in libc_r), because their read() uses poll(). >How-To-Repeat: just try to use poll() with events=POLLIN at opened file descriptor. it will always return revents & POLLIN, despite of the data availability. >Fix: Fix bpfpoll() function in /sys/net/bpf.c: === --- bpf.c.old Fri Mar 22 13:48:18 2002 +++ bpf.c Fri Mar 22 13:48:42 2002 @@ -1085,7 +1085,7 @@ if (d->bd_bif == NULL) return (ENXIO); - revents = events & (POLLIN | POLLWRNORM); + revents = events & (POLLOUT | POLLWRNORM); s = splimp(); if (events & (POLLIN | POLLRDNORM)) { /* @@ -1094,11 +1094,12 @@ * if (d->b_slen != 0 || * (d->bd_hbuf != NULL && d->bd_hlen != 0) */ - if (d->bd_hlen != 0 || - ((d->bd_immediate || d->bd_state == BPF_TIMED_OUT) && - d->bd_slen != 0)) + if (d->bd_hlen != 0 + || (d->bd_immediate && d->bd_slen != 0) + || d->bd_state == BPF_TIMED_OUT + ) { revents |= events & (POLLIN | POLLRDNORM); - else { + } else { selrecord(p, &d->bd_sel); /* Start the read timeout if necessary. */ if (d->bd_rtout > 0 && d->bd_state == BPF_IDLE) { >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message