From 8816876fa9909d3428b22db33b1e6fd8edcdd209 Mon Sep 17 00:00:00 2001 From: jhb Date: Sat, 9 Jul 2005 12:26:22 +0000 Subject: Add missing locking to linux_connect() so that it can be marked MP safe: - Conditionally grab Giant around the EISCONN hack at the end based on debug.mpsafenet. - Protect access to so_emuldata via SOCK_LOCK. Reviewed by: rwatson Approved by: re (scottl) --- sys/compat/linux/linux_socket.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'sys/compat') diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 950e170..f1f26bc 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -44,7 +44,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include +#include #include #include #include @@ -614,15 +616,20 @@ linux_connect(struct thread *td, struct linux_connect_args *args) * when on a non-blocking socket. Instead it returns the * error getsockopt(SOL_SOCKET, SO_ERROR) would return on BSD. */ - if ((error = fgetsock(td, linux_args.s, &so, &fflag)) != 0) - return(error); - error = EISCONN; - if (fflag & FNONBLOCK) { - if (so->so_emuldata == 0) - error = so->so_error; - so->so_emuldata = (void *)1; + NET_LOCK_GIANT(); + error = fgetsock(td, linux_args.s, &so, &fflag); + if (error == 0) { + error = EISCONN; + if (fflag & FNONBLOCK) { + SOCK_LOCK(so); + if (so->so_emuldata == 0) + error = so->so_error; + so->so_emuldata = (void *)1; + SOCK_UNLOCK(so); + } + fputsock(so); } - fputsock(so); + NET_UNLOCK_GIANT(); return (error); } -- cgit v1.1