[lkml]   [2000]   [Sep]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Subject[2.4][2.2] Bug: accept discards socket options/O_NONBLOCK
Please mind the To: and Cc: headers. If there are relevant followups,
please send me a Cc: as I'm only subscribed to the linux-kernel and dns
mailing lists.

In some debugging, Pavel Kankovsky and Daniel J. Bernstein have tracked
down a Linux Kernel bug that I can confirm for 2.2.17 and 2.4.0-test8 (I
did not try 2.0.38, don't have gcc installed). I have copies of
their mail (without Received: headers) available (see below).

(This is for IPv4, someone would have to check IPv6 as well).
The socket flag O_NONBLOCK is _NOT_ properly inherited through an
accept(2) call, in spite of what socket(7) documents. This is a bug.
accept(2) must copy the file descriptor's flag of the socket.

SOCKET(7) EXCERPT: (from man pages 1.31)
It is possible to do non-blocking IO on sockets by setting the
O_NONBLOCK flag on a socket file descriptor using fcntl(2).
O_NONBLOCK is inherited through an accept. Then all operations
that would normally block will (usu­ ally) return with EAGAIN;
connect(2) returns an EIN­ PROGRESS error in this case. The user
can then wait for various events via poll(2) or select(2).

At, there is a small test
program (3 kB) that is not really portable, and that relies on
dnscache for library functions (it's a quick hack).

Build it on Linux 2.2 or Linux 2.4.0-test8 and see this: (I'm running
./socktest 1234 & telnet localhost 1234)

options on socket (fd=3): O_NONBLOCK
options after accept (fd=6):
accepted from

It SHOULD be: (FreeBSD 4.0 gets it right):
options on socket (fd=3): O_NONBLOCK
options after accept (fd=4): O_NONBLOCK
accepted from

To compile the program on FreeBSD 4, comment out the line with O_SYNC
and insert #include <poll.h>; compilation instructions are at the head
of that file.

test program is at
dnscache source code is at (78 kB).
Pavel's mail is at
Dan's mail is at

Matthias Andree
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 12:38    [W:0.064 / U:28.416 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site