Module Name:    src
Committed By:   rmind
Date:           Sat May 17 23:55:24 UTC 2014

Modified Files:
        src/sys/kern: uipc_socket2.c

Log Message:
sonewconn: insert the socket into the queue *after* the protocol attach.
This potentially avoids unnecessary race conditions when handling partial
connections.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/kern/uipc_socket2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/uipc_socket2.c
diff -u src/sys/kern/uipc_socket2.c:1.116 src/sys/kern/uipc_socket2.c:1.117
--- src/sys/kern/uipc_socket2.c:1.116	Sat May 17 22:52:36 2014
+++ src/sys/kern/uipc_socket2.c	Sat May 17 23:55:24 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_socket2.c,v 1.116 2014/05/17 22:52:36 rmind Exp $	*/
+/*	$NetBSD: uipc_socket2.c,v 1.117 2014/05/17 23:55:24 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.116 2014/05/17 22:52:36 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.117 2014/05/17 23:55:24 rmind Exp $");
 
 #include "opt_mbuftrace.h"
 #include "opt_sb_max.h"
@@ -302,13 +302,11 @@ sonewconn(struct socket *head, bool sore
 	 */
 	mutex_obj_hold(head->so_lock);
 	so->so_lock = head->so_lock;
-	soqinsque(head, so, soqueue);
 
 	error = (*so->so_proto->pr_usrreq)(so, PRU_ATTACH, NULL, NULL,
 	    NULL, NULL);
 	KASSERT(solocked(so));
 	if (error) {
-		(void) soqremque(so, soqueue);
 out:
 		KASSERT(so->so_accf == NULL);
 		soput(so);
@@ -319,9 +317,10 @@ out:
 	}
 
 	/*
-	 * Update the connection status and wake up any waiters,
-	 * e.g. processes blocking on accept().
+	 * Insert into the queue.  If ready, update the connection status
+	 * and wake up any waiters, e.g. processes blocking on accept().
 	 */
+	soqinsque(head, so, soqueue);
 	if (soready) {
 		so->so_state |= SS_ISCONNECTED;
 		sorwakeup(head);

Reply via email to