[SCM] Socket Wrapper Repository - branch master updated

Andreas Schneider asn at samba.org
Thu Aug 9 08:59:53 UTC 2018


The branch, master has been updated
       via  93d4387 ctest: Move to new dashboard
       via  f0f8640 swrap: Add error check around pthread mutex locks
       via  1551444 tests: Prevent child process falling to defunct state
       via  326ae3b doc: Add SOCKET_WRAPPER_MAX_SOCKETS to manual page
       via  8ba0d9c swrap: Fix thread deadlock found by Coverity scan
       via  4d732f6 tests: Add missing header for IPPROTO_TCP
       via  32c1b58 swrap: Update header
       via  50fc189 Update LICENSE
       via  6c3e3b3 Rename COPYING to LICENSE
       via  f8b725a cpack: Do not package build dirs in source tarball
      from  5529ba0 swrap: Replace socket_fds linked list with an array

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 93d4387c27efb2b62bdc4240f66b2030f82c7705
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Jul 5 10:14:14 2018 +0200

    ctest: Move to new dashboard
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit f0f86400b6a9b9b8fc7ffddc24c64000f7b6866f
Author: Anoop C S <anoopcs at redhat.com>
Date:   Tue Jun 12 20:19:34 2018 +0530

    swrap: Add error check around pthread mutex locks
    
    Signed-off-by: Anoop C S <anoopcs at redhat.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 1551444228d7e0a0b0e1028dabd23d92fb8f2834
Author: Anoop C S <anoopcs at redhat.com>
Date:   Wed Jun 27 23:35:28 2018 +0530

    tests: Prevent child process falling to defunct state
    
    Parent process does not wait for child process(which gets forked after
    accepting a client connection) to exit inside echo server which in turn
    puts child into defunct state. Even though those defunct childs are
    cleaned up during parent exit it is better to wait from parent process
    itself.
    
    Signed-off-by: Anoop C S <anoopcs at redhat.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 326ae3b98f766b95ccc83717896acb8651ec2ab2
Author: Anoop C S <anoopcs at redhat.com>
Date:   Mon Jun 25 19:15:44 2018 +0530

    doc: Add SOCKET_WRAPPER_MAX_SOCKETS to manual page
    
    Signed-off-by: Anoop C S <anoopcs at redhat.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 8ba0d9cf9769579f3c68f78b33477c10aa133e8c
Author: Anoop C S <anoopcs at redhat.com>
Date:   Fri Jun 15 12:36:54 2018 +0530

    swrap: Fix thread deadlock found by Coverity scan
    
    CID 175897
    CID 175898
    
    Signed-off-by: Anoop C S <anoopcs at redhat.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 4d732f6d037cfc2ca3c44c51081163b1d3e06b17
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Jun 29 15:17:10 2018 +0200

    tests: Add missing header for IPPROTO_TCP
    
    This fixes the build on FreeBSD.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 32c1b58590648becf179bea82eead158c324d7a7
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Jun 22 08:47:08 2018 +0200

    swrap: Update header
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 50fc18998e65be6012c59d69752978a21f5def49
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Jun 22 08:42:06 2018 +0200

    Update LICENSE
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 6c3e3b3c816c5530c5be55ed9739fb87c9573e2d
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Jun 22 08:38:04 2018 +0200

    Rename COPYING to LICENSE
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit f8b725a982653824dbe4a580e15b2104fd18af4d
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Jun 22 09:01:19 2018 +0200

    cpack: Do not package build dirs in source tarball
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 .gitignore                  |   2 +-
 CPackConfig.cmake           |   4 +-
 CTestConfig.cmake           |   6 +-
 COPYING => LICENSE          |   9 ++-
 doc/socket_wrapper.1        |  21 ++++-
 doc/socket_wrapper.1.txt    |  10 ++-
 src/socket_wrapper.c        | 182 ++++++++++++++++++++++++++++++--------------
 tests/echo_srv.c            |   2 +
 tests/test_thread_sockets.c |   1 +
 9 files changed, 165 insertions(+), 72 deletions(-)
 rename COPYING => LICENSE (82%)


Changeset truncated at 500 lines:

diff --git a/.gitignore b/.gitignore
index 5d8f581..21038a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,6 @@
 *.swp
 *~
 build
-obj
+obj*/
 cscope.*
 tags
diff --git a/CPackConfig.cmake b/CPackConfig.cmake
index dc74dfa..e1b83ac 100644
--- a/CPackConfig.cmake
+++ b/CPackConfig.cmake
@@ -7,7 +7,7 @@ set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The SSH library")
 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README")
 set(CPACK_PACKAGE_VENDOR "The SSH Library Development Team")
 set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
