The branch, master has been updated
       via  ac18c80 Bump version to 1.2.0
       via  aff61a7 swrap: Also log the process name
       via  d26ceb5 swrap: Better handling for default values in 
socket_wrapper_max_sockets()
       via  74c3a9a swrap: Always allocate the socket fd array to the maximum
       via  87cc3f8 swrap: Rename global variable for max sockets
      from  d788cef tests: Enable threaded test cases on FreeBSD

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


- Log -----------------------------------------------------------------
commit ac18c80e2096f0edc542273325fb2571d35cb796
Author: Andreas Schneider <a...@samba.org>
Date:   Mon Nov 12 11:14:20 2018 +0100

    Bump version to 1.2.0
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit aff61a781700ce8c1e6f9d0cd74b4c484be354fa
Author: Andreas Schneider <a...@samba.org>
Date:   Mon Nov 12 15:22:35 2018 +0100

    swrap: Also log the process name
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit d26ceb542342d6eef4a8df14f79ca2f81d1e550e
Author: Andreas Schneider <a...@samba.org>
Date:   Tue Nov 13 08:31:43 2018 +0100

    swrap: Better handling for default values in socket_wrapper_max_sockets()
    
    Pair-Programmed-With: Anoop C S <anoo...@redhat.com>
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Signed-off-by: Anoop C S <anoo...@redhat.com>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 74c3a9a60e5cfb8d191876c24e88e5d3aa38ca58
Author: Andreas Schneider <a...@samba.org>
Date:   Mon Nov 12 17:34:08 2018 +0100

    swrap: Always allocate the socket fd array to the maximum
    
    This will allow that we can deal with duplicates if the default value is
    used.
    
    Pair-Programmed-With: Anoop C S <anoo...@redhat.com>
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Signed-off-by: Anoop C S <anoo...@redhat.com>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 87cc3f8e5433471e986c3b50e351ae49289b4cbe
Author: Andreas Schneider <a...@samba.org>
Date:   Mon Nov 12 17:00:09 2018 +0100

    swrap: Rename global variable for max sockets
    
    We also need a mutex to protect access to it.
    
    Pair-Programmed-With: Anoop C S <anoo...@redhat.com>
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Signed-off-by: Anoop C S <anoo...@redhat.com>
    Reviewed-by: Ralph Boehme <s...@samba.org>

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

Summary of changes:
 CMakeLists.txt        |  4 +--
 ChangeLog             |  5 +++
 ConfigureChecks.cmake |  9 ++++++
 config.h.cmake        |  6 ++++
 src/socket_wrapper.c  | 85 ++++++++++++++++++++++++++++++++++++++-------------
 5 files changed, 85 insertions(+), 24 deletions(-)


