diff options
Diffstat (limited to 'net/unix/af_unix.c')
-rw-r--r-- | net/unix/af_unix.c | 87 |
1 files changed, 71 insertions, 16 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index e18cd3628db4..015606b54d9b 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
@@ -8,8 +8,6 @@ | |||
8 | * as published by the Free Software Foundation; either version | 8 | * as published by the Free Software Foundation; either version |
9 | * 2 of the License, or (at your option) any later version. | 9 | * 2 of the License, or (at your option) any later version. |
10 | * | 10 | * |
11 | * Version: $Id: af_unix.c,v 1.133 2002/02/08 03:57:19 davem Exp $ | ||
12 | * | ||
13 | * Fixes: | 11 | * Fixes: |
14 | * Linus Torvalds : Assorted bug cures. | 12 | * Linus Torvalds : Assorted bug cures. |
15 | * Niibe Yutaka : async I/O support. | 13 | * Niibe Yutaka : async I/O support. |
@@ -169,6 +167,11 @@ static inline int unix_may_send(struct sock *sk, struct sock *osk) | |||
169 | return (unix_peer(osk) == NULL || unix_our_peer(sk, osk)); | 167 | return (unix_peer(osk) == NULL || unix_our_peer(sk, osk)); |
170 | } | 168 | } |
171 | 169 | ||
170 | static inline int unix_recvq_full(struct sock const *sk) | ||
171 | { | ||
172 | return skb_queue_len(&sk->sk_receive_queue) > sk->sk_max_ack_backlog; | ||
173 | } | ||
174 | |||
172 | static struct sock *unix_peer_get(struct sock *s) | 175 | static struct sock *unix_peer_get(struct sock *s) |
173 | { | 176 | { |
174 | struct sock *peer; | 177 | struct sock *peer; |
@@ -224,7 +227,7 @@ static void __unix_remove_socket(struct sock *sk) | |||
224 | 227 | ||
225 | static void __unix_insert_socket(struct hlist_head *list, struct sock *sk) | 228 | static void __unix_insert_socket(struct hlist_head *list, struct sock *sk) |
226 | { | 229 | { |
227 | BUG_TRAP(sk_unhashed(sk)); | 230 | WARN_ON(!sk_unhashed(sk)); |
228 | sk_add_node(sk, list); | 231 | sk_add_node(sk, list); |
229 | } | 232 | } |
230 | 233 | ||
@@ -347,9 +350,9 @@ static void unix_sock_destructor(struct sock *sk) | |||
347 | 350 | ||
348 | skb_queue_purge(&sk->sk_receive_queue); | 351 | skb_queue_purge(&sk->sk_receive_queue); |
349 | 352 | ||
350 | BUG_TRAP(!atomic_read(&sk->sk_wmem_alloc)); | 353 | WARN_ON(atomic_read(&sk->sk_wmem_alloc)); |
351 | BUG_TRAP(sk_unhashed(sk)); | 354 | WARN_ON(!sk_unhashed(sk)); |
352 | BUG_TRAP(!sk->sk_socket); | 355 | WARN_ON(sk->sk_socket); |
353 | if (!sock_flag(sk, SOCK_DEAD)) { | 356 | if (!sock_flag(sk, SOCK_DEAD)) { |
354 | printk("Attempt to release alive unix socket: %p\n", sk); | 357 | printk("Attempt to release alive unix socket: %p\n", sk); |
355 | return; | 358 | return; |
@@ -482,6 +485,8 @@ static int unix_socketpair(struct socket *, struct socket *); | |||
482 | static int unix_accept(struct socket *, struct socket *, int); | 485 | static int unix_accept(struct socket *, struct socket *, int); |
483 | static int unix_getname(struct socket *, struct sockaddr *, int *, int); | 486 | static int unix_getname(struct socket *, struct sockaddr *, int *, int); |
484 | static unsigned int unix_poll(struct file *, struct socket *, poll_table *); | 487 | static unsigned int unix_poll(struct file *, struct socket *, poll_table *); |
488 | static unsigned int unix_dgram_poll(struct file *, struct socket *, | ||
489 | poll_table *); | ||
485 | static int unix_ioctl(struct socket *, unsigned int, unsigned long); | 490 | static int unix_ioctl(struct socket *, unsigned int, unsigned long); |
486 | static int unix_shutdown(struct socket *, int); | 491 | static int unix_shutdown(struct socket *, int); |
487 | static int unix_stream_sendmsg(struct kiocb *, struct socket *, | 492 | static int unix_stream_sendmsg(struct kiocb *, struct socket *, |
@@ -527,7 +532,7 @@ static const struct proto_ops unix_dgram_ops = { | |||
527 | .socketpair = unix_socketpair, | 532 | .socketpair = unix_socketpair, |
528 | .accept = sock_no_accept, | 533 | .accept = sock_no_accept, |
529 | .getname = unix_getname, | 534 | .getname = unix_getname, |
530 | .poll = datagram_poll, | 535 | .poll = unix_dgram_poll, |
531 | .ioctl = unix_ioctl, | 536 | .ioctl = unix_ioctl, |
532 | .listen = sock_no_listen, | 537 | .listen = sock_no_listen, |
533 | .shutdown = unix_shutdown, | 538 | .shutdown = unix_shutdown, |
@@ -548,7 +553,7 @@ static const struct proto_ops unix_seqpacket_ops = { | |||
548 | .socketpair = unix_socketpair, | 553 | .socketpair = unix_socketpair, |
549 | .accept = unix_accept, | 554 | .accept = unix_accept, |
550 | .getname = unix_getname, | 555 | .getname = unix_getname, |
551 | .poll = datagram_poll, | 556 | .poll = unix_dgram_poll, |
552 | .ioctl = unix_ioctl, | 557 | .ioctl = unix_ioctl, |
553 | .listen = unix_listen, | 558 | .listen = unix_listen, |
554 | .shutdown = unix_shutdown, | 559 | .shutdown = unix_shutdown, |
@@ -598,7 +603,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock) | |||
598 | u->dentry = NULL; | 603 | u->dentry = NULL; |
599 | u->mnt = NULL; | 604 | u->mnt = NULL; |
600 | spin_lock_init(&u->lock); | 605 | spin_lock_init(&u->lock); |
601 | atomic_set(&u->inflight, 0); | 606 | atomic_long_set(&u->inflight, 0); |
602 | INIT_LIST_HEAD(&u->link); | 607 | INIT_LIST_HEAD(&u->link); |
603 | mutex_init(&u->readlock); /* single task reading lock */ | 608 | mutex_init(&u->readlock); /* single task reading lock */ |
604 | init_waitqueue_head(&u->peer_wait); | 609 | init_waitqueue_head(&u->peer_wait); |
@@ -983,8 +988,7 @@ static long unix_wait_for_peer(struct sock *other, long timeo) | |||
983 | 988 | ||
984 | sched = !sock_flag(other, SOCK_DEAD) && | 989 | sched = !sock_flag(other, SOCK_DEAD) && |
985 | !(other->sk_shutdown & RCV_SHUTDOWN) && | 990 | !(other->sk_shutdown & RCV_SHUTDOWN) && |
986 | (skb_queue_len(&other->sk_receive_queue) > | 991 | unix_recvq_full(other); |
987 | other->sk_max_ack_backlog); | ||
988 | 992 | ||
989 | unix_state_unlock(other); | 993 | unix_state_unlock(other); |
990 | 994 | ||
@@ -1058,8 +1062,7 @@ restart: | |||
1058 | if (other->sk_state != TCP_LISTEN) | 1062 | if (other->sk_state != TCP_LISTEN) |
1059 | goto out_unlock; | 1063 | goto out_unlock; |
1060 | 1064 | ||
1061 | if (skb_queue_len(&other->sk_receive_queue) > | 1065 | if (unix_recvq_full(other)) { |
1062 | other->sk_max_ack_backlog) { | ||
1063 | err = -EAGAIN; | 1066 | err = -EAGAIN; |
1064 | if (!timeo) | 1067 | if (!timeo) |
1065 | goto out_unlock; | 1068 | goto out_unlock; |
@@ -1428,9 +1431,7 @@ restart: | |||
1428 | goto out_unlock; | 1431 | goto out_unlock; |
1429 | } | 1432 | } |
1430 | 1433 | ||
1431 | if (unix_peer(other) != sk && | 1434 | if (unix_peer(other) != sk && unix_recvq_full(other)) { |
1432 | (skb_queue_len(&other->sk_receive_queue) > | ||
1433 | other->sk_max_ack_backlog)) { | ||
1434 | if (!timeo) { | 1435 | if (!timeo) { |
1435 | err = -EAGAIN; | 1436 | err = -EAGAIN; |
1436 | goto out_unlock; | 1437 | goto out_unlock; |
@@ -1991,6 +1992,60 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl | |||
1991 | return mask; | 1992 | return mask; |
1992 | } | 1993 | } |
1993 | 1994 | ||
1995 | static unsigned int unix_dgram_poll(struct file *file, struct socket *sock, | ||
1996 | poll_table *wait) | ||
1997 | { | ||
1998 | struct sock *sk = sock->sk, *other; | ||
1999 | unsigned int mask, writable; | ||
2000 | |||
2001 | poll_wait(file, sk->sk_sleep, wait); | ||
2002 | mask = 0; | ||
2003 | |||
2004 | /* exceptional events? */ | ||
2005 | if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) | ||
2006 | mask |= POLLERR; | ||
2007 | if (sk->sk_shutdown & RCV_SHUTDOWN) | ||
2008 | mask |= POLLRDHUP; | ||
2009 | if (sk->sk_shutdown == SHUTDOWN_MASK) | ||
2010 | mask |= POLLHUP; | ||
2011 | |||
2012 | /* readable? */ | ||
2013 | if (!skb_queue_empty(&sk->sk_receive_queue) || | ||
2014 | (sk->sk_shutdown & RCV_SHUTDOWN)) | ||
2015 | mask |= POLLIN | POLLRDNORM; | ||
2016 | |||
2017 | /* Connection-based need to check for termination and startup */ | ||
2018 | if (sk->sk_type == SOCK_SEQPACKET) { | ||
2019 | if (sk->sk_state == TCP_CLOSE) | ||
2020 | mask |= POLLHUP; | ||
2021 | /* connection hasn't started yet? */ | ||
2022 | if (sk->sk_state == TCP_SYN_SENT) | ||
2023 | return mask; | ||
2024 | } | ||
2025 | |||
2026 | /* writable? */ | ||
2027 | writable = unix_writable(sk); | ||
2028 | if (writable) { | ||
2029 | other = unix_peer_get(sk); | ||
2030 | if (other) { | ||
2031 | if (unix_peer(other) != sk) { | ||
2032 | poll_wait(file, &unix_sk(other)->peer_wait, | ||
2033 | wait); | ||
2034 | if (unix_recvq_full(other)) | ||
2035 | writable = 0; | ||
2036 | } | ||
2037 | |||
2038 | sock_put(other); | ||
2039 | } | ||
2040 | } | ||
2041 | |||
2042 | if (writable) | ||
2043 | mask |= POLLOUT | POLLWRNORM | POLLWRBAND; | ||
2044 | else | ||
2045 | set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); | ||
2046 | |||
2047 | return mask; | ||
2048 | } | ||
1994 | 2049 | ||
1995 | #ifdef CONFIG_PROC_FS | 2050 | #ifdef CONFIG_PROC_FS |
1996 | static struct sock *first_unix_socket(int *i) | 2051 | static struct sock *first_unix_socket(int *i) |