swrap: Replace socket_fds linked list with an array
authorAnoop C S <anoopcs@redhat.com>
Sun, 10 Jun 2018 07:49:14 +0000 (13:19 +0530)
committerAndreas Schneider <asn@samba.org>
Thu, 14 Jun 2018 09:05:17 +0000 (11:05 +0200)
commit5529ba060519017bb71de5de6e7b81e5b3d56ccf
treede8dceef2b2fdd372617e49f222426825eafbf07
parent321833e2696f1964eef6ff1bfa2455da735a372a
swrap: Replace socket_fds linked list with an array

This fixes the following bug:

As we are using a doubly linked list, we need a mutex which needs to be
locked when we are reading it that we do not end up with invalid
pointers.

The following can happen:

We are in swrap_close() which calls find_socket_info_fd() this locks the
mutex for the linked list. Now we get a singal SIGCHILD and the signal
handler is called. The signal handler calls swrap_write() and we try to
find out if the socket is managed by socket_wrapper calling
find_socket_info_fd() again -> DEADLOCK!

By moving to an array to handle the socket fds and using the fd as the
array access, we do not need a mutex for reading anymore. All we need is
a memory barrier.

This change also improves the performance as we move from the a linked
list to a hash table!

Pair-Programmed-With: Andreas Schneider <asn@samba.org>

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
src/socket_wrapper.c