diff options
author | David Hill <dhill@cvs.openbsd.org> | 2017-01-26 01:58:01 +0000 |
---|---|---|
committer | David Hill <dhill@cvs.openbsd.org> | 2017-01-26 01:58:01 +0000 |
commit | f2d58c9d2f370581c24d1d731d28d147316f505e (patch) | |
tree | f6ce0aeb417c292cfe46a29f5476cf985e5c235a | |
parent | 7761fe578cf3c2799febb0f995b87d36748a79fd (diff) |
Allocate the mbuf before the netlock. While here, move the setting of
nflag closer to where its value is used.
ok mpi@
-rw-r--r-- | sys/kern/uipc_syscalls.c | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index cf38996d86e..7a8841c4988 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_syscalls.c,v 1.147 2017/01/25 07:35:31 deraadt Exp $ */ +/* $OpenBSD: uipc_syscalls.c,v 1.148 2017/01/26 01:58:00 dhill Exp $ */ /* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */ /* @@ -265,7 +265,7 @@ doaccept(struct proc *p, int sock, struct sockaddr *name, socklen_t *anamelen, { struct filedesc *fdp = p->p_fd; struct file *fp, *headfp; - struct mbuf *nam = NULL; + struct mbuf *nam; socklen_t namelen; int error, s, tmpfd; struct socket *head, *so; @@ -288,7 +288,8 @@ doaccept(struct proc *p, int sock, struct sockaddr *name, socklen_t *anamelen, return (error); } -redo: + nam = m_get(M_WAIT, MT_SONAME); + NET_LOCK(s); head = headfp->f_data; if (isdnssocket(head) || (head->so_options & SO_ACCEPTCONN) == 0) { @@ -318,24 +319,6 @@ redo: goto out; } - /* Figure out whether the new socket should be non-blocking. */ - nflag = flags & SOCK_NONBLOCK_INHERIT ? (headfp->f_flag & FNONBLOCK) - : (flags & SOCK_NONBLOCK ? FNONBLOCK : 0); - - nam = m_get(M_WAIT, MT_SONAME); - - /* - * Check whether the queue emptied while we slept: m_get() may have - * blocked, allowing the connection to be reset or another thread or - * process to accept it. If so, start over. - */ - if (head->so_qlen == 0) { - NET_UNLOCK(s); - m_freem(nam); - nam = NULL; - goto redo; - } - /* * Do not sleep after we have taken the socket out of the queue. */ @@ -343,6 +326,10 @@ redo: if (soqremque(so, 1) == 0) panic("accept"); + /* Figure out whether the new socket should be non-blocking. */ + nflag = flags & SOCK_NONBLOCK_INHERIT ? (headfp->f_flag & FNONBLOCK) + : (flags & SOCK_NONBLOCK ? FNONBLOCK : 0); + /* connection has been removed from the listen queue */ KNOTE(&head->so_rcv.sb_sel.si_note, 0); |