[PATCH] accept AF_UNIX not blocking

Pete Wyckoff (wyckoff@ca.sandia.gov)
Mon, 13 Dec 1999 13:58:10 -0800


--5vNYLRcllDrimb99
Content-Type: text/plain; charset=us-ascii

This trivial half-liner should probably go in the kernel proper.
Attached is the satisfied user message, then his original complaint.
Patch against 2.3.31.

It's networking, but AF_UNIX, not ipv4/v6, so I'm not exactly sure
who the maintainer is.

-- Pete

--- linux/net/core/datagram.c.orig Sun Dec 12 13:30:40 1999
+++ linux/net/core/datagram.c Sun Dec 12 13:31:50 1999
@@ -82,7 +83,7 @@

/* Sequenced packets can come disconnected. If so we report the problem */
error = -ENOTCONN;
- if(connection_based(sk) && sk->state!=TCP_ESTABLISHED)
+ if(connection_based(sk) && !(sk->state==TCP_ESTABLISHED || sk->state==TCP_LISTEN))
goto out;

/* handle signals */

--5vNYLRcllDrimb99
Content-Type: text/plain; charset=us-ascii
Content-Description: happy-user-mail.txt
Content-Disposition: attachment; filename=524

Received: from california.sandia.gov (california.sandia.gov [146.246.250.1])
by dancer.ca.sandia.gov (8.9.3/8.9.3) with ESMTP id NAA12793
for <pw@dancer.ca.sandia.gov>; Mon, 13 Dec 1999 13:42:31 -0800 (PST)
Received: (from smap@localhost) by california.sandia.gov (8.8.8/1.15) id NAA10001 for <wyckoff@ca.sandia.gov>; Mon, 13 Dec 1999 13:42:30 -0800 (PST)
Received: from a235017.ext.fluke.com(208.238.235.17) by ca.sandia.gov via smap (V1.3)
id sma021866; Mon Dec 13 13:42:20 1999
Received: from 129.196.184.7 by evtvir02.tc.fluke.com (InterScan E-Mail VirusWall NT); Mon, 13 Dec 1999 13:42:10 -0800 (Pacific Standard Time)
Received: from dd.tc.fluke.com (root@dd.tc.fluke.com [129.196.148.100])
by mailhub.tc.fluke.com (8.9.3/8.9.1) with ESMTP id NAA24594;
Mon, 13 Dec 1999 13:42:10 -0800 (PST)
Received: from localhost (dcd@localhost [127.0.0.1]) by dd.tc.fluke.com (8.8.5/8.6.12) with ESMTP id NAA03400; Mon, 13 Dec 1999 13:42:11 -0800
Date: Mon, 13 Dec 1999 13:42:11 -0800 (PST)
From: David Dyck <dcd@tc.fluke.com>
To: Pete Wyckoff <wyckoff@california.sandia.gov>
cc: linux-kernel@vger.rutgers.edu, kuznet@ms2.inr.ac.ru
Subject: Pete's patch fixes accept() for me, was Re: accept() doesn't block
as it should in 2.3.x kernels
In-Reply-To: <19991212134542.A8062@dancer.ca.sandia.gov>
Message-ID: <Pine.LNX.4.05.9912131340120.192-100000@dd.tc.fluke.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII

Thanks Pete, the patch you sent fixed accept() for
me, so now perl passes lib/io_unix test as well
as my test program now blocks accept as I expect

David

On Sun, 12 Dec 1999, Pete Wyckoff wrote:

> Date: Sun, 12 Dec 1999 13:45:42 -0800
> From: Pete Wyckoff <wyckoff@ca.sandia.gov>
> To: David Dyck <dcd@tc.fluke.com>
> Cc: linux-kernel@vger.rutgers.edu, kuznet@ms2.inr.ac.ru
> Subject: Re: accept() doesn't block as it should in 2.3.x kernels
>
> dcd@tc.fluke.com said:
> >
> > The following demo code should block on the call to accept
> > but it doesn't in 2.3.x, (where x is 24,27,28,30,31, and 32pre2)
> >
> > 2.2.5, 2.2.13, and 2.2.14pre9 block as expected in accept()
> >
> > I'm getting
> > ENOTCONN "Transport endpoint is not connected"
>
> Looks like the changes to 2.3.15 did not take the accept() case into
> account.
> -- Pete
>
> --- linux/net/core/datagram.c.orig Sun Dec 12 13:30:40 1999
> +++ linux/net/core/datagram.c Sun Dec 12 13:31:50 1999
> @@ -20,6 +20,7 @@
> * Alan Cox : Datagram iovec handling
> * Darryl Miles : Fixed non-blocking SOCK_STREAM.
> * Alan Cox : POSIXisms
> + * Pete Wyckoff : Unconnected accept() fix.
> *
> */
>
> @@ -82,7 +83,7 @@
>
> /* Sequenced packets can come disconnected. If so we report the problem */
> error = -ENOTCONN;
> - if(connection_based(sk) && sk->state!=TCP_ESTABLISHED)
> + if(connection_based(sk) && !(sk->state==TCP_ESTABLISHED || sk->state==TCP_LISTEN))
> goto out;
>
> /* handle signals */
>

