aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2018-11-12 17:34:08 +0100
committerAndreas Schneider <asn@samba.org>2018-11-13 11:59:41 +0100
commit74c3a9a60e5cfb8d191876c24e88e5d3aa38ca58 (patch)
tree7a09b48b6c33180e4d8c5a59b6ae898eee6223b2 /src
parent87cc3f8e5433471e986c3b50e351ae49289b4cbe (diff)
downloadsocket_wrapper-74c3a9a60e5cfb8d191876c24e88e5d3aa38ca58.tar.gz
socket_wrapper-74c3a9a60e5cfb8d191876c24e88e5d3aa38ca58.tar.xz
socket_wrapper-74c3a9a60e5cfb8d191876c24e88e5d3aa38ca58.zip
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 <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>
Diffstat (limited to 'src')
-rw-r--r--src/socket_wrapper.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 514179e..94a2193 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -295,6 +295,13 @@ static struct socket_info_container *sockets;
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;
@@ -1360,7 +1367,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 +1375,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;
}
@@ -1500,11 +1507,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;
}
@@ -1551,11 +1558,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;
}
@@ -6253,7 +6260,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);
}