-set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
 
 
 ### versions
@@ -19,7 +19,7 @@ set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSIO
 
 ### source generator
 set(CPACK_SOURCE_GENERATOR "TGZ")
-set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]svn/;/[.]git/;.gitignore;/build/;/obj/;tags;cscope.*")
+set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]svn/;/[.]git/;.gitignore;/build*;/obj*;tags;cscope.*")
 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
 
 if (WIN32)
diff --git a/CTestConfig.cmake b/CTestConfig.cmake
index 3c29af3..0f4e9aa 100644
--- a/CTestConfig.cmake
+++ b/CTestConfig.cmake
@@ -1,9 +1,9 @@
 set(UPDATE_TYPE "true")
 
-set(CTEST_PROJECT_NAME "socketwrapper")
+set(CTEST_PROJECT_NAME "socket_wrapper")
 set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
 
 set(CTEST_DROP_METHOD "https")
-set(CTEST_DROP_SITE "mock.cryptomilk.org")
-set(CTEST_DROP_LOCATION "/submit.php?project=socketwrapper")
+set(CTEST_DROP_SITE "test.cmocka.org")
+set(CTEST_DROP_LOCATION "/submit.php?project=${CTEST_PROJECT_NAME}")
 set(CTEST_DROP_SITE_CDASH TRUE)
diff --git a/COPYING b/LICENSE
similarity index 82%
rename from COPYING
rename to LICENSE
index e6227e1..5142482 100644
--- a/COPYING
+++ b/LICENSE
@@ -1,7 +1,10 @@
-Copyright (C) Jelmer Vernooij 2005,2008 <jelmer at samba.org>
-Copyright (C) Stefan Metzmacher 2006-2009 <metze at samba.org>
-Copyright (C) Andreas Schneider 2013 <asn at samba.org>
+BSD 3-Clause License
 
+Copyright (c) 2005-2008, Jelmer Vernooij <jelmer at samba.org>
+Copyright (c) 2006-2018, Stefan Metzmacher <metze at samba.org>
+Copyright (c) 2013-2018, Andreas Schneider <asn at samba.org>
+Copyright (c) 2014-2017, Michael Adam <obnox at samba.org>
+Copyright (c) 2016-2018, Anoop C S <anoopcs at redhat.com>
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
diff --git a/doc/socket_wrapper.1 b/doc/socket_wrapper.1
index c3cf835..7e10224 100644
--- a/doc/socket_wrapper.1
+++ b/doc/socket_wrapper.1
@@ -1,13 +1,13 @@
 '\" t
 .\"     Title: socket_wrapper
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
-.\"      Date: 2015-08-11
+.\"    Author: Samba Team
+.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
+.\"      Date: 2018-06-26
 .\"    Manual: \ \&
 .\"    Source: \ \&
 .\"  Language: English
 .\"
-.TH "SOCKET_WRAPPER" "1" "2015\-08\-11" "\ \&" "\ \&"
+.TH "SOCKET_WRAPPER" "1" "2018\-06\-26" "\ \&" "\ \&"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -92,6 +92,13 @@ With this variable you can change the MTU size\&. However we do not recomment to
 .sp
 The minimum value you can set is 512 and the maximum 32768\&.
 .PP
+\fBSOCKET_WRAPPER_MAX_SOCKETS\fR
+.RS 4
+This variable can be used to set the maximum number of sockets to be used by an application\&.
+.RE
+.sp
+The default value is set to 65535 and the maximum 256000\&.
+.PP
 \fBSOCKET_WRAPPER_DEBUGLEVEL\fR
 .RS 4
 If you need to see what is going on in socket_wrapper itself or try to find a bug, you can enable logging support in socket_wrapper if you built it with debug symbols\&.
@@ -202,3 +209,9 @@ $ LD_PRELOAD=libsocket_wrapper\&.so \e
 .if n \{\
 .RE
 .\}
+.SH "AUTHOR"
+.PP
+\fBSamba Team\fR
+.RS 4
+Author.
+.RE
diff --git a/doc/socket_wrapper.1.txt b/doc/socket_wrapper.1.txt
index f4e82a8..583b50a 100644
--- a/doc/socket_wrapper.1.txt
+++ b/doc/socket_wrapper.1.txt
@@ -1,6 +1,7 @@
 socket_wrapper(1)
 =================
-:revdate: 2015-08-11
+:revdate: 2018-06-26
+:author: Samba Team
 
 NAME
 ----
@@ -59,6 +60,13 @@ do that as the default size of 1500 byte is best for formatting PCAP files.
 
 The minimum value you can set is 512 and the maximum 32768.
 
