swrap: Better handling for default values in socket_wrapper_max_sockets()
authorAndreas Schneider <asn@samba.org>
Tue, 13 Nov 2018 07:31:43 +0000 (08:31 +0100)
committerAndreas Schneider <asn@samba.org>
Tue, 13 Nov 2018 10:59:45 +0000 (11:59 +0100)
Pair-Programmed-With: Anoop C S <anoopcs@redhat.com>
Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
src/socket_wrapper.c

index 94a219332b887624491d58f426f1bd5d7dbfff44..165922b79d0be36571cb9a7b9bb08b6986d5bd19 100644 (file)
@@ -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
@@ -1328,7 +1328,7 @@ done:
 static size_t socket_wrapper_max_sockets(void)
 {
        const char *s;
-       unsigned long tmp;
+       size_t tmp;
        char *endp;
 
        if (socket_info_max != 0) {
@@ -1346,10 +1346,20 @@ 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);
        }
 
        socket_info_max = tmp;