socket_wrapper.git
5 years agoBump version to 1.2.0 socket_wrapper-1.2.0
Andreas Schneider [Mon, 12 Nov 2018 10:14:20 +0000 (11:14 +0100)]
Bump version to 1.2.0

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agoswrap: Also log the process name
Andreas Schneider [Mon, 12 Nov 2018 14:22:35 +0000 (15:22 +0100)]
swrap: Also log the process name

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agoswrap: Better handling for default values in socket_wrapper_max_sockets()
Andreas Schneider [Tue, 13 Nov 2018 07:31:43 +0000 (08:31 +0100)]
swrap: Better handling for default values in socket_wrapper_max_sockets()

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>
5 years agoswrap: Always allocate the socket fd array to the maximum
Andreas Schneider [Mon, 12 Nov 2018 16:34:08 +0000 (17:34 +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 <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>
5 years agoswrap: Rename global variable for max sockets
Andreas Schneider [Mon, 12 Nov 2018 16:00:09 +0000 (17:00 +0100)]
swrap: Rename global variable for max sockets

We also need a mutex to protect access to it.

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>
5 years agotests: Enable threaded test cases on FreeBSD
Anoop C S [Sat, 10 Nov 2018 05:27:27 +0000 (10:57 +0530)]
tests: Enable threaded test cases on FreeBSD

It was previously judged as a bug which now turned to be due to
wrong backlog count set in echo_srv while listening on socket.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Increase backlog count for listen() in echo_srv
Anoop C S [Sat, 10 Nov 2018 05:26:24 +0000 (10:56 +0530)]
tests: Increase backlog count for listen() in echo_srv

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agogitlab-ci: Add csbuild
Andreas Schneider [Wed, 7 Nov 2018 07:31:50 +0000 (08:31 +0100)]
gitlab-ci: Add csbuild

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Protect IPv6 in st_echo_tcp_get_peer_sock_name
Andreas Schneider [Wed, 7 Nov 2018 08:05:30 +0000 (09:05 +0100)]
tests: Protect IPv6 in st_echo_tcp_get_peer_sock_name

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: SWRAP_REQUIRED_LIBRARIES should be a list
Andreas Schneider [Wed, 7 Nov 2018 08:02:35 +0000 (09:02 +0100)]
cmake: SWRAP_REQUIRED_LIBRARIES should be a list

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Set LINK_FLAGS for echo_srv
Andreas Schneider [Wed, 7 Nov 2018 08:14:40 +0000 (09:14 +0100)]
cmake: Set LINK_FLAGS for echo_srv

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Set LINK_FLAGS for socket_wrapper
Andreas Schneider [Wed, 7 Nov 2018 08:13:26 +0000 (09:13 +0100)]
cmake: Set LINK_FLAGS for socket_wrapper

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Only set default flags if they have been detected
Andreas Schneider [Wed, 7 Nov 2018 08:25:54 +0000 (09:25 +0100)]
cmake: Only set default flags if they have been detected

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Disable stack protector on Solaris
Andreas Schneider [Wed, 7 Nov 2018 08:27:38 +0000 (09:27 +0100)]
cmake: Disable stack protector on Solaris

They don't work.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agogitlab-ci: Enable freebsd runner
Andreas Schneider [Tue, 30 Oct 2018 12:01:27 +0000 (13:01 +0100)]
gitlab-ci: Enable freebsd runner

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Disable failing tests as on FreeBSD
Andreas Schneider [Tue, 30 Oct 2018 12:00:51 +0000 (13:00 +0100)]
tests: Disable failing tests as on FreeBSD

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Create a list with required libraries
Andreas Schneider [Wed, 31 Oct 2018 07:07:17 +0000 (08:07 +0100)]
cmake: Create a list with required libraries

This should fix the build on OmniOS.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Protect IPv6 function in setup_echo_srv_tcp_ipv6
Andreas Schneider [Mon, 5 Nov 2018 07:29:25 +0000 (08:29 +0100)]
tests: Protect IPv6 function in setup_echo_srv_tcp_ipv6

Fixes the build on OmniOS.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Protect IPv6 case in echo_srv
Andreas Schneider [Wed, 31 Oct 2018 07:04:03 +0000 (08:04 +0100)]
tests: Protect IPv6 case in echo_srv

This fixes the build on OmniOS.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agoswrap: Protect IPv6 case in swrap_socket()
Andreas Schneider [Wed, 31 Oct 2018 07:02:25 +0000 (08:02 +0100)]
swrap: Protect IPv6 case in swrap_socket()

Fixes the build on OmniOS

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Don't use string PREPEND
Andreas Schneider [Wed, 24 Oct 2018 06:44:19 +0000 (08:44 +0200)]
cmake: Don't use string PREPEND

This is only supported in cmake >= 3.10.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agoswrap: Fix coverity issues
Anoop C S [Fri, 26 Oct 2018 10:14:53 +0000 (15:44 +0530)]
swrap: Fix coverity issues

CID 184220
CID 184221

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agogitlab-ci: Disable the FreeBSD runner
Andreas Schneider [Tue, 2 Oct 2018 14:40:16 +0000 (16:40 +0200)]
gitlab-ci: Disable the FreeBSD runner

There is a threading race condition in FreeBSD.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agogitlab-ci: Add helgrind tests
Andreas Schneider [Thu, 27 Sep 2018 19:10:45 +0000 (21:10 +0200)]
gitlab-ci: Add helgrind tests

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agogitlab-ci: Add runners and toolchain files
Andreas Schneider [Thu, 27 Sep 2018 15:56:11 +0000 (17:56 +0200)]
gitlab-ci: Add runners and toolchain files

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Init in_addr only once in test_tcp_socket_overwrite
Andreas Schneider [Mon, 1 Oct 2018 19:34:44 +0000 (21:34 +0200)]
tests: Init in_addr only once in test_tcp_socket_overwrite

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Return an error if setenv() fails in test_max_sockets
Andreas Schneider [Mon, 1 Oct 2018 19:28:27 +0000 (21:28 +0200)]
tests: Return an error if setenv() fails in test_max_sockets

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Check the correct return code in test_thread_echo_tcp_write_read
Andreas Schneider [Mon, 1 Oct 2018 19:28:06 +0000 (21:28 +0200)]
tests: Check the correct return code in test_thread_echo_tcp_write_read

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Check return code of connect in test_thread_echo_tcp_sendmsg_recvmsg
Andreas Schneider [Mon, 1 Oct 2018 19:27:40 +0000 (21:27 +0200)]
tests: Check return code of connect in test_thread_echo_tcp_sendmsg_recvmsg

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Check the return code of connect in test_echo_udp_sendmsg_recvmsg
Andreas Schneider [Mon, 1 Oct 2018 19:31:19 +0000 (21:31 +0200)]
tests: Check the return code of connect in test_echo_udp_sendmsg_recvmsg

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Check return code of connnect in test_echo_tcp_sendmsg_recvmsg
Andreas Schneider [Mon, 1 Oct 2018 19:27:14 +0000 (21:27 +0200)]
tests: Check return code of connnect in test_echo_tcp_sendmsg_recvmsg

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agoecho_srv: Check for a valid pidfile pointer
Andreas Schneider [Mon, 1 Oct 2018 19:23:31 +0000 (21:23 +0200)]
echo_srv: Check for a valid pidfile pointer

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agoecho_srv: Only use 128K as buffer size instead of 4MB
Andreas Schneider [Mon, 1 Oct 2018 08:54:53 +0000 (10:54 +0200)]
echo_srv: Only use 128K as buffer size instead of 4MB

This produced errors built with clang.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotorture: Wait longer for echo_srv startup
Andreas Schneider [Thu, 27 Sep 2018 16:19:42 +0000 (18:19 +0200)]
torture: Wait longer for echo_srv startup

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agoecho_srv: Do not close bogus file descriptors
Andreas Schneider [Fri, 28 Sep 2018 10:55:49 +0000 (12:55 +0200)]
echo_srv: Do not close bogus file descriptors

==1564== Warning: invalid file descriptor 1048564 in syscall close()
==1564==    at 0x4D18534: close (in /lib64/libc-2.27.so)
==1564==    by 0x4046A74: libc_close (socket_wrapper.c:760)
==1564==    by 0x405105C: swrap_close (socket_wrapper.c:5933)
==1564==    by 0x40511F5: close (socket_wrapper.c:5979)
==1564==    by 0x401679: become_daemon (echo_srv.c:202)
==1564==    by 0x402D44: main (echo_srv.c:896)
==1563==

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agoswrap: Don't do a deep bind if we run with libasan
Andreas Schneider [Sat, 1 Sep 2018 17:36:19 +0000 (19:36 +0200)]
swrap: Don't do a deep bind if we run with libasan

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agoswrap: Add a mutex for resetting socket index
Andreas Schneider [Fri, 28 Sep 2018 10:46:30 +0000 (12:46 +0200)]
swrap: Add a mutex for resetting socket index

Fixes a helgrind error.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agoswrap: Fix helgrind errors
Anoop C S [Wed, 19 Sep 2018 08:11:49 +0000 (13:41 +0530)]
swrap: Fix helgrind errors

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Use assert_return_code() to get errno
Andreas Schneider [Fri, 28 Sep 2018 06:11:57 +0000 (08:11 +0200)]
tests: Use assert_return_code() to get errno

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Avoid -Wcast-align warning
Anoop C S [Wed, 29 Aug 2018 23:18:30 +0000 (04:48 +0530)]
tests: Avoid -Wcast-align warning

warning: cast from 'struct sockaddr *' to 'struct sockaddr_in *'
                increases required alignment from 2 to 4 [-Wcast-align]
        struct sockaddr_in *sinp = (struct sockaddr_in *)to; ^~~~~~~~~~~~~~~~~~~~~~~~

Above warning can be avoided by making use of sockaddr_in available
within torture_address from the caller of echo_udp_recv_from_to().
Following that sa_socklen from torture_address can be used instead of
passing sa_socklen explicitly to echo_udp_recv_from_to().

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Fix -Wformat gcc warning
Anoop C S [Tue, 28 Aug 2018 16:41:31 +0000 (22:11 +0530)]
tests: Fix -Wformat gcc warning

test_fork_thread_deadlock.c:48:25: warning: format ‘%d’ expects argument
    of type ‘int’, but argument 3 has type ‘pid_t {aka long int}’ [-Wformat=]

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Fix checking for required system libraries
Andreas Schneider [Thu, 27 Sep 2018 16:31:26 +0000 (18:31 +0200)]
cmake: Fix checking for required system libraries

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Use target_include_directories()
Andreas Schneider [Thu, 27 Sep 2018 15:52:19 +0000 (17:52 +0200)]
cmake: Use target_include_directories()

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Require modern cmake version
Andreas Schneider [Mon, 10 Sep 2018 06:34:03 +0000 (08:34 +0200)]
cmake: Require modern cmake version

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Update AddCMockaTest
Andreas Schneider [Thu, 27 Sep 2018 15:22:57 +0000 (17:22 +0200)]
cmake: Update AddCMockaTest

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Update cmocka requirement
Andreas Schneider [Thu, 27 Sep 2018 15:50:02 +0000 (17:50 +0200)]
cmake: Update cmocka requirement

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Support running the tests with AddressSanitizer
Andreas Schneider [Sat, 1 Sep 2018 18:46:52 +0000 (20:46 +0200)]
cmake: Support running the tests with AddressSanitizer

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Add CFLAGS for AddressSanitizer and UndefinedSanitizer
Andreas Schneider [Wed, 5 Sep 2018 13:39:35 +0000 (15:39 +0200)]
cmake: Add CFLAGS for AddressSanitizer and UndefinedSanitizer

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Move Compiler flags to new file
Andreas Schneider [Wed, 5 Sep 2018 13:38:37 +0000 (15:38 +0200)]
cmake: Move Compiler flags to new file

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Remove obsolete DefineCompilerFlags.cmake
Andreas Schneider [Sun, 2 Sep 2018 09:18:45 +0000 (11:18 +0200)]
cmake: Remove obsolete DefineCompilerFlags.cmake

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Improve checks for compiler flags
Andreas Schneider [Sun, 2 Sep 2018 09:18:09 +0000 (11:18 +0200)]
cmake: Improve checks for compiler flags

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Update CMake defaults
Andreas Schneider [Tue, 2 Oct 2018 14:37:43 +0000 (16:37 +0200)]
cmake: Update CMake defaults

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Suppress helgrind race condition warning we created on purpose
Andreas Schneider [Fri, 28 Sep 2018 09:01:15 +0000 (11:01 +0200)]
cmake: Suppress helgrind race condition warning we created on purpose

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Create an error if helgrind finds a bug
Andreas Schneider [Thu, 27 Sep 2018 19:08:23 +0000 (21:08 +0200)]
cmake: Create an error if helgrind finds a bug

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Write helgrind logs to stderr so we can see them
Andreas Schneider [Thu, 6 Sep 2018 16:40:17 +0000 (18:40 +0200)]
cmake: Write helgrind logs to stderr so we can see them

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agocmake: Don't misuse CMAKE_REQUIRED_LIBRARIES
Andreas Schneider [Sat, 1 Sep 2018 18:32:04 +0000 (20:32 +0200)]
cmake: Don't misuse CMAKE_REQUIRED_LIBRARIES

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
5 years agotests: Update valgrind suppression file
Andreas Schneider [Tue, 14 Aug 2018 09:42:38 +0000 (11:42 +0200)]
tests: Update valgrind suppression file

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agocmake: Require at least cmake 3.2.0
Andreas Schneider [Thu, 9 Aug 2018 09:16:29 +0000 (11:16 +0200)]
cmake: Require at least cmake 3.2.0

This allows us to modernize the CMakeLists.txt

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agoctest: Move to new dashboard
Andreas Schneider [Thu, 5 Jul 2018 08:14:14 +0000 (10:14 +0200)]
ctest: Move to new dashboard

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agoswrap: Add error check around pthread mutex locks
Anoop C S [Tue, 12 Jun 2018 14:49:34 +0000 (20:19 +0530)]
swrap: Add error check around pthread mutex locks

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agotests: Prevent child process falling to defunct state
Anoop C S [Wed, 27 Jun 2018 18:05:28 +0000 (23:35 +0530)]
tests: Prevent child process falling to defunct state

Parent process does not wait for child process(which gets forked after
accepting a client connection) to exit inside echo server which in turn
puts child into defunct state. Even though those defunct childs are
cleaned up during parent exit it is better to wait from parent process
itself.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agodoc: Add SOCKET_WRAPPER_MAX_SOCKETS to manual page
Anoop C S [Mon, 25 Jun 2018 13:45:44 +0000 (19:15 +0530)]
doc: Add SOCKET_WRAPPER_MAX_SOCKETS to manual page

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agoswrap: Fix thread deadlock found by Coverity scan
Anoop C S [Fri, 15 Jun 2018 07:06:54 +0000 (12:36 +0530)]
swrap: Fix thread deadlock found by Coverity scan

CID 175897
CID 175898

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agotests: Add missing header for IPPROTO_TCP
Andreas Schneider [Fri, 29 Jun 2018 13:17:10 +0000 (15:17 +0200)]
tests: Add missing header for IPPROTO_TCP

This fixes the build on FreeBSD.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agoswrap: Update header
Andreas Schneider [Fri, 22 Jun 2018 06:47:08 +0000 (08:47 +0200)]
swrap: Update header

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agoUpdate LICENSE
Andreas Schneider [Fri, 22 Jun 2018 06:42:06 +0000 (08:42 +0200)]
Update LICENSE

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agoRename COPYING to LICENSE
Andreas Schneider [Fri, 22 Jun 2018 06:38:04 +0000 (08:38 +0200)]
Rename COPYING to LICENSE

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agocpack: Do not package build dirs in source tarball
Andreas Schneider [Fri, 22 Jun 2018 07:01:19 +0000 (09:01 +0200)]
cpack: Do not package build dirs in source tarball

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
5 years agoswrap: Replace socket_fds linked list with an array
Anoop C S [Sun, 10 Jun 2018 07:49:14 +0000 (13:19 +0530)]
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>
6 years agotests: Fix resouce leak in echo_srv tcp handling
Andreas Schneider [Fri, 4 May 2018 06:01:29 +0000 (08:01 +0200)]
tests: Fix resouce leak in echo_srv tcp handling

CID 175587

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
6 years agocmake: Run threaded tests with helgrind
Andreas Schneider [Wed, 2 May 2018 15:05:21 +0000 (17:05 +0200)]
cmake: Run threaded tests with helgrind

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agotests: Add test case to validate free-list indexes
Anoop C S [Wed, 31 Jan 2018 17:13:21 +0000 (22:43 +0530)]
tests: Add test case to validate free-list indexes

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Update free-list only when refcount is zero
Anoop C S [Wed, 31 Jan 2018 17:16:23 +0000 (22:46 +0530)]
swrap: Update free-list only when refcount is zero

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Move metadata into socket_info_meta structure
Michael Adam [Wed, 12 Jul 2017 23:25:19 +0000 (01:25 +0200)]
swrap: Move metadata into socket_info_meta structure

Separating out the metadata related information to another
sub-structure to make it more clean and structured.

Pair-Programmed-With: Anoop C S <anoopcs@redhat.com>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agotests: New threaded test cases
Anoop C S [Thu, 2 Mar 2017 07:26:20 +0000 (07:26 +0000)]
tests: New threaded test cases

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agotests: Modify echo server to accept multiple connections
Anoop C S [Thu, 2 Mar 2017 07:12:50 +0000 (07:12 +0000)]
tests: Modify echo server to accept multiple connections

In context of multiple threads, echo server must be capable of
accepting connections in a loop rather than be satisfied with
one incoming connection.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agotests: Add new test to check mutex lock contention
Michael Adam [Thu, 22 Sep 2016 01:53:27 +0000 (03:53 +0200)]
tests: Add new test to check mutex lock contention

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Implement thread safety using pthread mutexes
Anoop C S [Tue, 28 Mar 2017 07:13:47 +0000 (07:13 +0000)]
swrap: Implement thread safety using pthread mutexes

Added a new mutex variable to socket_info structure along with
new macros for locking and unlocking mutex corresponding to
each socket_info entry. Apart from individual mutex defined in
socket_info structure, 4 new mutexes are added to protect the
concurrent access of globally used swrap parameters from different
threads.

All other individual wrappers and helper routines are also made
capable of acquiring relevant mutex locks before operating on such
global parameters.

Pair-Programmed-With: Michael Adam <obnox@samba.org>

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Rearrange swrap_remove_stale
Anoop C S [Thu, 13 Jul 2017 09:43:07 +0000 (15:13 +0530)]
swrap: Rearrange swrap_remove_stale

In preparation to implement thread safety, re-ordering lines
of code to properly align to lockign calls

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Rearrange swrap_close
Anoop C S [Thu, 13 Jul 2017 09:50:15 +0000 (15:20 +0530)]
swrap: Rearrange swrap_close

In preparation to implement thread safety, re-ordering lines
of code to properly align to locking calls.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Remove swrap_first_free_index
Anoop C S [Tue, 29 Aug 2017 08:59:16 +0000 (14:29 +0530)]
swrap: Remove swrap_first_free_index

swrap_first_free_index is no longer used as the whole logic now
implemented within swrap_create_socket.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Use swrap_create_socket within swrap_accept
Anoop C S [Tue, 29 Aug 2017 09:04:58 +0000 (14:34 +0530)]
swrap: Use swrap_create_socket within swrap_accept

Replace the current logic of socket creation within swrap_accept
with more cleaner version using swrap_create_socket.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Use swrap_create_socket within swrap_socket
Anoop C S [Tue, 29 Aug 2017 09:04:28 +0000 (14:34 +0530)]
swrap: Use swrap_create_socket within swrap_socket

Replace the current logic of socket creation within swrap_socket
with more cleaner version using swrap_create_socket.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Add new routines to handle socket creation
Anoop C S [Tue, 29 Aug 2017 07:10:35 +0000 (12:40 +0530)]
swrap: Add new routines to handle socket creation

A new function named swrap_create_socket is introduced which
cleanly performs all stuff related to creation of new socket
file descriptors and updation of relevant metadata including
the free-list and reference counter.

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Internal reorganization of core socket_info structures
Michael Adam [Sat, 15 Jul 2017 09:10:07 +0000 (14:40 +0530)]
swrap: Internal reorganization of core socket_info structures

The change basically splits socket_info structure into
two structures, namely,
    - socket_info: to store the core information
      corresponding to a socket entry.
    - socket_info_container: wrapping structure to hold
      the socket_info data as well as metadata(currently
      refcount and next_free).

Pair-Programmed-With: Anoop C S <anoopcs@redhat.com>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Reorder code inside swrap_socket
Michael Adam [Wed, 2 Aug 2017 11:56:09 +0000 (13:56 +0200)]
swrap: Reorder code inside swrap_socket

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Use swrap_get_socket_info inside socket_wrapper_first_free_index
Michael Adam [Tue, 18 Jul 2017 10:53:03 +0000 (12:53 +0200)]
swrap: Use swrap_get_socket_info inside socket_wrapper_first_free_index

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: set errno to ENFILE if there is no more free socket_info
Michael Adam [Tue, 18 Jul 2017 10:50:15 +0000 (12:50 +0200)]
swrap: set errno to ENFILE if there is no more free socket_info

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: New helper functions to treat next_free
Michael Adam [Wed, 12 Jul 2017 23:01:57 +0000 (01:01 +0200)]
swrap: New helper functions to treat next_free

- swrap_get_next_free
- swrap_set_next_free

to avoid accessing socket_info.next_free directly

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Use helper functions to manage refcount
Anoop C S [Thu, 1 Mar 2018 05:09:20 +0000 (10:39 +0530)]
swrap: Use helper functions to manage refcount

- swrap_get_refcount
- swrap_alter_refcount

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Use helper function swrap_get_socket_info
Anoop C S [Thu, 1 Mar 2018 05:04:54 +0000 (10:34 +0530)]
swrap: Use helper function swrap_get_socket_info

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agoswrap: Make early-libc-out more obvious by removing else
Michael Adam [Thu, 13 Jul 2017 00:40:11 +0000 (02:40 +0200)]
swrap: Make early-libc-out more obvious by removing else

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
6 years agotests: Increase wait time for setup and teardown to 5ms
Andreas Schneider [Wed, 2 May 2018 10:23:50 +0000 (12:23 +0200)]
tests: Increase wait time for setup and teardown to 5ms

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
6 years agotests: Remove extra test by moving getsockname() to another
Anoop C S [Fri, 23 Mar 2018 11:42:49 +0000 (17:12 +0530)]
tests: Remove extra test by moving getsockname() to another

test_echo_tcp_socket currently tests socket() and getsockname() network
calls. The test name was misleading as it does not require echo server
to be setup. Moreover it failed to create socket_wrapper directory which
is the pre-requisite for testing with libsocket_wrapper.

Therefore it is better to integrate getsockname() test into existing
test_tcp_listen test and remove useless test_echo_tcp_socket

Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
6 years agocmake: Fix configure check for fall-through attribute
Andreas Schneider [Wed, 28 Feb 2018 06:36:58 +0000 (07:36 +0100)]
cmake: Fix configure check for fall-through attribute

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
6 years agocmake: Fix checks for attributes
Andreas Schneider [Thu, 22 Feb 2018 08:37:40 +0000 (09:37 +0100)]
cmake: Fix checks for attributes

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
6 years agoswrap: Avoid double semicolons in the code
Andreas Schneider [Tue, 20 Feb 2018 16:52:00 +0000 (17:52 +0100)]
swrap: Avoid double semicolons in the code

Compilers that don't support fallthrough will end up with an empty
FALL_THROUGH define and just see a semicolon. The probably will warn
that there are double semicolons in the code.

Signed-off-by: Andreas Schneider <asn@samba.org>
6 years agoBump version to 1.1.9 socket_wrapper-1.1.9
Andreas Schneider [Mon, 4 Dec 2017 09:19:38 +0000 (10:19 +0100)]
Bump version to 1.1.9

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agotests: Add a thread deadlock reproducer
Andreas Schneider [Tue, 28 Nov 2017 14:41:05 +0000 (15:41 +0100)]
tests: Add a thread deadlock reproducer

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
6 years agoswrap: Avoid symbol binding deadlocks during fork
Andreas Schneider [Mon, 27 Nov 2017 10:00:54 +0000 (11:00 +0100)]
swrap: Avoid symbol binding deadlocks during fork

If there is a signal handler defined, e.g. for SIGCHILD and this signal
handler is called during pthread_atfork() has just locked all mutexes
and we want to check if a symbol is bound, we end up in a deadlock.

(gdb) bt
 0  __lll_lock_wait () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135
 1  0x00007fe48837aef5 in __GI___pthread_mutex_lock (mutex=0x7fe4889a71c0 <libc_symbol_binding_mutex>) at ../nptl/pthread_mutex_lock.c:80
 2  0x00007fe48879b2f1 in libc_write (fd=14, buf=0x7ffdad6436e8, count=8) at /home/asn/workspace/projects/socket_wrapper/src/socket_wrapper.c:1070
 3  0x00007fe4887a21cb in swrap_write (s=14, buf=0x7ffdad6436e8, len=8) at /home/asn/workspace/projects/socket_wrapper/src/socket_wrapper.c:5137
 4  0x00007fe4887a2359 in write (s=14, buf=0x7ffdad6436e8, len=8) at /home/asn/workspace/projects/socket_wrapper/src/socket_wrapper.c:5171
 5  0x00007fe48713e5f2 in tevent_common_wakeup_fd (fd=14) at ../lib/tevent/tevent.c:959
 6  0x00007fe48713e61f in tevent_common_wakeup (ev=ev@entry=0x55d04922e280) at ../lib/tevent/tevent.c:975
 7  0x00007fe487141d38 in tevent_common_signal_handler (signum=<optimized out>) at ../lib/tevent/tevent_signal.c:109
 8  <signal handler called>
 9  0x00007fe4844de081 in __libc_fork () at ../sysdeps/nptl/fork.c:135
 10 0x000055d047e8ddb3 in smbd_accept_connection (ev=0x55d04922e280, fde=<optimized out>, flags=<optimized out>, private_data=<optimized out>)
    at ../source3/smbd/server.c:992

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>