+*SOCKET_WRAPPER_MAX_SOCKETS*::
+
+This variable can be used to set the maximum number of sockets to be used by
+an application.
+
+The default value is set to 65535 and the maximum 256000.
+
 *SOCKET_WRAPPER_DEBUGLEVEL*::
 
 If you need to see what is going on in socket_wrapper itself or try to find a
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index a22f7dc..36482c6 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1,8 +1,11 @@
 /*
- * Copyright (c) 2005-2008 Jelmer Vernooij <jelmer at samba.org>
- * Copyright (C) 2006-2014 Stefan Metzmacher <metze at samba.org>
- * Copyright (C) 2013-2014 Andreas Schneider <asn at samba.org>
+ * BSD 3-Clause License
  *
+ * Copyright (c) 2005-2008, Jelmer Vernooij <jelmer at samba.org>
+ * Copyright (c) 2006-2018, Stefan Metzmacher <metze at samba.org>
+ * Copyright (c) 2013-2018, Andreas Schneider <asn at samba.org>
+ * Copyright (c) 2014-2017, Michael Adam <obnox at samba.org>
+ * Copyright (c) 2016-2018, Anoop C S <anoopcs at redhat.com>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -31,7 +34,6 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- *
  */
 
 /*
@@ -173,33 +175,24 @@ enum swrap_dbglvl_e {
 # endif
 #endif
 
-/* Macros for accessing mutexes */
-# define SWRAP_LOCK(m) do { \
-	pthread_mutex_lock(&(m ## _mutex)); \
-} while(0)
-
-# define SWRAP_UNLOCK(m) do { \
-	pthread_mutex_unlock(&(m ## _mutex)); \
-} while(0)
-
 /* Add new global locks here please */
 # define SWRAP_LOCK_ALL \
-	SWRAP_LOCK(libc_symbol_binding); \
+	swrap_mutex_lock(&libc_symbol_binding_mutex); \
 
 # define SWRAP_UNLOCK_ALL \
-	SWRAP_UNLOCK(libc_symbol_binding); \
+	swrap_mutex_unlock(&libc_symbol_binding_mutex); \
 
 #define SOCKET_INFO_CONTAINER(si) \
 	(struct socket_info_container *)(si)
 
 #define SWRAP_LOCK_SI(si) do { \
 	struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si); \
-	pthread_mutex_lock(&sic->meta.mutex); \
+	swrap_mutex_lock(&sic->meta.mutex); \
 } while(0)
 
 #define SWRAP_UNLOCK_SI(si) do { \
 	struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si); \
-	pthread_mutex_unlock(&sic->meta.mutex); \
+	swrap_mutex_unlock(&sic->meta.mutex); \
 } while(0)
 
 #if defined(HAVE_GETTIMEOFDAY_TZ) || defined(HAVE_GETTIMEOFDAY_TZ_VOID)
@@ -299,31 +292,23 @@ struct socket_info_container
 };
 
 static struct socket_info_container *sockets;
+
 static size_t max_sockets = 0;
 
-/*
- * While socket file descriptors are passed among different processes, the
- * numerical value gets changed. So its better to store it locally to each
- * process rather than including it within socket_info which will be shared.
- */
+/* Hash table to map fds to corresponding socket_info index */
 static int *socket_fds_idx;
 
-/* The mutex for accessing the global libc.symbols */
+/* Mutex to synchronize access to global libc.symbols */
 static pthread_mutex_t libc_symbol_binding_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-/* The mutex for syncronizing the port selection during swrap_auto_bind() */
-static pthread_mutex_t autobind_start_mutex = PTHREAD_MUTEX_INITIALIZER;
+/* Mutex for syncronizing port selection during swrap_auto_bind() */
+static pthread_mutex_t autobind_start_mutex;
 
-/*
- * Global mutex to guard the initialization of array of socket_info structures.
- */
-static pthread_mutex_t sockets_mutex = PTHREAD_MUTEX_INITIALIZER;
+/* Mutex to guard the initialization of array of socket_info structures */
+static pthread_mutex_t sockets_mutex;
 
-/*
- * Global mutex to synchronize the query for first free index in array of
- * socket_info structures by different threads within a process.
- */
-static pthread_mutex_t first_free_mutex = PTHREAD_MUTEX_INITIALIZER;
+/* Mutex to synchronize access to first free index in socket_info array */
+static pthread_mutex_t first_free_mutex;
 
 /* Function prototypes */
 
@@ -652,34 +637,56 @@ static void *_swrap_bind_symbol(enum swrap_lib lib, const char *fn_name)
 	return func;
 }
 
