aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix/af_unix.c
diff options
context:
space:
mode:
authorLachlan McIlroy <lachlan@redback.melbourne.sgi.com>2008-12-29 00:47:18 -0500
committerLachlan McIlroy <lachlan@redback.melbourne.sgi.com>2008-12-29 00:47:18 -0500
commit0a8c5395f90f06d128247844b2515c8bf3f2826b (patch)
treed95382dcdfa303b99d480c01763d6cb6767fdaca /net/unix/af_unix.c
parent25051158bbed127e8672b43396c71c5eb610e5f1 (diff)
parent3c92ec8ae91ecf59d88c798301833d7cf83f2179 (diff)
[XFS] Fix merge failures
Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6 Conflicts: fs/xfs/linux-2.6/xfs_cred.h fs/xfs/linux-2.6/xfs_globals.h fs/xfs/linux-2.6/xfs_ioctl.c fs/xfs/xfs_vnodeops.h Signed-off-by: Lachlan McIlroy <lachlan@sgi.com>
Diffstat (limited to 'net/unix/af_unix.c')
-rw-r--r--net/unix/af_unix.c211
1 files changed, 105 insertions, 106 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 66d5ac4773a..c6250d0055d 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -164,7 +164,7 @@ static inline int unix_our_peer(struct sock *sk, struct sock *osk)
164 164
165static inline int unix_may_send(struct sock *sk, struct sock *osk) 165static inline int unix_may_send(struct sock *sk, struct sock *osk)
166{ 166{
167 return (unix_peer(osk) == NULL || unix_our_peer(sk, osk)); 167 return unix_peer(osk) == NULL || unix_our_peer(sk, osk);
168} 168}
169 169
170static inline int unix_recvq_full(struct sock const *sk) 170static inline int unix_recvq_full(struct sock const *sk)
@@ -197,7 +197,7 @@ static inline void unix_release_addr(struct unix_address *addr)
197 * - if started by zero, it is abstract name. 197 * - if started by zero, it is abstract name.
198 */ 198 */
199 199
200static int unix_mkname(struct sockaddr_un * sunaddr, int len, unsigned *hashp) 200static int unix_mkname(struct sockaddr_un *sunaddr, int len, unsigned *hashp)
201{ 201{
202 if (len <= sizeof(short) || len > sizeof(*sunaddr)) 202 if (len <= sizeof(short) || len > sizeof(*sunaddr))
203 return -EINVAL; 203 return -EINVAL;
@@ -211,12 +211,12 @@ static int unix_mkname(struct sockaddr_un * sunaddr, int len, unsigned *hashp)
211 * we are guaranteed that it is a valid memory location in our 211 * we are guaranteed that it is a valid memory location in our
212 * kernel address buffer. 212 * kernel address buffer.
213 */ 213 */
214 ((char *)sunaddr)[len]=0; 214 ((char *)sunaddr)[len] = 0;
215 len = strlen(sunaddr->sun_path)+1+sizeof(short); 215 len = strlen(sunaddr->sun_path)+1+sizeof(short);
216 return len; 216 return len;
217 } 217 }
218 218
219 *hashp = unix_hash_fold(csum_partial((char*)sunaddr, len, 0)); 219 *hashp = unix_hash_fold(csum_partial(sunaddr, len, 0));
220 return len; 220 return len;
221} 221}
222 222
@@ -295,8 +295,7 @@ static struct sock *unix_find_socket_byinode(struct net *net, struct inode *i)
295 if (!net_eq(sock_net(s), net)) 295 if (!net_eq(sock_net(s), net))
296 continue; 296 continue;
297 297
298 if(dentry && dentry->d_inode == i) 298 if (dentry && dentry->d_inode == i) {
299 {
300 sock_hold(s); 299 sock_hold(s);
301 goto found; 300 goto found;
302 } 301 }
@@ -354,7 +353,7 @@ static void unix_sock_destructor(struct sock *sk)
354 WARN_ON(!sk_unhashed(sk)); 353 WARN_ON(!sk_unhashed(sk));
355 WARN_ON(sk->sk_socket); 354 WARN_ON(sk->sk_socket);
356 if (!sock_flag(sk, SOCK_DEAD)) { 355 if (!sock_flag(sk, SOCK_DEAD)) {
357 printk("Attempt to release alive unix socket: %p\n", sk); 356 printk(KERN_INFO "Attempt to release alive unix socket: %p\n", sk);
358 return; 357 return;
359 } 358 }
360 359
@@ -362,12 +361,16 @@ static void unix_sock_destructor(struct sock *sk)
362 unix_release_addr(u->addr); 361 unix_release_addr(u->addr);
363 362
364 atomic_dec(&unix_nr_socks); 363 atomic_dec(&unix_nr_socks);
364 local_bh_disable();
365 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
366 local_bh_enable();
365#ifdef UNIX_REFCNT_DEBUG 367#ifdef UNIX_REFCNT_DEBUG
366 printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk, atomic_read(&unix_nr_socks)); 368 printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk,
369 atomic_read(&unix_nr_socks));
367#endif 370#endif
368} 371}
369 372
370static int unix_release_sock (struct sock *sk, int embrion) 373static int unix_release_sock(struct sock *sk, int embrion)
371{ 374{
372 struct unix_sock *u = unix_sk(sk); 375 struct unix_sock *u = unix_sk(sk);
373 struct dentry *dentry; 376 struct dentry *dentry;
@@ -392,9 +395,9 @@ static int unix_release_sock (struct sock *sk, int embrion)
392 395
393 wake_up_interruptible_all(&u->peer_wait); 396 wake_up_interruptible_all(&u->peer_wait);
394 397
395 skpair=unix_peer(sk); 398 skpair = unix_peer(sk);
396 399
397 if (skpair!=NULL) { 400 if (skpair != NULL) {
398 if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) { 401 if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) {
399 unix_state_lock(skpair); 402 unix_state_lock(skpair);
400 /* No more writes */ 403 /* No more writes */
@@ -414,7 +417,7 @@ static int unix_release_sock (struct sock *sk, int embrion)
414 /* Try to flush out this socket. Throw out buffers at least */ 417 /* Try to flush out this socket. Throw out buffers at least */
415 418
416 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { 419 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
417 if (state==TCP_LISTEN) 420 if (state == TCP_LISTEN)
418 unix_release_sock(skb->sk, 1); 421 unix_release_sock(skb->sk, 1);
419 /* passed fds are erased in the kfree_skb hook */ 422 /* passed fds are erased in the kfree_skb hook */
420 kfree_skb(skb); 423 kfree_skb(skb);
@@ -453,11 +456,11 @@ static int unix_listen(struct socket *sock, int backlog)
453 struct unix_sock *u = unix_sk(sk); 456 struct unix_sock *u = unix_sk(sk);
454 457
455 err = -EOPNOTSUPP; 458 err = -EOPNOTSUPP;
456 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET) 459 if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET)
457 goto out; /* Only stream/seqpacket sockets accept */ 460 goto out; /* Only stream/seqpacket sockets accept */
458 err = -EINVAL; 461 err = -EINVAL;
459 if (!u->addr) 462 if (!u->addr)
460 goto out; /* No listens on an unbound socket */ 463 goto out; /* No listens on an unbound socket */
461 unix_state_lock(sk); 464 unix_state_lock(sk);
462 if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN) 465 if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN)
463 goto out_unlock; 466 goto out_unlock;
@@ -467,8 +470,7 @@ static int unix_listen(struct socket *sock, int backlog)
467 sk->sk_state = TCP_LISTEN; 470 sk->sk_state = TCP_LISTEN;
468 /* set credentials so connect can copy them */ 471 /* set credentials so connect can copy them */
469 sk->sk_peercred.pid = task_tgid_vnr(current); 472 sk->sk_peercred.pid = task_tgid_vnr(current);
470 sk->sk_peercred.uid = current->euid; 473 current_euid_egid(&sk->sk_peercred.uid, &sk->sk_peercred.gid);
471 sk->sk_peercred.gid = current->egid;
472 err = 0; 474 err = 0;
473 475
474out_unlock: 476out_unlock:
@@ -566,9 +568,9 @@ static const struct proto_ops unix_seqpacket_ops = {
566}; 568};
567 569
568static struct proto unix_proto = { 570static struct proto unix_proto = {
569 .name = "UNIX", 571 .name = "UNIX",
570 .owner = THIS_MODULE, 572 .owner = THIS_MODULE,
571 .obj_size = sizeof(struct unix_sock), 573 .obj_size = sizeof(struct unix_sock),
572}; 574};
573 575
574/* 576/*
@@ -579,7 +581,7 @@ static struct proto unix_proto = {
579 */ 581 */
580static struct lock_class_key af_unix_sk_receive_queue_lock_key; 582static struct lock_class_key af_unix_sk_receive_queue_lock_key;
581 583
582static struct sock * unix_create1(struct net *net, struct socket *sock) 584static struct sock *unix_create1(struct net *net, struct socket *sock)
583{ 585{
584 struct sock *sk = NULL; 586 struct sock *sk = NULL;
585 struct unix_sock *u; 587 struct unix_sock *u;
@@ -592,7 +594,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
592 if (!sk) 594 if (!sk)
593 goto out; 595 goto out;
594 596
595 sock_init_data(sock,sk); 597 sock_init_data(sock, sk);
596 lockdep_set_class(&sk->sk_receive_queue.lock, 598 lockdep_set_class(&sk->sk_receive_queue.lock,
597 &af_unix_sk_receive_queue_lock_key); 599 &af_unix_sk_receive_queue_lock_key);
598 600
@@ -611,6 +613,11 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
611out: 613out:
612 if (sk == NULL) 614 if (sk == NULL)
613 atomic_dec(&unix_nr_socks); 615 atomic_dec(&unix_nr_socks);
616 else {
617 local_bh_disable();
618 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
619 local_bh_enable();
620 }
614 return sk; 621 return sk;
615} 622}
616 623
@@ -630,7 +637,7 @@ static int unix_create(struct net *net, struct socket *sock, int protocol)
630 * nothing uses it. 637 * nothing uses it.
631 */ 638 */
632 case SOCK_RAW: 639 case SOCK_RAW:
633 sock->type=SOCK_DGRAM; 640 sock->type = SOCK_DGRAM;
634 case SOCK_DGRAM: 641 case SOCK_DGRAM:
635 sock->ops = &unix_dgram_ops; 642 sock->ops = &unix_dgram_ops;
636 break; 643 break;
@@ -653,7 +660,7 @@ static int unix_release(struct socket *sock)
653 660
654 sock->sk = NULL; 661 sock->sk = NULL;
655 662
656 return unix_release_sock (sk, 0); 663 return unix_release_sock(sk, 0);
657} 664}
658 665
659static int unix_autobind(struct socket *sock) 666static int unix_autobind(struct socket *sock)
@@ -662,7 +669,7 @@ static int unix_autobind(struct socket *sock)
662 struct net *net = sock_net(sk); 669 struct net *net = sock_net(sk);
663 struct unix_sock *u = unix_sk(sk); 670 struct unix_sock *u = unix_sk(sk);
664 static u32 ordernum = 1; 671 static u32 ordernum = 1;
665 struct unix_address * addr; 672 struct unix_address *addr;
666 int err; 673 int err;
667 674
668 mutex_lock(&u->readlock); 675 mutex_lock(&u->readlock);
@@ -681,7 +688,7 @@ static int unix_autobind(struct socket *sock)
681 688
682retry: 689retry:
683 addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short); 690 addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short);
684 addr->hash = unix_hash_fold(csum_partial((void*)addr->name, addr->len, 0)); 691 addr->hash = unix_hash_fold(csum_partial(addr->name, addr->len, 0));
685 692
686 spin_lock(&unix_table_lock); 693 spin_lock(&unix_table_lock);
687 ordernum = (ordernum+1)&0xFFFFF; 694 ordernum = (ordernum+1)&0xFFFFF;
@@ -736,14 +743,14 @@ static struct sock *unix_find_other(struct net *net,
736 743
737 path_put(&path); 744 path_put(&path);
738 745
739 err=-EPROTOTYPE; 746 err = -EPROTOTYPE;
740 if (u->sk_type != type) { 747 if (u->sk_type != type) {
741 sock_put(u); 748 sock_put(u);
742 goto fail; 749 goto fail;
743 } 750 }
744 } else { 751 } else {
745 err = -ECONNREFUSED; 752 err = -ECONNREFUSED;
746 u=unix_find_socket_byname(net, sunname, len, type, hash); 753 u = unix_find_socket_byname(net, sunname, len, type, hash);
747 if (u) { 754 if (u) {
748 struct dentry *dentry; 755 struct dentry *dentry;
749 dentry = unix_sk(u)->dentry; 756 dentry = unix_sk(u)->dentry;
@@ -757,7 +764,7 @@ static struct sock *unix_find_other(struct net *net,
757put_fail: 764put_fail:
758 path_put(&path); 765 path_put(&path);
759fail: 766fail:
760 *error=err; 767 *error = err;
761 return NULL; 768 return NULL;
762} 769}
763 770
@@ -767,8 +774,8 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
767 struct sock *sk = sock->sk; 774 struct sock *sk = sock->sk;
768 struct net *net = sock_net(sk); 775 struct net *net = sock_net(sk);
769 struct unix_sock *u = unix_sk(sk); 776 struct unix_sock *u = unix_sk(sk);
770 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 777 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
771 struct dentry * dentry = NULL; 778 struct dentry *dentry = NULL;
772 struct nameidata nd; 779 struct nameidata nd;
773 int err; 780 int err;
774 unsigned hash; 781 unsigned hash;
@@ -779,7 +786,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
779 if (sunaddr->sun_family != AF_UNIX) 786 if (sunaddr->sun_family != AF_UNIX)
780 goto out; 787 goto out;
781 788
782 if (addr_len==sizeof(short)) { 789 if (addr_len == sizeof(short)) {
783 err = unix_autobind(sock); 790 err = unix_autobind(sock);
784 goto out; 791 goto out;
785 } 792 }
@@ -875,8 +882,8 @@ out_mknod_unlock:
875 mutex_unlock(&nd.path.dentry->d_inode->i_mutex); 882 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
876 path_put(&nd.path); 883 path_put(&nd.path);
877out_mknod_parent: 884out_mknod_parent:
878 if (err==-EEXIST) 885 if (err == -EEXIST)
879 err=-EADDRINUSE; 886 err = -EADDRINUSE;
880 unix_release_addr(addr); 887 unix_release_addr(addr);
881 goto out_up; 888 goto out_up;
882} 889}
@@ -911,7 +918,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
911{ 918{
912 struct sock *sk = sock->sk; 919 struct sock *sk = sock->sk;
913 struct net *net = sock_net(sk); 920 struct net *net = sock_net(sk);
914 struct sockaddr_un *sunaddr=(struct sockaddr_un*)addr; 921 struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr;
915 struct sock *other; 922 struct sock *other;
916 unsigned hash; 923 unsigned hash;
917 int err; 924 int err;
@@ -927,7 +934,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
927 goto out; 934 goto out;
928 935
929restart: 936restart:
930 other=unix_find_other(net, sunaddr, alen, sock->type, hash, &err); 937 other = unix_find_other(net, sunaddr, alen, sock->type, hash, &err);
931 if (!other) 938 if (!other)
932 goto out; 939 goto out;
933 940
@@ -961,14 +968,14 @@ restart:
961 */ 968 */
962 if (unix_peer(sk)) { 969 if (unix_peer(sk)) {
963 struct sock *old_peer = unix_peer(sk); 970 struct sock *old_peer = unix_peer(sk);
964 unix_peer(sk)=other; 971 unix_peer(sk) = other;
965 unix_state_double_unlock(sk, other); 972 unix_state_double_unlock(sk, other);
966 973
967 if (other != old_peer) 974 if (other != old_peer)
968 unix_dgram_disconnected(sk, old_peer); 975 unix_dgram_disconnected(sk, old_peer);
969 sock_put(old_peer); 976 sock_put(old_peer);
970 } else { 977 } else {
971 unix_peer(sk)=other; 978 unix_peer(sk) = other;
972 unix_state_double_unlock(sk, other); 979 unix_state_double_unlock(sk, other);
973 } 980 }
974 return 0; 981 return 0;
@@ -1004,7 +1011,7 @@ static long unix_wait_for_peer(struct sock *other, long timeo)
1004static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, 1011static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
1005 int addr_len, int flags) 1012 int addr_len, int flags)
1006{ 1013{
1007 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 1014 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
1008 struct sock *sk = sock->sk; 1015 struct sock *sk = sock->sk;
1009 struct net *net = sock_net(sk); 1016 struct net *net = sock_net(sk);
1010 struct unix_sock *u = unix_sk(sk), *newu, *otheru; 1017 struct unix_sock *u = unix_sk(sk), *newu, *otheru;
@@ -1126,8 +1133,7 @@ restart:
1126 newsk->sk_state = TCP_ESTABLISHED; 1133 newsk->sk_state = TCP_ESTABLISHED;
1127 newsk->sk_type = sk->sk_type; 1134 newsk->sk_type = sk->sk_type;
1128 newsk->sk_peercred.pid = task_tgid_vnr(current); 1135 newsk->sk_peercred.pid = task_tgid_vnr(current);
1129 newsk->sk_peercred.uid = current->euid; 1136 current_euid_egid(&newsk->sk_peercred.uid, &newsk->sk_peercred.gid);
1130 newsk->sk_peercred.gid = current->egid;
1131 newu = unix_sk(newsk); 1137 newu = unix_sk(newsk);
1132 newsk->sk_sleep = &newu->peer_wait; 1138 newsk->sk_sleep = &newu->peer_wait;
1133 otheru = unix_sk(other); 1139 otheru = unix_sk(other);
@@ -1179,16 +1185,17 @@ out:
1179 1185
1180static int unix_socketpair(struct socket *socka, struct socket *sockb) 1186static int unix_socketpair(struct socket *socka, struct socket *sockb)
1181{ 1187{
1182 struct sock *ska=socka->sk, *skb = sockb->sk; 1188 struct sock *ska = socka->sk, *skb = sockb->sk;
1183 1189
1184 /* Join our sockets back to back */ 1190 /* Join our sockets back to back */
1185 sock_hold(ska); 1191 sock_hold(ska);
1186 sock_hold(skb); 1192 sock_hold(skb);
1187 unix_peer(ska)=skb; 1193 unix_peer(ska) = skb;
1188 unix_peer(skb)=ska; 1194 unix_peer(skb) = ska;
1189 ska->sk_peercred.pid = skb->sk_peercred.pid = task_tgid_vnr(current); 1195 ska->sk_peercred.pid = skb->sk_peercred.pid = task_tgid_vnr(current);
1190 ska->sk_peercred.uid = skb->sk_peercred.uid = current->euid; 1196 current_euid_egid(&skb->sk_peercred.uid, &skb->sk_peercred.gid);
1191 ska->sk_peercred.gid = skb->sk_peercred.gid = current->egid; 1197 ska->sk_peercred.uid = skb->sk_peercred.uid;
1198 ska->sk_peercred.gid = skb->sk_peercred.gid;
1192 1199
1193 if (ska->sk_type != SOCK_DGRAM) { 1200 if (ska->sk_type != SOCK_DGRAM) {
1194 ska->sk_state = TCP_ESTABLISHED; 1201 ska->sk_state = TCP_ESTABLISHED;
@@ -1207,7 +1214,7 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags)
1207 int err; 1214 int err;
1208 1215
1209 err = -EOPNOTSUPP; 1216 err = -EOPNOTSUPP;
1210 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET) 1217 if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET)
1211 goto out; 1218 goto out;
1212 1219
1213 err = -EINVAL; 1220 err = -EINVAL;
@@ -1246,7 +1253,7 @@ static int unix_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_
1246{ 1253{
1247 struct sock *sk = sock->sk; 1254 struct sock *sk = sock->sk;
1248 struct unix_sock *u; 1255 struct unix_sock *u;
1249 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 1256 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
1250 int err = 0; 1257 int err = 0;
1251 1258
1252 if (peer) { 1259 if (peer) {
@@ -1286,7 +1293,7 @@ static void unix_detach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1286 skb->destructor = sock_wfree; 1293 skb->destructor = sock_wfree;
1287 UNIXCB(skb).fp = NULL; 1294 UNIXCB(skb).fp = NULL;
1288 1295
1289 for (i=scm->fp->count-1; i>=0; i--) 1296 for (i = scm->fp->count-1; i >= 0; i--)
1290 unix_notinflight(scm->fp->fp[i]); 1297 unix_notinflight(scm->fp->fp[i]);
1291} 1298}
1292 1299
@@ -1315,7 +1322,7 @@ static int unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1315 if (!UNIXCB(skb).fp) 1322 if (!UNIXCB(skb).fp)
1316 return -ENOMEM; 1323 return -ENOMEM;
1317 1324
1318 for (i=scm->fp->count-1; i>=0; i--) 1325 for (i = scm->fp->count-1; i >= 0; i--)
1319 unix_inflight(scm->fp->fp[i]); 1326 unix_inflight(scm->fp->fp[i]);
1320 skb->destructor = unix_destruct_fds; 1327 skb->destructor = unix_destruct_fds;
1321 return 0; 1328 return 0;
@@ -1332,7 +1339,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1332 struct sock *sk = sock->sk; 1339 struct sock *sk = sock->sk;
1333 struct net *net = sock_net(sk); 1340 struct net *net = sock_net(sk);
1334 struct unix_sock *u = unix_sk(sk); 1341 struct unix_sock *u = unix_sk(sk);
1335 struct sockaddr_un *sunaddr=msg->msg_name; 1342 struct sockaddr_un *sunaddr = msg->msg_name;
1336 struct sock *other = NULL; 1343 struct sock *other = NULL;
1337 int namelen = 0; /* fake GCC */ 1344 int namelen = 0; /* fake GCC */
1338 int err; 1345 int err;
@@ -1374,7 +1381,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1374 goto out; 1381 goto out;
1375 1382
1376 skb = sock_alloc_send_skb(sk, len, msg->msg_flags&MSG_DONTWAIT, &err); 1383 skb = sock_alloc_send_skb(sk, len, msg->msg_flags&MSG_DONTWAIT, &err);
1377 if (skb==NULL) 1384 if (skb == NULL)
1378 goto out; 1385 goto out;
1379 1386
1380 memcpy(UNIXCREDS(skb), &siocb->scm->creds, sizeof(struct ucred)); 1387 memcpy(UNIXCREDS(skb), &siocb->scm->creds, sizeof(struct ucred));
@@ -1386,7 +1393,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1386 unix_get_secdata(siocb->scm, skb); 1393 unix_get_secdata(siocb->scm, skb);
1387 1394
1388 skb_reset_transport_header(skb); 1395 skb_reset_transport_header(skb);
1389 err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len); 1396 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
1390 if (err) 1397 if (err)
1391 goto out_free; 1398 goto out_free;
1392 1399
@@ -1400,7 +1407,7 @@ restart:
1400 1407
1401 other = unix_find_other(net, sunaddr, namelen, sk->sk_type, 1408 other = unix_find_other(net, sunaddr, namelen, sk->sk_type,
1402 hash, &err); 1409 hash, &err);
1403 if (other==NULL) 1410 if (other == NULL)
1404 goto out_free; 1411 goto out_free;
1405 } 1412 }
1406 1413
@@ -1420,7 +1427,7 @@ restart:
1420 err = 0; 1427 err = 0;
1421 unix_state_lock(sk); 1428 unix_state_lock(sk);
1422 if (unix_peer(sk) == other) { 1429 if (unix_peer(sk) == other) {
1423 unix_peer(sk)=NULL; 1430 unix_peer(sk) = NULL;
1424 unix_state_unlock(sk); 1431 unix_state_unlock(sk);
1425 1432
1426 unix_dgram_disconnected(sk, other); 1433 unix_dgram_disconnected(sk, other);
@@ -1486,10 +1493,10 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1486 struct sock_iocb *siocb = kiocb_to_siocb(kiocb); 1493 struct sock_iocb *siocb = kiocb_to_siocb(kiocb);
1487 struct sock *sk = sock->sk; 1494 struct sock *sk = sock->sk;
1488 struct sock *other = NULL; 1495 struct sock *other = NULL;
1489 struct sockaddr_un *sunaddr=msg->msg_name; 1496 struct sockaddr_un *sunaddr = msg->msg_name;
1490 int err,size; 1497 int err, size;
1491 struct sk_buff *skb; 1498 struct sk_buff *skb;
1492 int sent=0; 1499 int sent = 0;
1493 struct scm_cookie tmp_scm; 1500 struct scm_cookie tmp_scm;
1494 1501
1495 if (NULL == siocb->scm) 1502 if (NULL == siocb->scm)
@@ -1517,8 +1524,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1517 if (sk->sk_shutdown & SEND_SHUTDOWN) 1524 if (sk->sk_shutdown & SEND_SHUTDOWN)
1518 goto pipe_err; 1525 goto pipe_err;
1519 1526
1520 while(sent < len) 1527 while (sent < len) {
1521 {
1522 /* 1528 /*
1523 * Optimisation for the fact that under 0.01% of X 1529 * Optimisation for the fact that under 0.01% of X
1524 * messages typically need breaking up. 1530 * messages typically need breaking up.
@@ -1537,9 +1543,10 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1537 * Grab a buffer 1543 * Grab a buffer
1538 */ 1544 */
1539 1545
1540 skb=sock_alloc_send_skb(sk,size,msg->msg_flags&MSG_DONTWAIT, &err); 1546 skb = sock_alloc_send_skb(sk, size, msg->msg_flags&MSG_DONTWAIT,
1547 &err);
1541 1548
1542 if (skb==NULL) 1549 if (skb == NULL)
1543 goto out_err; 1550 goto out_err;
1544 1551
1545 /* 1552 /*
@@ -1560,7 +1567,8 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1560 } 1567 }
1561 } 1568 }
1562 1569
1563 if ((err = memcpy_fromiovec(skb_put(skb,size), msg->msg_iov, size)) != 0) { 1570 err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size);
1571 if (err) {
1564 kfree_skb(skb); 1572 kfree_skb(skb);
1565 goto out_err; 1573 goto out_err;
1566 } 1574 }
@@ -1574,7 +1582,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1574 skb_queue_tail(&other->sk_receive_queue, skb); 1582 skb_queue_tail(&other->sk_receive_queue, skb);
1575 unix_state_unlock(other); 1583 unix_state_unlock(other);
1576 other->sk_data_ready(other, size); 1584 other->sk_data_ready(other, size);
1577 sent+=size; 1585 sent += size;
1578 } 1586 }
1579 1587
1580 scm_destroy(siocb->scm); 1588 scm_destroy(siocb->scm);
@@ -1586,8 +1594,8 @@ pipe_err_free:
1586 unix_state_unlock(other); 1594 unix_state_unlock(other);
1587 kfree_skb(skb); 1595 kfree_skb(skb);
1588pipe_err: 1596pipe_err:
1589 if (sent==0 && !(msg->msg_flags&MSG_NOSIGNAL)) 1597 if (sent == 0 && !(msg->msg_flags&MSG_NOSIGNAL))
1590 send_sig(SIGPIPE,current,0); 1598 send_sig(SIGPIPE, current, 0);
1591 err = -EPIPE; 1599 err = -EPIPE;
1592out_err: 1600out_err:
1593 scm_destroy(siocb->scm); 1601 scm_destroy(siocb->scm);
@@ -1677,13 +1685,10 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1677 siocb->scm->creds = *UNIXCREDS(skb); 1685 siocb->scm->creds = *UNIXCREDS(skb);
1678 unix_set_secdata(siocb->scm, skb); 1686 unix_set_secdata(siocb->scm, skb);
1679 1687
1680 if (!(flags & MSG_PEEK)) 1688 if (!(flags & MSG_PEEK)) {
1681 {
1682 if (UNIXCB(skb).fp) 1689 if (UNIXCB(skb).fp)
1683 unix_detach_fds(siocb->scm, skb); 1690 unix_detach_fds(siocb->scm, skb);
1684 } 1691 } else {
1685 else
1686 {
1687 /* It is questionable: on PEEK we could: 1692 /* It is questionable: on PEEK we could:
1688 - do not return fds - good, but too simple 8) 1693 - do not return fds - good, but too simple 8)
1689 - return fds, and do not return them on read (old strategy, 1694 - return fds, and do not return them on read (old strategy,
@@ -1704,7 +1709,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1704 scm_recv(sock, msg, siocb->scm, flags); 1709 scm_recv(sock, msg, siocb->scm, flags);
1705 1710
1706out_free: 1711out_free:
1707 skb_free_datagram(sk,skb); 1712 skb_free_datagram(sk, skb);
1708out_unlock: 1713out_unlock:
1709 mutex_unlock(&u->readlock); 1714 mutex_unlock(&u->readlock);
1710out: 1715out:
@@ -1715,7 +1720,7 @@ out:
1715 * Sleep until data has arrive. But check for races.. 1720 * Sleep until data has arrive. But check for races..
1716 */ 1721 */
1717 1722
1718static long unix_stream_data_wait(struct sock * sk, long timeo) 1723static long unix_stream_data_wait(struct sock *sk, long timeo)
1719{ 1724{
1720 DEFINE_WAIT(wait); 1725 DEFINE_WAIT(wait);
1721 1726
@@ -1753,7 +1758,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1753 struct scm_cookie tmp_scm; 1758 struct scm_cookie tmp_scm;
1754 struct sock *sk = sock->sk; 1759 struct sock *sk = sock->sk;
1755 struct unix_sock *u = unix_sk(sk); 1760 struct unix_sock *u = unix_sk(sk);
1756 struct sockaddr_un *sunaddr=msg->msg_name; 1761 struct sockaddr_un *sunaddr = msg->msg_name;
1757 int copied = 0; 1762 int copied = 0;
1758 int check_creds = 0; 1763 int check_creds = 0;
1759 int target; 1764 int target;
@@ -1784,15 +1789,13 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1784 1789
1785 mutex_lock(&u->readlock); 1790 mutex_lock(&u->readlock);
1786 1791
1787 do 1792 do {
1788 {
1789 int chunk; 1793 int chunk;
1790 struct sk_buff *skb; 1794 struct sk_buff *skb;
1791 1795
1792 unix_state_lock(sk); 1796 unix_state_lock(sk);
1793 skb = skb_dequeue(&sk->sk_receive_queue); 1797 skb = skb_dequeue(&sk->sk_receive_queue);
1794 if (skb==NULL) 1798 if (skb == NULL) {
1795 {
1796 if (copied >= target) 1799 if (copied >= target)
1797 goto unlock; 1800 goto unlock;
1798 1801
@@ -1800,7 +1803,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1800 * POSIX 1003.1g mandates this order. 1803 * POSIX 1003.1g mandates this order.
1801 */ 1804 */
1802 1805
1803 if ((err = sock_error(sk)) != 0) 1806 err = sock_error(sk);
1807 if (err)
1804 goto unlock; 1808 goto unlock;
1805 if (sk->sk_shutdown & RCV_SHUTDOWN) 1809 if (sk->sk_shutdown & RCV_SHUTDOWN)
1806 goto unlock; 1810 goto unlock;
@@ -1827,7 +1831,8 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1827 1831
1828 if (check_creds) { 1832 if (check_creds) {
1829 /* Never glue messages from different writers */ 1833 /* Never glue messages from different writers */
1830 if (memcmp(UNIXCREDS(skb), &siocb->scm->creds, sizeof(siocb->scm->creds)) != 0) { 1834 if (memcmp(UNIXCREDS(skb), &siocb->scm->creds,
1835 sizeof(siocb->scm->creds)) != 0) {
1831 skb_queue_head(&sk->sk_receive_queue, skb); 1836 skb_queue_head(&sk->sk_receive_queue, skb);
1832 break; 1837 break;
1833 } 1838 }
@@ -1838,8 +1843,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1838 } 1843 }
1839 1844
1840 /* Copy address just once */ 1845 /* Copy address just once */
1841 if (sunaddr) 1846 if (sunaddr) {
1842 {
1843 unix_copy_addr(msg, skb->sk); 1847 unix_copy_addr(msg, skb->sk);
1844 sunaddr = NULL; 1848 sunaddr = NULL;
1845 } 1849 }
@@ -1855,16 +1859,14 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1855 size -= chunk; 1859 size -= chunk;
1856 1860
1857 /* Mark read part of skb as used */ 1861 /* Mark read part of skb as used */
1858 if (!(flags & MSG_PEEK)) 1862 if (!(flags & MSG_PEEK)) {
1859 {
1860 skb_pull(skb, chunk); 1863 skb_pull(skb, chunk);
1861 1864
1862 if (UNIXCB(skb).fp) 1865 if (UNIXCB(skb).fp)
1863 unix_detach_fds(siocb->scm, skb); 1866 unix_detach_fds(siocb->scm, skb);
1864 1867
1865 /* put the skb back if we didn't use it up.. */ 1868 /* put the skb back if we didn't use it up.. */
1866 if (skb->len) 1869 if (skb->len) {
1867 {
1868 skb_queue_head(&sk->sk_receive_queue, skb); 1870 skb_queue_head(&sk->sk_receive_queue, skb);
1869 break; 1871 break;
1870 } 1872 }
@@ -1873,9 +1875,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1873 1875
1874 if (siocb->scm->fp) 1876 if (siocb->scm->fp)
1875 break; 1877 break;
1876 } 1878 } else {
1877 else
1878 {
1879 /* It is questionable, see note in unix_dgram_recvmsg. 1879 /* It is questionable, see note in unix_dgram_recvmsg.
1880 */ 1880 */
1881 if (UNIXCB(skb).fp) 1881 if (UNIXCB(skb).fp)
@@ -1903,7 +1903,7 @@ static int unix_shutdown(struct socket *sock, int mode)
1903 if (mode) { 1903 if (mode) {
1904 unix_state_lock(sk); 1904 unix_state_lock(sk);
1905 sk->sk_shutdown |= mode; 1905 sk->sk_shutdown |= mode;
1906 other=unix_peer(sk); 1906 other = unix_peer(sk);
1907 if (other) 1907 if (other)
1908 sock_hold(other); 1908 sock_hold(other);
1909 unix_state_unlock(sk); 1909 unix_state_unlock(sk);
@@ -1938,16 +1938,15 @@ static int unix_shutdown(struct socket *sock, int mode)
1938static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 1938static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1939{ 1939{
1940 struct sock *sk = sock->sk; 1940 struct sock *sk = sock->sk;
1941 long amount=0; 1941 long amount = 0;
1942 int err; 1942 int err;
1943 1943
1944 switch(cmd) 1944 switch (cmd) {
1945 { 1945 case SIOCOUTQ:
1946 case SIOCOUTQ: 1946 amount = atomic_read(&sk->sk_wmem_alloc);
1947 amount = atomic_read(&sk->sk_wmem_alloc); 1947 err = put_user(amount, (int __user *)arg);
1948 err = put_user(amount, (int __user *)arg); 1948 break;
1949 break; 1949 case SIOCINQ:
1950 case SIOCINQ:
1951 { 1950 {
1952 struct sk_buff *skb; 1951 struct sk_buff *skb;
1953 1952
@@ -1964,21 +1963,21 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1964 } else { 1963 } else {
1965 skb = skb_peek(&sk->sk_receive_queue); 1964 skb = skb_peek(&sk->sk_receive_queue);
1966 if (skb) 1965 if (skb)
1967 amount=skb->len; 1966 amount = skb->len;
1968 } 1967 }
1969 spin_unlock(&sk->sk_receive_queue.lock); 1968 spin_unlock(&sk->sk_receive_queue.lock);
1970 err = put_user(amount, (int __user *)arg); 1969 err = put_user(amount, (int __user *)arg);
1971 break; 1970 break;
1972 } 1971 }
1973 1972
1974 default: 1973 default:
1975 err = -ENOIOCTLCMD; 1974 err = -ENOIOCTLCMD;
1976 break; 1975 break;
1977 } 1976 }
1978 return err; 1977 return err;
1979} 1978}
1980 1979
1981static unsigned int unix_poll(struct file * file, struct socket *sock, poll_table *wait) 1980static unsigned int unix_poll(struct file *file, struct socket *sock, poll_table *wait)
1982{ 1981{
1983 struct sock *sk = sock->sk; 1982 struct sock *sk = sock->sk;
1984 unsigned int mask; 1983 unsigned int mask;
@@ -2000,7 +1999,8 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl
2000 mask |= POLLIN | POLLRDNORM; 1999 mask |= POLLIN | POLLRDNORM;
2001 2000
2002 /* Connection-based need to check for termination and startup */ 2001 /* Connection-based need to check for termination and startup */
2003 if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) && sk->sk_state == TCP_CLOSE) 2002 if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) &&
2003 sk->sk_state == TCP_CLOSE)
2004 mask |= POLLHUP; 2004 mask |= POLLHUP;
2005 2005
2006 /* 2006 /*
@@ -2096,6 +2096,7 @@ struct unix_iter_state {
2096 struct seq_net_private p; 2096 struct seq_net_private p;
2097 int i; 2097 int i;
2098}; 2098};
2099
2099static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos) 2100static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos)
2100{ 2101{
2101 struct unix_iter_state *iter = seq->private; 2102 struct unix_iter_state *iter = seq->private;
@@ -2112,7 +2113,6 @@ static struct sock *unix_seq_idx(struct seq_file *seq, loff_t pos)
2112 return NULL; 2113 return NULL;
2113} 2114}
2114 2115
2115
2116static void *unix_seq_start(struct seq_file *seq, loff_t *pos) 2116static void *unix_seq_start(struct seq_file *seq, loff_t *pos)
2117 __acquires(unix_table_lock) 2117 __acquires(unix_table_lock)
2118{ 2118{
@@ -2192,7 +2192,6 @@ static const struct seq_operations unix_seq_ops = {
2192 .show = unix_seq_show, 2192 .show = unix_seq_show,
2193}; 2193};
2194 2194
2195
2196static int unix_seq_open(struct inode *inode, struct file *file) 2195static int unix_seq_open(struct inode *inode, struct file *file)
2197{ 2196{
2198 return seq_open_net(inode, file, &unix_seq_ops, 2197 return seq_open_net(inode, file, &unix_seq_ops,