Changeset truncated at 500 lines:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 35527f1..2f51bea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ list(APPEND CMAKE_MODULE_PATH 
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
 include(DefineCMakeDefaults)
 include(DefineCompilerFlags)
 
-project(socket_wrapper VERSION 1.1.9 LANGUAGES C)
+project(socket_wrapper VERSION 1.2.0 LANGUAGES C)
 
 # global needed variables
 set(APPLICATION_NAME ${PROJECT_NAME})
@@ -23,7 +23,7 @@ set(APPLICATION_NAME ${PROJECT_NAME})
 #     Increment AGE. Set REVISION to 0
 #   If the source code was changed, but there were no interface changes:
 #     Increment REVISION.
-set(LIBRARY_VERSION "0.1.9")
+set(LIBRARY_VERSION "0.1.10")
 set(LIBRARY_SOVERSION "0")
 
 # add definitions
diff --git a/ChangeLog b/ChangeLog
index 50911b6..639044d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
 ChangeLog
 ==========
 
+version 1.2.0 (released 2018-11-13)
+  * Added threading support
+  * Moved to modern cmake
+  * Several smaller bugfixes
+
 version 1.1.9 (released 2017-12-04)
   * Fixed thread - signal deadlock issue
 
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 94fed22..6cedb90 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -54,6 +54,13 @@ check_include_file(sys/timerfd.h HAVE_SYS_TIMERFD_H)
 check_include_file(gnu/lib-names.h HAVE_GNU_LIB_NAMES_H)
 check_include_file(rpc/rpc.h HAVE_RPC_RPC_H)
 
+# SYMBOLS
+set(CMAKE_REQUIRED_FLAGS -D_GNU_SOURCE)
+check_symbol_exists(program_invocation_short_name
+                    "errno.h"
+                    HAVE_PROGRAM_INVOCATION_SHORT_NAME)
+unset(CMAKE_REQUIRED_FLAGS)
+
 # FUNCTIONS
 check_function_exists(strncpy HAVE_STRNCPY)
 check_function_exists(vsnprintf HAVE_VSNPRINTF)
@@ -65,6 +72,8 @@ check_function_exists(bindresvport HAVE_BINDRESVPORT)
 check_function_exists(accept4 HAVE_ACCEPT4)
 check_function_exists(open64 HAVE_OPEN64)
 check_function_exists(fopen64 HAVE_FOPEN64)
+check_function_exists(getprogname HAVE_GETPROGNAME)
+check_function_exists(getexecname HAVE_GETEXECNAME)
 
 check_function_exists(pledge HAVE_PLEDGE)
 
diff --git a/config.h.cmake b/config.h.cmake
index 5baa789..0207031 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -31,6 +31,10 @@
 #cmakedefine HAVE_STRUCT_SOCKADDR_SA_LEN 1
 #cmakedefine HAVE_STRUCT_MSGHDR_MSG_CONTROL 1
 
+/**************************** SYMBOLS ****************************/
+
+#cmakedefine HAVE_PROGRAM_INVOCATION_SHORT_NAME 1
+
 /*************************** FUNCTIONS ***************************/
 
 /* Define to 1 if you have the `getaddrinfo' function. */
@@ -42,6 +46,8 @@
 #cmakedefine HAVE_ACCEPT4 1
 #cmakedefine HAVE_OPEN64 1
 #cmakedefine HAVE_FOPEN64 1
+#cmakedefine HAVE_GETPROGNAME 1
+#cmakedefine HAVE_GETEXECNAME 1
 #cmakedefine HAVE_PLEDGE 1
 
 #cmakedefine HAVE_ACCEPT_PSOCKLEN_T 1
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index a107710..2b77ceb 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -230,7 +230,7 @@ enum swrap_dbglvl_e {
  */
 #define SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT 65535
 
-#define SOCKET_WRAPPER_MAX_SOCKETS_LIMIT 256000
+#define SOCKET_WRAPPER_MAX_SOCKETS_LIMIT 262140
 
 /* This limit is to avoid broadcast sendto() needing to stat too many
  * files.  It may be raised (with a performance cost) to up to 254
@@ -293,7 +293,14 @@ struct socket_info_container
 
 static struct socket_info_container *sockets;
 
-static size_t max_sockets = 0;
+static size_t socket_info_max = 0;
+
+/*
+ * Allocate the socket array always on the limit value. We want it to be
+ * at least bigger than the default so if we reach the limit we can
+ * still deal with duplicate fds pointing to the same socket_info.
+ */
+static size_t socket_fds_max = SOCKET_WRAPPER_MAX_SOCKETS_LIMIT;
 
 /* Hash table to map fds to corresponding socket_info index */
 static int *socket_fds_idx;
@@ -326,6 +333,19 @@ bool socket_wrapper_enabled(void);
 void swrap_constructor(void) CONSTRUCTOR_ATTRIBUTE;
 void swrap_destructor(void) DESTRUCTOR_ATTRIBUTE;
 
+#ifndef HAVE_GETPROGNAME
+static const char *getprogname(void)
+{
+#if defined(HAVE_PROGRAM_INVOCATION_SHORT_NAME)
+       return program_invocation_short_name;
+#elif defined(HAVE_GETEXECNAME)
+       return getexecname();
+#else
+       return NULL;
+#endif /* HAVE_PROGRAM_INVOCATION_SHORT_NAME */
+}
+#endif /* HAVE_GETPROGNAME */
+
 static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *func, const char 
*format, ...) PRINTF_ATTRIBUTE(3, 4);
 # define SWRAP_LOG(dbglvl, ...) swrap_log((dbglvl), __func__, __VA_ARGS__)
 
@@ -338,6 +358,7 @@ static void swrap_log(enum swrap_dbglvl_e dbglvl,
        const char *d;
        unsigned int lvl = 0;
        const char *prefix = "SWRAP";
+       const char *progname = getprogname();
 
        d = getenv("SOCKET_WRAPPER_DEBUGLEVEL");
        if (d != NULL) {
@@ -367,9 +388,17 @@ static void swrap_log(enum swrap_dbglvl_e dbglvl,
                        break;
        }
 
+       if (progname == NULL) {
+               progname = "<unknown>";
+       }
+
        fprintf(stderr,
-               "%s(%d) - %s: %s\n",
-               prefix, (int)getpid(), func, buffer);
+               "%s[%s (%u)] - %s: %s\n",
+               prefix,
+               progname,
+               (unsigned int)getpid(),
+               func,
+               buffer);
 }
 
 /*********************************************************
@@ -1321,14 +1350,14 @@ done:
 static size_t socket_wrapper_max_sockets(void)
 {
        const char *s;
-       unsigned long tmp;
+       size_t tmp;
        char *endp;
 
-       if (max_sockets != 0) {
-               return max_sockets;
+       if (socket_info_max != 0) {
+               return socket_info_max;
        }
 
-       max_sockets = SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT;
+       socket_info_max = SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT;
 
        s = getenv("SOCKET_WRAPPER_MAX_SOCKETS");
        if (s == NULL || s[0] == '\0') {
@@ -1339,16 +1368,26 @@ static size_t socket_wrapper_max_sockets(void)
        if (s == endp) {
                goto done;
        }
-       if (tmp == 0 || tmp > SOCKET_WRAPPER_MAX_SOCKETS_LIMIT) {
+       if (tmp == 0) {
+               tmp = SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT;
                SWRAP_LOG(SWRAP_LOG_ERROR,
-                         "Invalid number of sockets specified, using 
default.");
-               goto done;
+                         "Invalid number of sockets specified, "
+                         "using default (%zu)",
+                         tmp);
+       }
+
+       if (tmp > SOCKET_WRAPPER_MAX_SOCKETS_LIMIT) {
+               tmp = SOCKET_WRAPPER_MAX_SOCKETS_LIMIT;
+               SWRAP_LOG(SWRAP_LOG_ERROR,
+                         "Invalid number of sockets specified, "
+                         "using maximum (%zu).",
+                         tmp);
        }
 
-       max_sockets = tmp;
+       socket_info_max = tmp;
 
 done:
-       return max_sockets;
+       return socket_info_max;
 }
 
 static void socket_wrapper_init_fds_idx(void)
@@ -1360,7 +1399,7 @@ static void socket_wrapper_init_fds_idx(void)
                return;
        }
 
-       tmp = (int *)calloc(SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT, sizeof(int));
+       tmp = (int *)calloc(socket_fds_max, sizeof(int));
        if (tmp == NULL) {
                SWRAP_LOG(SWRAP_LOG_ERROR,
                          "Failed to allocate socket fds index array: %s",
@@ -1368,7 +1407,7 @@ static void socket_wrapper_init_fds_idx(void)
                exit(-1);
        }
 
-       for (i = 0; i < SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT; i++) {
+       for (i = 0; i < socket_fds_max; i++) {
                tmp[i] = -1;
        }
 
@@ -1377,6 +1416,7 @@ static void socket_wrapper_init_fds_idx(void)
 
 static void socket_wrapper_init_sockets(void)
 {
+       size_t max_sockets;
        size_t i;
        int ret;
 
@@ -1389,6 +1429,7 @@ static void socket_wrapper_init_sockets(void)
 
        socket_wrapper_init_fds_idx();
 
+       /* Needs to be called inside the sockets_mutex lock here. */
        max_sockets = socket_wrapper_max_sockets();
 
        sockets = (struct socket_info_container *)calloc(max_sockets,
@@ -1498,11 +1539,11 @@ static int find_socket_info_index(int fd)
                return -1;
        }
 
-       if (fd >= SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT) {
+       if (fd >= socket_fds_max) {
                SWRAP_LOG(SWRAP_LOG_ERROR,
-                         "The max socket index limit of %u has been reached, "
+                         "The max socket index limit of %zu has been reached, "
                          "trying to add %d",
-                         SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT,
+                         socket_fds_max,
                          fd);
                return -1;
        }
@@ -1549,11 +1590,11 @@ static int swrap_create_socket(struct socket_info *si, 
int fd)
 {
        int idx;
 
-       if (fd >= SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT) {
+       if (fd >= socket_fds_max) {
                SWRAP_LOG(SWRAP_LOG_ERROR,
-                         "The max socket index limit of %u has been reached, "
+                         "The max socket index limit of %zu has been reached, "
                          "trying to add %d",
-                         SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT,
+                         socket_fds_max,
                          fd);
                return -1;
        }
@@ -6251,7 +6292,7 @@ void swrap_destructor(void)
        size_t i;
 
        if (socket_fds_idx != NULL) {
-               for (i = 0; i < SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT; ++i) {
+               for (i = 0; i < socket_fds_max; ++i) {
                        if (socket_fds_idx[i] != -1) {
                                swrap_close(i);
                        }


-- 
Socket Wrapper Repository

Reply via email to