+static void swrap_mutex_lock(pthread_mutex_t *mutex)
+{
+	int ret;
+
+	ret = pthread_mutex_lock(mutex);
+	if (ret != 0) {
+		SWRAP_LOG(SWRAP_LOG_ERROR, "Couldn't lock pthread mutex - %s",
+			  strerror(ret));
+	}
+}
+
+static void swrap_mutex_unlock(pthread_mutex_t *mutex)
+{
+	int ret;
+
+	ret = pthread_mutex_unlock(mutex);
+	if (ret != 0) {
+		SWRAP_LOG(SWRAP_LOG_ERROR, "Couldn't unlock pthread mutex - %s",
+			  strerror(ret));
+	}
+}
+
 #define swrap_bind_symbol_libc(sym_name) \
 	if (swrap.libc.symbols._libc_##sym_name.obj == NULL) { \
-		SWRAP_LOCK(libc_symbol_binding); \
+		swrap_mutex_lock(&libc_symbol_binding_mutex); \
 		if (swrap.libc.symbols._libc_##sym_name.obj == NULL) { \
 			swrap.libc.symbols._libc_##sym_name.obj = \
 				_swrap_bind_symbol(SWRAP_LIBC, #sym_name); \
 		} \
-		SWRAP_UNLOCK(libc_symbol_binding); \
+		swrap_mutex_unlock(&libc_symbol_binding_mutex); \
 	}
 
 #define swrap_bind_symbol_libsocket(sym_name) \
 	if (swrap.libc.symbols._libc_##sym_name.obj == NULL) { \
-		SWRAP_LOCK(libc_symbol_binding); \
+		swrap_mutex_lock(&libc_symbol_binding_mutex); \
 		if (swrap.libc.symbols._libc_##sym_name.obj == NULL) { \
 			swrap.libc.symbols._libc_##sym_name.obj = \
 				_swrap_bind_symbol(SWRAP_LIBSOCKET, #sym_name); \
 		} \
-		SWRAP_UNLOCK(libc_symbol_binding); \
+		swrap_mutex_unlock(&libc_symbol_binding_mutex); \
 	}
 
 #define swrap_bind_symbol_libnsl(sym_name) \
 	if (swrap.libc.symbols._libc_##sym_name.obj == NULL) { \
-		SWRAP_LOCK(libc_symbol_binding); \
+		swrap_mutex_lock(&libc_symbol_binding_mutex); \
 		if (swrap.libc.symbols._libc_##sym_name.obj == NULL) { \
 			swrap.libc.symbols._libc_##sym_name.obj = \
 				_swrap_bind_symbol(SWRAP_LIBNSL, #sym_name); \
 		} \
-		SWRAP_UNLOCK(libc_symbol_binding); \
+		swrap_mutex_unlock(&libc_symbol_binding_mutex); \
 	}
 
 /****************************************************************************
@@ -1262,6 +1269,29 @@ done:
 	return max_mtu;
 }
 
+static int socket_wrapper_init_mutex(pthread_mutex_t *m)
+{
+	pthread_mutexattr_t ma;
+	int ret;
+
+	ret = pthread_mutexattr_init(&ma);
+	if (ret != 0) {
+		return ret;
+	}
+
+	ret = pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_ERRORCHECK);
+	if (ret != 0) {
+		goto done;
+	}
+
+	ret = pthread_mutex_init(m, &ma);
+
+done:
+	pthread_mutexattr_destroy(&ma);
+
+	return ret;
+}
+
 static size_t socket_wrapper_max_sockets(void)
 {
 	const char *s;
@@ -1322,11 +1352,12 @@ static void socket_wrapper_init_fds_idx(void)
 static void socket_wrapper_init_sockets(void)
 {
 	size_t i;
+	int ret;
 
-	SWRAP_LOCK(sockets);
+	swrap_mutex_lock(&sockets_mutex);
 
 	if (sockets != NULL) {
-		SWRAP_UNLOCK(sockets);
+		swrap_mutex_unlock(&sockets_mutex);
 		return;
 	}
 
@@ -1339,25 +1370,42 @@ static void socket_wrapper_init_sockets(void)
 
 	if (sockets == NULL) {
 		SWRAP_LOG(SWRAP_LOG_ERROR,
-			  "Failed to allocate sockets array.\n");
-		SWRAP_UNLOCK(sockets);
+			  "Failed to allocate sockets array: %s",
+			  strerror(errno));
+		swrap_mutex_unlock(&sockets_mutex);
 		exit(-1);
 	}
 
-	SWRAP_LOCK(first_free);
+	swrap_mutex_lock(&first_free_mutex);
 
 	first_free = 0;
 
 	for (i = 0; i < max_sockets; i++) {
 		swrap_set_next_free(&sockets[i].info, i+1);
-		sockets[i].meta.mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
+		ret = socket_wrapper_init_mutex(&sockets[i].meta.mutex);
+		if (ret != 0) {
+			SWRAP_LOG(SWRAP_LOG_ERROR,
+				  "Failed to initialize pthread mutex");
+			goto done;
+		}
 	}
 
 	/* mark the end of the free list */
 	swrap_set_next_free(&sockets[max_sockets-1].info, -1);
 
-	SWRAP_UNLOCK(first_free);
-	SWRAP_UNLOCK(sockets);
+	ret = socket_wrapper_init_mutex(&autobind_start_mutex);
+	if (ret != 0) {
+		SWRAP_LOG(SWRAP_LOG_ERROR,
+			  "Failed to initialize pthread mutex");
+		goto done;
+	}
+
+done:
+	swrap_mutex_unlock(&first_free_mutex);
+	swrap_mutex_unlock(&sockets_mutex);
+	if (ret != 0) {
+		exit(-1);
+	}
 }
 
 bool socket_wrapper_enabled(void)
@@ -1434,7 +1482,7 @@ static int swrap_add_socket_info(struct socket_info *si_input)
 		return -1;
 	}
 
-	SWRAP_LOCK(first_free);
+	swrap_mutex_lock(&first_free_mutex);
 	if (first_free == -1) {
 		errno = ENFILE;
 		goto out;
@@ -1452,7 +1500,7 @@ static int swrap_add_socket_info(struct socket_info *si_input)
 	SWRAP_UNLOCK_SI(si);
 
 out:
-	SWRAP_UNLOCK(first_free);
+	swrap_mutex_unlock(&first_free_mutex);
 
 	return si_index;
 }
@@ -1966,7 +2014,7 @@ static void swrap_remove_stale(int fd)
 
 	reset_socket_info_index(fd);
 
-	SWRAP_LOCK(first_free);
+	swrap_mutex_lock(&first_free_mutex);
 	SWRAP_LOCK_SI(si);
 
 	swrap_dec_refcount(si);
@@ -1984,7 +2032,7 @@ static void swrap_remove_stale(int fd)
 
 out:
 	SWRAP_UNLOCK_SI(si);
-	SWRAP_UNLOCK(first_free);
+	swrap_mutex_unlock(&first_free_mutex);
 }
 
 static int sockaddr_convert_to_un(struct socket_info *si,
@@ -3294,7 +3342,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
 	int port;
 	struct stat st;
 
-	SWRAP_LOCK(autobind_start);
+	swrap_mutex_lock(&autobind_start_mutex);
 
 	if (autobind_start_init != 1) {
 		autobind_start_init = 1;
@@ -3414,7 +3462,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
 	ret = 0;
 
 done:
-	SWRAP_UNLOCK(autobind_start);
+	swrap_mutex_unlock(&autobind_start_mutex);
 	return ret;
 }
 
@@ -4654,13 +4702,14 @@ static ssize_t swrap_sendmsg_before(int fd,
 		if (si->bound == 0) {
 			ret = swrap_auto_bind(fd, si, si->family);
 			if (ret == -1) {
+				SWRAP_UNLOCK_SI(si);
 				if (errno == ENOTSOCK) {
 					swrap_remove_stale(fd);
 					ret = -ENOTSOCK;
 				} else {
 					SWRAP_LOG(SWRAP_LOG_ERROR, "swrap_sendmsg_before failed");
 				}
-				goto out;
+				return ret;
 			}
 		}
 
@@ -4864,6 +4913,7 @@ static int swrap_recvmsg_before(int fd,
 		if (si->bound == 0) {
 			ret = swrap_auto_bind(fd, si, si->family);
 			if (ret == -1) {
+				SWRAP_UNLOCK_SI(si);
 				/*
 				 * When attempting to read or write to a
 				 * descriptor, if an underlying autobind fails
@@ -4877,7 +4927,7 @@ static int swrap_recvmsg_before(int fd,
 					SWRAP_LOG(SWRAP_LOG_ERROR,
 						  "swrap_recvmsg_before failed");
 				}
-				goto out;
+				return ret;
 			}
 		}
 		break;
@@ -5834,7 +5884,7 @@ static int swrap_close(int fd)
 
 	si = swrap_get_socket_info(si_index);
 
-	SWRAP_LOCK(first_free);


-- 
Socket Wrapper Repository



More information about the samba-cvs mailing list