--5vNYLRcllDrimb99
Content-Type: text/plain; charset=us-ascii
Content-Description: original-complaint.txt
Content-Disposition: attachment; filename=516

Received: from lml.valinux.com (postfix@lml.varesearch.com [209.81.8.228])
by dancer.ca.sandia.gov (8.9.3/8.9.3) with ESMTP id XAA06253
for <pw@dancer.ca.sandia.gov>; Sat, 11 Dec 1999 23:02:11 -0800 (PST)
Received: from vger.rutgers.edu (vger.rutgers.edu [128.6.190.2])
by lml.valinux.com (Postfix) with ESMTP
id 7D02359366; Sat, 11 Dec 1999 23:05:24 -0800 (PST)
Received: by vger.rutgers.edu via listexpand id <S156697AbPLLG7o>;
Sun, 12 Dec 1999 01:59:44 -0500
Received: by vger.rutgers.edu id <S156397AbPLLG7X>;
Sun, 12 Dec 1999 01:59:23 -0500
Received: from a235017.ext.fluke.com ([208.238.235.17]:3717 "HELO
evtvir02.tc.fluke.com") by vger.rutgers.edu with SMTP
id <S156388AbPLLG7R>; Sun, 12 Dec 1999 01:59:17 -0500
Received: from 129.196.184.7 by evtvir02.tc.fluke.com (InterScan E-Mail VirusWall NT); Sat, 11 Dec 1999 22:59:16 -0800 (Pacific Standard Time)
Received: from dd.tc.fluke.com (root@dd.tc.fluke.com [129.196.148.100])
by mailhub.tc.fluke.com (8.9.3/8.9.1) with ESMTP id WAA29491
for <linux-kernel@vger.rutgers.edu>; Sat, 11 Dec 1999 22:59:15 -0800 (PST)
Received: from localhost (dcd@localhost [127.0.0.1]) by dd.tc.fluke.com (8.8.5/8.6.12) with ESMTP id WAA04321 for <linux-kernel@vger.rutgers.edu>; Sat, 11 Dec 1999 22:59:17 -0800
Date: Sat, 11 Dec 1999 22:59:17 -0800 (PST)
From: David Dyck <dcd@tc.fluke.com>
To: linux-kernel@vger.rutgers.edu
Subject: accept() doesn't block as it should in 2.3.x kernels
Message-ID: <Pine.LNX.4.05.9912111613520.166-100000@dd.tc.fluke.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Sender: owner-linux-kernel@vger.rutgers.edu
Precedence: bulk
X-Loop: majordomo@vger.rutgers.edu
X-Orcpt: rfc822;linux-kernel-outgoing-dig
Status: RO
X-Status: A
Content-Length: 1652
Lines: 69

The following demo code should block on the call to accept
but it doesn't in 2.3.x, (where x is 24,27,28,30,31, and 32pre2)

2.2.5, 2.2.13, and 2.2.14pre9 block as expected in accept()

I'm getting
ENOTCONN "Transport endpoint is not connected"

The man page for accept(2) leads me to believe that it should block

If no pending connections are present on the queue, and the
socket is not marked as non- blocking, accept blocks the
caller until a connection is present.

I discovered this when attempting to build perl for 2.3.32pre2
(I'm using libc5.4.44 if that matters)
and it failed in when testing lib/io_unix

I will appreciate your comments

Thanks again,
David Dyck

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#define PATH "/tmp/sock-test"
int main()
{
int s;
pid_t pid;
struct sockaddr_un sa = { AF_UNIX, PATH };
char *buf[1024];

unlink(PATH); /* just in case */

s = socket(AF_UNIX, SOCK_STREAM, 0);
if (s == -1) { perror("socket"); exit(1); }

if (bind(s, (struct sockaddr *)&sa,
strlen(sa.sun_path) + sizeof (sa.sun_family)) == -1)
{ perror("bind"); exit(1); }

if (listen(s, 5) == -1) { perror("listen"); exit(1); }

{
int s2;
int sa2_len;
struct sockaddr_un sa2;

if ((s2=accept(s, (struct sockaddr *)&sa2, &sa2_len)) == -1)
{perror("accept didn't block"); exit(1); }
}

return 0;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

--5vNYLRcllDrimb99--
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.rutgers.edu