Home | History | Annotate | Line # | Download | only in kern
uipc_usrreq.c revision 1.20
      1  1.20   mycroft /*	$NetBSD: uipc_usrreq.c,v 1.20 1996/05/23 16:03:45 mycroft Exp $	*/
      2  1.10       cgd 
      3   1.1       cgd /*
      4   1.8   mycroft  * Copyright (c) 1982, 1986, 1989, 1991, 1993
      5   1.8   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  *
     35  1.10       cgd  *	@(#)uipc_usrreq.c	8.3 (Berkeley) 1/4/94
     36   1.1       cgd  */
     37   1.1       cgd 
     38   1.7   mycroft #include <sys/param.h>
     39   1.8   mycroft #include <sys/systm.h>
     40   1.7   mycroft #include <sys/proc.h>
     41   1.7   mycroft #include <sys/filedesc.h>
     42   1.7   mycroft #include <sys/domain.h>
     43   1.7   mycroft #include <sys/protosw.h>
     44   1.7   mycroft #include <sys/socket.h>
     45   1.7   mycroft #include <sys/socketvar.h>
     46   1.7   mycroft #include <sys/unpcb.h>
     47   1.7   mycroft #include <sys/un.h>
     48   1.7   mycroft #include <sys/namei.h>
     49   1.7   mycroft #include <sys/vnode.h>
     50   1.7   mycroft #include <sys/file.h>
     51   1.7   mycroft #include <sys/stat.h>
     52   1.7   mycroft #include <sys/mbuf.h>
     53   1.1       cgd 
     54   1.1       cgd /*
     55   1.1       cgd  * Unix communications domain.
     56   1.1       cgd  *
     57   1.1       cgd  * TODO:
     58   1.1       cgd  *	SEQPACKET, RDM
     59   1.1       cgd  *	rethink name space problems
     60   1.1       cgd  *	need a proper out-of-band
     61   1.1       cgd  */
     62  1.20   mycroft struct	sockaddr_un sun_noname = { sizeof(sun_noname), AF_UNIX };
     63   1.1       cgd ino_t	unp_ino;			/* prototype for fake inode numbers */
     64   1.1       cgd 
     65  1.20   mycroft int
     66  1.20   mycroft unp_output(m, control, unp)
     67  1.20   mycroft 	struct mbuf *m, *control;
     68  1.20   mycroft 	struct unpcb *unp;
     69  1.20   mycroft {
     70  1.20   mycroft 	struct socket *so2;
     71  1.20   mycroft 	struct sockaddr_un *sun;
     72  1.20   mycroft 
     73  1.20   mycroft 	so2 = unp->unp_conn->unp_socket;
     74  1.20   mycroft 	if (unp->unp_addr)
     75  1.20   mycroft 		sun = unp->unp_addr;
     76  1.20   mycroft 	else
     77  1.20   mycroft 		sun = &sun_noname;
     78  1.20   mycroft 	if (sbappendaddr(&so2->so_rcv, (struct sockaddr *)sun, m,
     79  1.20   mycroft 	    control) == 0) {
     80  1.20   mycroft 		m_freem(control);
     81  1.20   mycroft 		m_freem(m);
     82  1.20   mycroft 		return (EINVAL);
     83  1.20   mycroft 	} else {
     84  1.20   mycroft 		sorwakeup(so2);
     85  1.20   mycroft 		return (0);
     86  1.20   mycroft 	}
     87  1.20   mycroft }
     88  1.20   mycroft 
     89  1.20   mycroft void
     90  1.20   mycroft unp_setsockaddr(unp, nam)
     91  1.20   mycroft 	register struct unpcb *unp;
     92  1.20   mycroft 	struct mbuf *nam;
     93  1.20   mycroft {
     94  1.20   mycroft 	struct sockaddr_un *sun;
     95  1.20   mycroft 
     96  1.20   mycroft 	if (unp->unp_addr)
     97  1.20   mycroft 		sun = unp->unp_addr;
     98  1.20   mycroft 	else
     99  1.20   mycroft 		sun = &sun_noname;
    100  1.20   mycroft 	nam->m_len = sun->sun_len;
    101  1.20   mycroft 	bcopy(sun, mtod(nam, caddr_t), (size_t)nam->m_len);
    102  1.20   mycroft }
    103  1.20   mycroft 
    104  1.20   mycroft void
    105  1.20   mycroft unp_setpeeraddr(unp, nam)
    106  1.20   mycroft 	register struct unpcb *unp;
    107  1.20   mycroft 	struct mbuf *nam;
    108  1.20   mycroft {
    109  1.20   mycroft 	struct sockaddr_un *sun;
    110  1.20   mycroft 
    111  1.20   mycroft 	if (unp->unp_conn && unp->unp_conn->unp_addr)
    112  1.20   mycroft 		sun = unp->unp_conn->unp_addr;
    113  1.20   mycroft 	else
    114  1.20   mycroft 		sun = &sun_noname;
    115  1.20   mycroft 	nam->m_len = sun->sun_len;
    116  1.20   mycroft 	bcopy(sun, mtod(nam, caddr_t), (size_t)nam->m_len);
    117  1.20   mycroft }
    118  1.20   mycroft 
    119   1.1       cgd /*ARGSUSED*/
    120   1.5    andrew int
    121  1.19   mycroft uipc_usrreq(so, req, m, nam, control, p)
    122   1.1       cgd 	struct socket *so;
    123   1.1       cgd 	int req;
    124   1.1       cgd 	struct mbuf *m, *nam, *control;
    125  1.19   mycroft 	struct proc *p;
    126   1.1       cgd {
    127   1.1       cgd 	struct unpcb *unp = sotounpcb(so);
    128   1.1       cgd 	register struct socket *so2;
    129   1.1       cgd 	register int error = 0;
    130   1.1       cgd 
    131   1.1       cgd 	if (req == PRU_CONTROL)
    132   1.1       cgd 		return (EOPNOTSUPP);
    133  1.20   mycroft 
    134   1.1       cgd 	if (req != PRU_SEND && control && control->m_len) {
    135   1.1       cgd 		error = EOPNOTSUPP;
    136   1.1       cgd 		goto release;
    137   1.1       cgd 	}
    138   1.1       cgd 	if (unp == 0 && req != PRU_ATTACH) {
    139   1.1       cgd 		error = EINVAL;
    140   1.1       cgd 		goto release;
    141   1.1       cgd 	}
    142  1.20   mycroft 
    143   1.1       cgd 	switch (req) {
    144   1.1       cgd 
    145   1.1       cgd 	case PRU_ATTACH:
    146  1.20   mycroft 		if (unp != 0) {
    147   1.1       cgd 			error = EISCONN;
    148   1.1       cgd 			break;
    149   1.1       cgd 		}
    150   1.1       cgd 		error = unp_attach(so);
    151   1.1       cgd 		break;
    152   1.1       cgd 
    153   1.1       cgd 	case PRU_DETACH:
    154   1.1       cgd 		unp_detach(unp);
    155   1.1       cgd 		break;
    156   1.1       cgd 
    157   1.1       cgd 	case PRU_BIND:
    158   1.1       cgd 		error = unp_bind(unp, nam, p);
    159   1.1       cgd 		break;
    160   1.1       cgd 
    161   1.1       cgd 	case PRU_LISTEN:
    162   1.1       cgd 		if (unp->unp_vnode == 0)
    163   1.1       cgd 			error = EINVAL;
    164   1.1       cgd 		break;
    165   1.1       cgd 
    166   1.1       cgd 	case PRU_CONNECT:
    167   1.1       cgd 		error = unp_connect(so, nam, p);
    168   1.1       cgd 		break;
    169   1.1       cgd 
    170   1.1       cgd 	case PRU_CONNECT2:
    171   1.1       cgd 		error = unp_connect2(so, (struct socket *)nam);
    172   1.1       cgd 		break;
    173   1.1       cgd 
    174   1.1       cgd 	case PRU_DISCONNECT:
    175   1.1       cgd 		unp_disconnect(unp);
    176   1.1       cgd 		break;
    177   1.1       cgd 
    178   1.1       cgd 	case PRU_ACCEPT:
    179  1.20   mycroft 		unp_setpeeraddr(unp, nam);
    180   1.1       cgd 		break;
    181   1.1       cgd 
    182   1.1       cgd 	case PRU_SHUTDOWN:
    183   1.1       cgd 		socantsendmore(so);
    184   1.1       cgd 		unp_shutdown(unp);
    185   1.1       cgd 		break;
    186   1.1       cgd 
    187   1.1       cgd 	case PRU_RCVD:
    188   1.1       cgd 		switch (so->so_type) {
    189   1.1       cgd 
    190   1.1       cgd 		case SOCK_DGRAM:
    191   1.1       cgd 			panic("uipc 1");
    192   1.1       cgd 			/*NOTREACHED*/
    193   1.1       cgd 
    194   1.1       cgd 		case SOCK_STREAM:
    195   1.1       cgd #define	rcv (&so->so_rcv)
    196   1.1       cgd #define snd (&so2->so_snd)
    197   1.1       cgd 			if (unp->unp_conn == 0)
    198   1.1       cgd 				break;
    199   1.1       cgd 			so2 = unp->unp_conn->unp_socket;
    200   1.1       cgd 			/*
    201   1.1       cgd 			 * Adjust backpressure on sender
    202   1.1       cgd 			 * and wakeup any waiting to write.
    203   1.1       cgd 			 */
    204   1.1       cgd 			snd->sb_mbmax += unp->unp_mbcnt - rcv->sb_mbcnt;
    205   1.1       cgd 			unp->unp_mbcnt = rcv->sb_mbcnt;
    206   1.1       cgd 			snd->sb_hiwat += unp->unp_cc - rcv->sb_cc;
    207   1.1       cgd 			unp->unp_cc = rcv->sb_cc;
    208   1.1       cgd 			sowwakeup(so2);
    209   1.1       cgd #undef snd
    210   1.1       cgd #undef rcv
    211   1.1       cgd 			break;
    212   1.1       cgd 
    213   1.1       cgd 		default:
    214   1.1       cgd 			panic("uipc 2");
    215   1.1       cgd 		}
    216   1.1       cgd 		break;
    217   1.1       cgd 
    218   1.1       cgd 	case PRU_SEND:
    219   1.1       cgd 		if (control && (error = unp_internalize(control, p)))
    220   1.1       cgd 			break;
    221   1.1       cgd 		switch (so->so_type) {
    222   1.1       cgd 
    223   1.1       cgd 		case SOCK_DGRAM: {
    224   1.1       cgd 			if (nam) {
    225  1.20   mycroft 				if ((so->so_state & SS_ISCONNECTED) != 0) {
    226  1.20   mycroft 					m_freem(m);
    227   1.1       cgd 					error = EISCONN;
    228   1.1       cgd 					break;
    229   1.1       cgd 				}
    230   1.1       cgd 				error = unp_connect(so, nam, p);
    231  1.20   mycroft 				if (error) {
    232  1.20   mycroft 					m_freem(m);
    233   1.1       cgd 					break;
    234  1.20   mycroft 				}
    235   1.1       cgd 			} else {
    236  1.20   mycroft 				if ((so->so_state & SS_ISCONNECTED) == 0) {
    237  1.20   mycroft 					m_freem(m);
    238   1.1       cgd 					error = ENOTCONN;
    239   1.1       cgd 					break;
    240   1.1       cgd 				}
    241   1.1       cgd 			}
    242  1.20   mycroft 			error = unp_output(m, control, unp);
    243   1.1       cgd 			if (nam)
    244   1.1       cgd 				unp_disconnect(unp);
    245   1.1       cgd 			break;
    246   1.1       cgd 		}
    247   1.1       cgd 
    248   1.1       cgd 		case SOCK_STREAM:
    249   1.1       cgd #define	rcv (&so2->so_rcv)
    250   1.1       cgd #define	snd (&so->so_snd)
    251   1.1       cgd 			if (so->so_state & SS_CANTSENDMORE) {
    252   1.1       cgd 				error = EPIPE;
    253   1.1       cgd 				break;
    254   1.1       cgd 			}
    255   1.1       cgd 			if (unp->unp_conn == 0)
    256   1.1       cgd 				panic("uipc 3");
    257   1.1       cgd 			so2 = unp->unp_conn->unp_socket;
    258   1.1       cgd 			/*
    259   1.1       cgd 			 * Send to paired receive port, and then reduce
    260   1.1       cgd 			 * send buffer hiwater marks to maintain backpressure.
    261   1.1       cgd 			 * Wake up readers.
    262   1.1       cgd 			 */
    263   1.1       cgd 			if (control) {
    264   1.1       cgd 				if (sbappendcontrol(rcv, m, control))
    265   1.1       cgd 					control = 0;
    266   1.1       cgd 			} else
    267   1.1       cgd 				sbappend(rcv, m);
    268   1.1       cgd 			snd->sb_mbmax -=
    269   1.1       cgd 			    rcv->sb_mbcnt - unp->unp_conn->unp_mbcnt;
    270   1.1       cgd 			unp->unp_conn->unp_mbcnt = rcv->sb_mbcnt;
    271   1.1       cgd 			snd->sb_hiwat -= rcv->sb_cc - unp->unp_conn->unp_cc;
    272   1.1       cgd 			unp->unp_conn->unp_cc = rcv->sb_cc;
    273   1.1       cgd 			sorwakeup(so2);
    274   1.1       cgd 			m = 0;
    275   1.1       cgd #undef snd
    276   1.1       cgd #undef rcv
    277   1.1       cgd 			break;
    278   1.1       cgd 
    279   1.1       cgd 		default:
    280   1.1       cgd 			panic("uipc 4");
    281   1.1       cgd 		}
    282   1.1       cgd 		break;
    283   1.1       cgd 
    284   1.1       cgd 	case PRU_ABORT:
    285   1.1       cgd 		unp_drop(unp, ECONNABORTED);
    286   1.1       cgd 		break;
    287   1.1       cgd 
    288   1.1       cgd 	case PRU_SENSE:
    289   1.1       cgd 		((struct stat *) m)->st_blksize = so->so_snd.sb_hiwat;
    290   1.1       cgd 		if (so->so_type == SOCK_STREAM && unp->unp_conn != 0) {
    291   1.1       cgd 			so2 = unp->unp_conn->unp_socket;
    292   1.1       cgd 			((struct stat *) m)->st_blksize += so2->so_rcv.sb_cc;
    293   1.1       cgd 		}
    294   1.1       cgd 		((struct stat *) m)->st_dev = NODEV;
    295   1.1       cgd 		if (unp->unp_ino == 0)
    296   1.1       cgd 			unp->unp_ino = unp_ino++;
    297   1.1       cgd 		((struct stat *) m)->st_ino = unp->unp_ino;
    298   1.1       cgd 		return (0);
    299   1.1       cgd 
    300   1.1       cgd 	case PRU_RCVOOB:
    301  1.20   mycroft 		error = EOPNOTSUPP;
    302  1.20   mycroft 		break;
    303   1.1       cgd 
    304   1.1       cgd 	case PRU_SENDOOB:
    305  1.20   mycroft 		m_freem(m);
    306   1.1       cgd 		error = EOPNOTSUPP;
    307   1.1       cgd 		break;
    308   1.1       cgd 
    309   1.1       cgd 	case PRU_SOCKADDR:
    310  1.20   mycroft 		unp_setsockaddr(unp, nam);
    311   1.1       cgd 		break;
    312   1.1       cgd 
    313   1.1       cgd 	case PRU_PEERADDR:
    314  1.20   mycroft 		unp_setpeeraddr(unp, nam);
    315   1.1       cgd 		break;
    316   1.1       cgd 
    317   1.1       cgd 	default:
    318   1.1       cgd 		panic("piusrreq");
    319   1.1       cgd 	}
    320  1.20   mycroft 
    321   1.1       cgd release:
    322   1.1       cgd 	return (error);
    323   1.1       cgd }
    324   1.1       cgd 
    325   1.1       cgd /*
    326   1.1       cgd  * Both send and receive buffers are allocated PIPSIZ bytes of buffering
    327   1.1       cgd  * for stream sockets, although the total for sender and receiver is
    328   1.1       cgd  * actually only PIPSIZ.
    329   1.1       cgd  * Datagram sockets really use the sendspace as the maximum datagram size,
    330   1.1       cgd  * and don't really want to reserve the sendspace.  Their recvspace should
    331   1.1       cgd  * be large enough for at least one max-size datagram plus address.
    332   1.1       cgd  */
    333   1.1       cgd #define	PIPSIZ	4096
    334   1.1       cgd u_long	unpst_sendspace = PIPSIZ;
    335   1.1       cgd u_long	unpst_recvspace = PIPSIZ;
    336   1.1       cgd u_long	unpdg_sendspace = 2*1024;	/* really max datagram size */
    337   1.1       cgd u_long	unpdg_recvspace = 4*1024;
    338   1.1       cgd 
    339   1.1       cgd int	unp_rights;			/* file descriptors in flight */
    340   1.1       cgd 
    341   1.5    andrew int
    342   1.1       cgd unp_attach(so)
    343   1.1       cgd 	struct socket *so;
    344   1.1       cgd {
    345   1.1       cgd 	register struct unpcb *unp;
    346   1.1       cgd 	int error;
    347   1.1       cgd 
    348   1.1       cgd 	if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
    349   1.1       cgd 		switch (so->so_type) {
    350   1.1       cgd 
    351   1.1       cgd 		case SOCK_STREAM:
    352   1.1       cgd 			error = soreserve(so, unpst_sendspace, unpst_recvspace);
    353   1.1       cgd 			break;
    354   1.1       cgd 
    355   1.1       cgd 		case SOCK_DGRAM:
    356   1.1       cgd 			error = soreserve(so, unpdg_sendspace, unpdg_recvspace);
    357   1.1       cgd 			break;
    358   1.8   mycroft 
    359   1.8   mycroft 		default:
    360   1.8   mycroft 			panic("unp_attach");
    361   1.1       cgd 		}
    362   1.1       cgd 		if (error)
    363   1.1       cgd 			return (error);
    364   1.1       cgd 	}
    365  1.14   mycroft 	unp = malloc(sizeof(*unp), M_PCB, M_NOWAIT);
    366  1.14   mycroft 	if (unp == NULL)
    367   1.1       cgd 		return (ENOBUFS);
    368  1.14   mycroft 	bzero((caddr_t)unp, sizeof(*unp));
    369  1.14   mycroft 	unp->unp_socket = so;
    370  1.15   mycroft 	so->so_pcb = unp;
    371   1.1       cgd 	return (0);
    372   1.1       cgd }
    373   1.1       cgd 
    374  1.17        pk void
    375   1.1       cgd unp_detach(unp)
    376   1.1       cgd 	register struct unpcb *unp;
    377   1.1       cgd {
    378   1.1       cgd 
    379   1.1       cgd 	if (unp->unp_vnode) {
    380   1.1       cgd 		unp->unp_vnode->v_socket = 0;
    381   1.1       cgd 		vrele(unp->unp_vnode);
    382   1.1       cgd 		unp->unp_vnode = 0;
    383   1.1       cgd 	}
    384   1.1       cgd 	if (unp->unp_conn)
    385   1.1       cgd 		unp_disconnect(unp);
    386   1.1       cgd 	while (unp->unp_refs)
    387   1.1       cgd 		unp_drop(unp->unp_refs, ECONNRESET);
    388   1.1       cgd 	soisdisconnected(unp->unp_socket);
    389   1.1       cgd 	unp->unp_socket->so_pcb = 0;
    390  1.20   mycroft 	if (unp->unp_addr)
    391  1.20   mycroft 		m_freem(dtom(unp->unp_addr));
    392   1.8   mycroft 	if (unp_rights) {
    393   1.8   mycroft 		/*
    394   1.8   mycroft 		 * Normally the receive buffer is flushed later,
    395   1.8   mycroft 		 * in sofree, but if our receive buffer holds references
    396   1.8   mycroft 		 * to descriptors that are now garbage, we will dispose
    397   1.8   mycroft 		 * of those descriptor references after the garbage collector
    398   1.8   mycroft 		 * gets them (resulting in a "panic: closef: count < 0").
    399   1.8   mycroft 		 */
    400   1.8   mycroft 		sorflush(unp->unp_socket);
    401  1.14   mycroft 		free(unp, M_PCB);
    402   1.1       cgd 		unp_gc();
    403  1.14   mycroft 	} else
    404  1.14   mycroft 		free(unp, M_PCB);
    405   1.1       cgd }
    406   1.1       cgd 
    407   1.5    andrew int
    408   1.1       cgd unp_bind(unp, nam, p)
    409   1.1       cgd 	struct unpcb *unp;
    410   1.1       cgd 	struct mbuf *nam;
    411   1.1       cgd 	struct proc *p;
    412   1.1       cgd {
    413  1.20   mycroft 	struct sockaddr_un *sun = mtod(nam, struct sockaddr_un *);
    414   1.1       cgd 	register struct vnode *vp;
    415   1.1       cgd 	struct vattr vattr;
    416   1.1       cgd 	int error;
    417   1.1       cgd 	struct nameidata nd;
    418   1.1       cgd 
    419  1.20   mycroft 	if (unp->unp_vnode != 0)
    420  1.20   mycroft 		return (EINVAL);
    421   1.9   mycroft 	NDINIT(&nd, CREATE, FOLLOW | LOCKPARENT, UIO_SYSSPACE,
    422  1.20   mycroft 	    sun->sun_path, p);
    423  1.20   mycroft 	if (nam->m_data + nam->m_len == &nam->m_dat[MLEN]) {	/* XXX */
    424   1.1       cgd 		if (*(mtod(nam, caddr_t) + nam->m_len - 1) != 0)
    425   1.1       cgd 			return (EINVAL);
    426   1.1       cgd 	} else
    427   1.1       cgd 		*(mtod(nam, caddr_t) + nam->m_len) = 0;
    428   1.1       cgd /* SHOULD BE ABLE TO ADOPT EXISTING AND wakeup() ALA FIFO's */
    429  1.16  christos 	if ((error = namei(&nd)) != 0)
    430   1.1       cgd 		return (error);
    431   1.9   mycroft 	vp = nd.ni_vp;
    432   1.1       cgd 	if (vp != NULL) {
    433   1.9   mycroft 		VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd);
    434   1.9   mycroft 		if (nd.ni_dvp == vp)
    435   1.9   mycroft 			vrele(nd.ni_dvp);
    436   1.1       cgd 		else
    437   1.9   mycroft 			vput(nd.ni_dvp);
    438   1.1       cgd 		vrele(vp);
    439   1.1       cgd 		return (EADDRINUSE);
    440   1.1       cgd 	}
    441   1.1       cgd 	VATTR_NULL(&vattr);
    442   1.1       cgd 	vattr.va_type = VSOCK;
    443   1.9   mycroft 	vattr.va_mode = ACCESSPERMS;
    444  1.12   mycroft 	VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
    445  1.16  christos 	error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
    446  1.16  christos 	if (error)
    447   1.1       cgd 		return (error);
    448   1.9   mycroft 	vp = nd.ni_vp;
    449   1.1       cgd 	vp->v_socket = unp->unp_socket;
    450   1.1       cgd 	unp->unp_vnode = vp;
    451  1.20   mycroft 	unp->unp_addr =
    452  1.20   mycroft 	    mtod(m_copy(nam, 0, (int)M_COPYALL), struct sockaddr_un *);
    453   1.1       cgd 	VOP_UNLOCK(vp);
    454   1.1       cgd 	return (0);
    455   1.1       cgd }
    456   1.1       cgd 
    457   1.5    andrew int
    458   1.1       cgd unp_connect(so, nam, p)
    459   1.1       cgd 	struct socket *so;
    460   1.1       cgd 	struct mbuf *nam;
    461   1.1       cgd 	struct proc *p;
    462   1.1       cgd {
    463  1.20   mycroft 	register struct sockaddr_un *sun = mtod(nam, struct sockaddr_un *);
    464   1.1       cgd 	register struct vnode *vp;
    465   1.1       cgd 	register struct socket *so2, *so3;
    466   1.1       cgd 	struct unpcb *unp2, *unp3;
    467   1.1       cgd 	int error;
    468   1.1       cgd 	struct nameidata nd;
    469   1.1       cgd 
    470  1.20   mycroft 	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, sun->sun_path, p);
    471   1.1       cgd 	if (nam->m_data + nam->m_len == &nam->m_dat[MLEN]) {	/* XXX */
    472   1.1       cgd 		if (*(mtod(nam, caddr_t) + nam->m_len - 1) != 0)
    473  1.20   mycroft 			return (EINVAL);
    474   1.1       cgd 	} else
    475   1.1       cgd 		*(mtod(nam, caddr_t) + nam->m_len) = 0;
    476  1.16  christos 	if ((error = namei(&nd)) != 0)
    477   1.1       cgd 		return (error);
    478   1.9   mycroft 	vp = nd.ni_vp;
    479   1.1       cgd 	if (vp->v_type != VSOCK) {
    480   1.1       cgd 		error = ENOTSOCK;
    481   1.1       cgd 		goto bad;
    482   1.1       cgd 	}
    483  1.16  christos 	if ((error = VOP_ACCESS(vp, VWRITE, p->p_ucred, p)) != 0)
    484   1.1       cgd 		goto bad;
    485   1.1       cgd 	so2 = vp->v_socket;
    486   1.1       cgd 	if (so2 == 0) {
    487   1.1       cgd 		error = ECONNREFUSED;
    488   1.1       cgd 		goto bad;
    489   1.1       cgd 	}
    490   1.1       cgd 	if (so->so_type != so2->so_type) {
    491   1.1       cgd 		error = EPROTOTYPE;
    492   1.1       cgd 		goto bad;
    493   1.1       cgd 	}
    494   1.1       cgd 	if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
    495   1.1       cgd 		if ((so2->so_options & SO_ACCEPTCONN) == 0 ||
    496   1.1       cgd 		    (so3 = sonewconn(so2, 0)) == 0) {
    497   1.1       cgd 			error = ECONNREFUSED;
    498   1.1       cgd 			goto bad;
    499   1.1       cgd 		}
    500   1.1       cgd 		unp2 = sotounpcb(so2);
    501   1.1       cgd 		unp3 = sotounpcb(so3);
    502   1.1       cgd 		if (unp2->unp_addr)
    503  1.20   mycroft 			unp3->unp_addr = mtod(m_copy(dtom(unp2->unp_addr), 0,
    504  1.20   mycroft 			    (int)M_COPYALL), struct sockaddr_un *);
    505   1.1       cgd 		so2 = so3;
    506   1.1       cgd 	}
    507   1.1       cgd 	error = unp_connect2(so, so2);
    508   1.1       cgd bad:
    509   1.1       cgd 	vput(vp);
    510   1.1       cgd 	return (error);
    511   1.1       cgd }
    512   1.1       cgd 
    513   1.5    andrew int
    514   1.1       cgd unp_connect2(so, so2)
    515   1.1       cgd 	register struct socket *so;
    516   1.1       cgd 	register struct socket *so2;
    517   1.1       cgd {
    518   1.1       cgd 	register struct unpcb *unp = sotounpcb(so);
    519   1.1       cgd 	register struct unpcb *unp2;
    520   1.1       cgd 
    521   1.1       cgd 	if (so2->so_type != so->so_type)
    522   1.1       cgd 		return (EPROTOTYPE);
    523   1.1       cgd 	unp2 = sotounpcb(so2);
    524   1.1       cgd 	unp->unp_conn = unp2;
    525   1.1       cgd 	switch (so->so_type) {
    526   1.1       cgd 
    527   1.1       cgd 	case SOCK_DGRAM:
    528   1.1       cgd 		unp->unp_nextref = unp2->unp_refs;
    529   1.1       cgd 		unp2->unp_refs = unp;
    530   1.1       cgd 		soisconnected(so);
    531   1.1       cgd 		break;
    532   1.1       cgd 
    533   1.1       cgd 	case SOCK_STREAM:
    534   1.1       cgd 		unp2->unp_conn = unp;
    535   1.1       cgd 		soisconnected(so);
    536   1.1       cgd 		soisconnected(so2);
    537   1.1       cgd 		break;
    538   1.1       cgd 
    539   1.1       cgd 	default:
    540   1.1       cgd 		panic("unp_connect2");
    541   1.1       cgd 	}
    542   1.1       cgd 	return (0);
    543   1.1       cgd }
    544   1.1       cgd 
    545   1.5    andrew void
    546   1.1       cgd unp_disconnect(unp)
    547   1.1       cgd 	struct unpcb *unp;
    548   1.1       cgd {
    549   1.1       cgd 	register struct unpcb *unp2 = unp->unp_conn;
    550   1.1       cgd 
    551   1.1       cgd 	if (unp2 == 0)
    552   1.1       cgd 		return;
    553   1.1       cgd 	unp->unp_conn = 0;
    554   1.1       cgd 	switch (unp->unp_socket->so_type) {
    555   1.1       cgd 
    556   1.1       cgd 	case SOCK_DGRAM:
    557   1.1       cgd 		if (unp2->unp_refs == unp)
    558   1.1       cgd 			unp2->unp_refs = unp->unp_nextref;
    559   1.1       cgd 		else {
    560   1.1       cgd 			unp2 = unp2->unp_refs;
    561   1.1       cgd 			for (;;) {
    562   1.1       cgd 				if (unp2 == 0)
    563   1.1       cgd 					panic("unp_disconnect");
    564   1.1       cgd 				if (unp2->unp_nextref == unp)
    565   1.1       cgd 					break;
    566   1.1       cgd 				unp2 = unp2->unp_nextref;
    567   1.1       cgd 			}
    568   1.1       cgd 			unp2->unp_nextref = unp->unp_nextref;
    569   1.1       cgd 		}
    570   1.1       cgd 		unp->unp_nextref = 0;
    571   1.1       cgd 		unp->unp_socket->so_state &= ~SS_ISCONNECTED;
    572   1.1       cgd 		break;
    573   1.1       cgd 
    574   1.1       cgd 	case SOCK_STREAM:
    575   1.1       cgd 		soisdisconnected(unp->unp_socket);
    576   1.1       cgd 		unp2->unp_conn = 0;
    577   1.1       cgd 		soisdisconnected(unp2->unp_socket);
    578   1.1       cgd 		break;
    579   1.1       cgd 	}
    580   1.1       cgd }
    581   1.1       cgd 
    582   1.1       cgd #ifdef notdef
    583   1.1       cgd unp_abort(unp)
    584   1.1       cgd 	struct unpcb *unp;
    585   1.1       cgd {
    586   1.1       cgd 
    587   1.1       cgd 	unp_detach(unp);
    588   1.1       cgd }
    589   1.1       cgd #endif
    590   1.1       cgd 
    591   1.5    andrew void
    592   1.1       cgd unp_shutdown(unp)
    593   1.1       cgd 	struct unpcb *unp;
    594   1.1       cgd {
    595   1.1       cgd 	struct socket *so;
    596   1.1       cgd 
    597   1.1       cgd 	if (unp->unp_socket->so_type == SOCK_STREAM && unp->unp_conn &&
    598   1.1       cgd 	    (so = unp->unp_conn->unp_socket))
    599   1.1       cgd 		socantrcvmore(so);
    600   1.1       cgd }
    601   1.1       cgd 
    602   1.5    andrew void
    603   1.1       cgd unp_drop(unp, errno)
    604   1.1       cgd 	struct unpcb *unp;
    605   1.1       cgd 	int errno;
    606   1.1       cgd {
    607   1.1       cgd 	struct socket *so = unp->unp_socket;
    608   1.1       cgd 
    609   1.1       cgd 	so->so_error = errno;
    610   1.1       cgd 	unp_disconnect(unp);
    611   1.1       cgd 	if (so->so_head) {
    612  1.15   mycroft 		so->so_pcb = 0;
    613  1.14   mycroft 		sofree(so);
    614  1.20   mycroft 		if (unp->unp_addr)
    615  1.20   mycroft 			m_freem(dtom(unp->unp_addr));
    616  1.14   mycroft 		free(unp, M_PCB);
    617   1.1       cgd 	}
    618   1.1       cgd }
    619   1.1       cgd 
    620   1.1       cgd #ifdef notdef
    621   1.1       cgd unp_drain()
    622   1.1       cgd {
    623   1.1       cgd 
    624   1.1       cgd }
    625   1.1       cgd #endif
    626   1.1       cgd 
    627   1.5    andrew int
    628   1.1       cgd unp_externalize(rights)
    629   1.1       cgd 	struct mbuf *rights;
    630   1.1       cgd {
    631   1.1       cgd 	struct proc *p = curproc;		/* XXX */
    632   1.1       cgd 	register int i;
    633   1.1       cgd 	register struct cmsghdr *cm = mtod(rights, struct cmsghdr *);
    634   1.1       cgd 	register struct file **rp = (struct file **)(cm + 1);
    635   1.1       cgd 	register struct file *fp;
    636   1.1       cgd 	int newfds = (cm->cmsg_len - sizeof(*cm)) / sizeof (int);
    637   1.1       cgd 	int f;
    638   1.1       cgd 
    639   1.6   mycroft 	if (!fdavail(p, newfds)) {
    640   1.1       cgd 		for (i = 0; i < newfds; i++) {
    641   1.1       cgd 			fp = *rp;
    642   1.1       cgd 			unp_discard(fp);
    643   1.1       cgd 			*rp++ = 0;
    644   1.1       cgd 		}
    645   1.1       cgd 		return (EMSGSIZE);
    646   1.1       cgd 	}
    647   1.1       cgd 	for (i = 0; i < newfds; i++) {
    648   1.1       cgd 		if (fdalloc(p, 0, &f))
    649   1.1       cgd 			panic("unp_externalize");
    650   1.1       cgd 		fp = *rp;
    651   1.1       cgd 		p->p_fd->fd_ofiles[f] = fp;
    652   1.1       cgd 		fp->f_msgcount--;
    653   1.1       cgd 		unp_rights--;
    654   1.1       cgd 		*(int *)rp++ = f;
    655   1.1       cgd 	}
    656   1.1       cgd 	return (0);
    657   1.1       cgd }
    658   1.1       cgd 
    659   1.5    andrew int
    660   1.1       cgd unp_internalize(control, p)
    661   1.1       cgd 	struct mbuf *control;
    662   1.1       cgd 	struct proc *p;
    663   1.1       cgd {
    664   1.1       cgd 	struct filedesc *fdp = p->p_fd;
    665   1.1       cgd 	register struct cmsghdr *cm = mtod(control, struct cmsghdr *);
    666   1.1       cgd 	register struct file **rp;
    667   1.1       cgd 	register struct file *fp;
    668   1.1       cgd 	register int i, fd;
    669   1.1       cgd 	int oldfds;
    670   1.1       cgd 
    671   1.1       cgd 	if (cm->cmsg_type != SCM_RIGHTS || cm->cmsg_level != SOL_SOCKET ||
    672   1.1       cgd 	    cm->cmsg_len != control->m_len)
    673   1.1       cgd 		return (EINVAL);
    674   1.1       cgd 	oldfds = (cm->cmsg_len - sizeof (*cm)) / sizeof (int);
    675   1.1       cgd 	rp = (struct file **)(cm + 1);
    676   1.1       cgd 	for (i = 0; i < oldfds; i++) {
    677   1.1       cgd 		fd = *(int *)rp++;
    678   1.1       cgd 		if ((unsigned)fd >= fdp->fd_nfiles ||
    679   1.1       cgd 		    fdp->fd_ofiles[fd] == NULL)
    680   1.1       cgd 			return (EBADF);
    681   1.1       cgd 	}
    682   1.1       cgd 	rp = (struct file **)(cm + 1);
    683   1.1       cgd 	for (i = 0; i < oldfds; i++) {
    684   1.1       cgd 		fp = fdp->fd_ofiles[*(int *)rp];
    685   1.1       cgd 		*rp++ = fp;
    686   1.1       cgd 		fp->f_count++;
    687   1.1       cgd 		fp->f_msgcount++;
    688   1.1       cgd 		unp_rights++;
    689   1.1       cgd 	}
    690   1.1       cgd 	return (0);
    691   1.1       cgd }
    692   1.1       cgd 
    693   1.1       cgd int	unp_defer, unp_gcing;
    694   1.1       cgd extern	struct domain unixdomain;
    695   1.1       cgd 
    696   1.5    andrew void
    697   1.1       cgd unp_gc()
    698   1.1       cgd {
    699   1.8   mycroft 	register struct file *fp, *nextfp;
    700   1.1       cgd 	register struct socket *so;
    701   1.8   mycroft 	struct file **extra_ref, **fpp;
    702   1.8   mycroft 	int nunref, i;
    703   1.1       cgd 
    704   1.1       cgd 	if (unp_gcing)
    705   1.1       cgd 		return;
    706   1.1       cgd 	unp_gcing = 1;
    707   1.1       cgd 	unp_defer = 0;
    708  1.11   mycroft 	for (fp = filehead.lh_first; fp != 0; fp = fp->f_list.le_next)
    709   1.1       cgd 		fp->f_flag &= ~(FMARK|FDEFER);
    710   1.1       cgd 	do {
    711  1.11   mycroft 		for (fp = filehead.lh_first; fp != 0; fp = fp->f_list.le_next) {
    712   1.1       cgd 			if (fp->f_count == 0)
    713   1.1       cgd 				continue;
    714   1.1       cgd 			if (fp->f_flag & FDEFER) {
    715   1.1       cgd 				fp->f_flag &= ~FDEFER;
    716   1.1       cgd 				unp_defer--;
    717   1.1       cgd 			} else {
    718   1.1       cgd 				if (fp->f_flag & FMARK)
    719   1.1       cgd 					continue;
    720   1.1       cgd 				if (fp->f_count == fp->f_msgcount)
    721   1.1       cgd 					continue;
    722   1.1       cgd 				fp->f_flag |= FMARK;
    723   1.1       cgd 			}
    724   1.1       cgd 			if (fp->f_type != DTYPE_SOCKET ||
    725   1.1       cgd 			    (so = (struct socket *)fp->f_data) == 0)
    726   1.1       cgd 				continue;
    727   1.1       cgd 			if (so->so_proto->pr_domain != &unixdomain ||
    728   1.1       cgd 			    (so->so_proto->pr_flags&PR_RIGHTS) == 0)
    729   1.1       cgd 				continue;
    730   1.1       cgd #ifdef notdef
    731   1.1       cgd 			if (so->so_rcv.sb_flags & SB_LOCK) {
    732   1.1       cgd 				/*
    733   1.1       cgd 				 * This is problematical; it's not clear
    734   1.1       cgd 				 * we need to wait for the sockbuf to be
    735   1.1       cgd 				 * unlocked (on a uniprocessor, at least),
    736   1.1       cgd 				 * and it's also not clear what to do
    737   1.1       cgd 				 * if sbwait returns an error due to receipt
    738   1.1       cgd 				 * of a signal.  If sbwait does return
    739   1.1       cgd 				 * an error, we'll go into an infinite
    740   1.1       cgd 				 * loop.  Delete all of this for now.
    741   1.1       cgd 				 */
    742   1.1       cgd 				(void) sbwait(&so->so_rcv);
    743   1.1       cgd 				goto restart;
    744   1.1       cgd 			}
    745   1.1       cgd #endif
    746   1.1       cgd 			unp_scan(so->so_rcv.sb_mb, unp_mark);
    747   1.1       cgd 		}
    748   1.1       cgd 	} while (unp_defer);
    749   1.8   mycroft 	/*
    750   1.8   mycroft 	 * We grab an extra reference to each of the file table entries
    751   1.8   mycroft 	 * that are not otherwise accessible and then free the rights
    752   1.8   mycroft 	 * that are stored in messages on them.
    753   1.8   mycroft 	 *
    754   1.8   mycroft 	 * The bug in the orginal code is a little tricky, so I'll describe
    755   1.8   mycroft 	 * what's wrong with it here.
    756   1.8   mycroft 	 *
    757   1.8   mycroft 	 * It is incorrect to simply unp_discard each entry for f_msgcount
    758   1.8   mycroft 	 * times -- consider the case of sockets A and B that contain
    759   1.8   mycroft 	 * references to each other.  On a last close of some other socket,
    760   1.8   mycroft 	 * we trigger a gc since the number of outstanding rights (unp_rights)
    761   1.8   mycroft 	 * is non-zero.  If during the sweep phase the gc code un_discards,
    762   1.8   mycroft 	 * we end up doing a (full) closef on the descriptor.  A closef on A
    763   1.8   mycroft 	 * results in the following chain.  Closef calls soo_close, which
    764   1.8   mycroft 	 * calls soclose.   Soclose calls first (through the switch
    765   1.8   mycroft 	 * uipc_usrreq) unp_detach, which re-invokes unp_gc.  Unp_gc simply
    766   1.8   mycroft 	 * returns because the previous instance had set unp_gcing, and
    767   1.8   mycroft 	 * we return all the way back to soclose, which marks the socket
    768   1.8   mycroft 	 * with SS_NOFDREF, and then calls sofree.  Sofree calls sorflush
    769   1.8   mycroft 	 * to free up the rights that are queued in messages on the socket A,
    770   1.8   mycroft 	 * i.e., the reference on B.  The sorflush calls via the dom_dispose
    771   1.8   mycroft 	 * switch unp_dispose, which unp_scans with unp_discard.  This second
    772   1.8   mycroft 	 * instance of unp_discard just calls closef on B.
    773   1.8   mycroft 	 *
    774   1.8   mycroft 	 * Well, a similar chain occurs on B, resulting in a sorflush on B,
    775   1.8   mycroft 	 * which results in another closef on A.  Unfortunately, A is already
    776   1.8   mycroft 	 * being closed, and the descriptor has already been marked with
    777   1.8   mycroft 	 * SS_NOFDREF, and soclose panics at this point.
    778   1.8   mycroft 	 *
    779   1.8   mycroft 	 * Here, we first take an extra reference to each inaccessible
    780   1.8   mycroft 	 * descriptor.  Then, we call sorflush ourself, since we know
    781   1.8   mycroft 	 * it is a Unix domain socket anyhow.  After we destroy all the
    782   1.8   mycroft 	 * rights carried in messages, we do a last closef to get rid
    783   1.8   mycroft 	 * of our extra reference.  This is the last close, and the
    784   1.8   mycroft 	 * unp_detach etc will shut down the socket.
    785   1.8   mycroft 	 *
    786   1.8   mycroft 	 * 91/09/19, bsy (at) cs.cmu.edu
    787   1.8   mycroft 	 */
    788   1.8   mycroft 	extra_ref = malloc(nfiles * sizeof(struct file *), M_FILE, M_WAITOK);
    789  1.11   mycroft 	for (nunref = 0, fp = filehead.lh_first, fpp = extra_ref; fp != 0;
    790  1.11   mycroft 	    fp = nextfp) {
    791  1.11   mycroft 		nextfp = fp->f_list.le_next;
    792   1.1       cgd 		if (fp->f_count == 0)
    793   1.1       cgd 			continue;
    794   1.8   mycroft 		if (fp->f_count == fp->f_msgcount && !(fp->f_flag & FMARK)) {
    795   1.8   mycroft 			*fpp++ = fp;
    796   1.8   mycroft 			nunref++;
    797   1.8   mycroft 			fp->f_count++;
    798   1.8   mycroft 		}
    799   1.1       cgd 	}
    800   1.8   mycroft 	for (i = nunref, fpp = extra_ref; --i >= 0; ++fpp)
    801   1.8   mycroft 		sorflush((struct socket *)(*fpp)->f_data);
    802   1.8   mycroft 	for (i = nunref, fpp = extra_ref; --i >= 0; ++fpp)
    803  1.13   mycroft 		(void) closef(*fpp, (struct proc *)0);
    804   1.8   mycroft 	free((caddr_t)extra_ref, M_FILE);
    805   1.1       cgd 	unp_gcing = 0;
    806   1.1       cgd }
    807   1.1       cgd 
    808   1.5    andrew void
    809   1.1       cgd unp_dispose(m)
    810   1.1       cgd 	struct mbuf *m;
    811   1.1       cgd {
    812   1.8   mycroft 
    813   1.1       cgd 	if (m)
    814   1.1       cgd 		unp_scan(m, unp_discard);
    815   1.1       cgd }
    816   1.1       cgd 
    817   1.5    andrew void
    818   1.1       cgd unp_scan(m0, op)
    819   1.1       cgd 	register struct mbuf *m0;
    820   1.5    andrew 	void (*op) __P((struct file *));
    821   1.1       cgd {
    822   1.1       cgd 	register struct mbuf *m;
    823   1.1       cgd 	register struct file **rp;
    824   1.1       cgd 	register struct cmsghdr *cm;
    825   1.1       cgd 	register int i;
    826   1.1       cgd 	int qfds;
    827   1.1       cgd 
    828   1.1       cgd 	while (m0) {
    829   1.1       cgd 		for (m = m0; m; m = m->m_next)
    830   1.1       cgd 			if (m->m_type == MT_CONTROL &&
    831   1.1       cgd 			    m->m_len >= sizeof(*cm)) {
    832   1.1       cgd 				cm = mtod(m, struct cmsghdr *);
    833   1.1       cgd 				if (cm->cmsg_level != SOL_SOCKET ||
    834   1.1       cgd 				    cm->cmsg_type != SCM_RIGHTS)
    835   1.1       cgd 					continue;
    836   1.1       cgd 				qfds = (cm->cmsg_len - sizeof *cm)
    837   1.1       cgd 						/ sizeof (struct file *);
    838   1.1       cgd 				rp = (struct file **)(cm + 1);
    839   1.1       cgd 				for (i = 0; i < qfds; i++)
    840   1.1       cgd 					(*op)(*rp++);
    841   1.1       cgd 				break;		/* XXX, but saves time */
    842   1.1       cgd 			}
    843   1.1       cgd 		m0 = m0->m_act;
    844   1.1       cgd 	}
    845   1.1       cgd }
    846   1.1       cgd 
    847   1.5    andrew void
    848   1.1       cgd unp_mark(fp)
    849   1.1       cgd 	struct file *fp;
    850   1.1       cgd {
    851   1.1       cgd 
    852   1.1       cgd 	if (fp->f_flag & FMARK)
    853   1.1       cgd 		return;
    854   1.1       cgd 	unp_defer++;
    855   1.1       cgd 	fp->f_flag |= (FMARK|FDEFER);
    856   1.1       cgd }
    857   1.1       cgd 
    858   1.5    andrew void
    859   1.1       cgd unp_discard(fp)
    860   1.1       cgd 	struct file *fp;
    861   1.1       cgd {
    862   1.8   mycroft 
    863   1.1       cgd 	fp->f_msgcount--;
    864   1.1       cgd 	unp_rights--;
    865  1.13   mycroft 	(void) closef(fp, (struct proc *)0);
    866   1.1       cgd }
    867