Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Mar 2002 13:51:37 -0800 (PST)
From:      Lev Walkin <vlm@netli.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/36219: poll() behaves erratic on BPF file descriptors.
Message-ID:  <200203222151.g2MLpb221186@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203222151.g2MLpb221186>