aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorFlorian Zumbiehl <florz@florz.de>2007-11-29 07:19:23 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2007-11-29 07:19:23 -0500
commit0a11225887fe6cbccd882404dc36ddc50f47daf9 (patch)
tree19f23a33bcd1f794e5e4bf06d0d97f4a0f7a7533 /net
parent6ab3b487db77fa98a24560f11a5a8e744b98d877 (diff)
[UNIX]: EOF on non-blocking SOCK_SEQPACKET
I am not absolutely sure whether this actually is a bug (as in: I've got no clue what the standards say or what other implementations do), but at least I was pretty surprised when I noticed that a recv() on a non-blocking unix domain socket of type SOCK_SEQPACKET (which is connection oriented, after all) where the remote end has closed the connection returned -1 (EAGAIN) rather than 0 to indicate end of file. This is a test case: | #include <sys/types.h> | #include <unistd.h> | #include <sys/socket.h> | #include <sys/un.h> | #include <fcntl.h> | #include <string.h> | #include <stdlib.h> | | int main(){ | int sock; | struct sockaddr_un addr; | char buf[4096]; | int pfds[2]; | | pipe(pfds); | sock=socket(PF_UNIX,SOCK_SEQPACKET,0); | addr.sun_family=AF_UNIX; | strcpy(addr.sun_path,"/tmp/foobar_testsock"); | bind(sock,(struct sockaddr *)&addr,sizeof(addr)); | listen(sock,1); | if(fork()){ | close(sock); | sock=socket(PF_UNIX,SOCK_SEQPACKET,0); | connect(sock,(struct sockaddr *)&addr,sizeof(addr)); | fcntl(sock,F_SETFL,fcntl(sock,F_GETFL)|O_NONBLOCK); | close(pfds[1]); | read(pfds[0],buf,sizeof(buf)); | recv(sock,buf,sizeof(buf),0); // <-- this one | }else accept(sock,NULL,NULL); | exit(0); | } If you try it, make sure /tmp/foobar_testsock doesn't exist. The marked recv() returns -1 (EAGAIN) on 2.6.23.9. Below you find a patch that fixes that. Signed-off-by: Florian Zumbiehl <florz@florz.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'net')
-rw-r--r--net/unix/af_unix.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index e835da8fc091..060bba4567d2 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1637,8 +1637,15 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1637 mutex_lock(&u->readlock); 1637 mutex_lock(&u->readlock);
1638 1638
1639 skb = skb_recv_datagram(sk, flags, noblock, &err); 1639 skb = skb_recv_datagram(sk, flags, noblock, &err);
1640 if (!skb) 1640 if (!skb) {
1641 unix_state_lock(sk);
1642 /* Signal EOF on disconnected non-blocking SEQPACKET socket. */
1643 if (sk->sk_type == SOCK_SEQPACKET && err == -EAGAIN &&
1644 (sk->sk_shutdown & RCV_SHUTDOWN))
1645 err = 0;
1646 unix_state_unlock(sk);
1641 goto out_unlock; 1647 goto out_unlock;
1648 }
1642 1649
1643 wake_up_interruptible_sync(&u->peer_wait); 1650 wake_up_interruptible_sync(&u->peer_wait);
1644 1651