From d26ceb542342d6eef4a8df14f79ca2f81d1e550e Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 13 Nov 2018 08:31:43 +0100 Subject: [PATCH] swrap: Better handling for default values in socket_wrapper_max_sockets() Pair-Programmed-With: Anoop C S Signed-off-by: Andreas Schneider Signed-off-by: Anoop C S Reviewed-by: Ralph Boehme --- src/socket_wrapper.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index 94a2193..165922b 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 @@ -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; -- 2.34.1