uwrap: Add library constructor and move pthread_atfork inside.

Library constructor is used for pthread_atfork call. Moved here because
pthread_atfork is cumulative and should be called only once.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
uwrap: Fix race condition - glibc lookups.

Patch adds libc_symbol_binding_mutex which guards global table of libc
functions and their lookup.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
uid_wrapper: Fix race condition - uwrap_init.

Patch moves uwrap_id_mutex before if (uwrap.initialised) statement
which can be passed by concurrent threads.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
uwrap: Optimalization of uid_wrapper_enabled() function.

Check only bool variable inside uwrap structure instead
of calling whole uid_init().

In the best case only one mutex lock is need when check.

NOTES:
 * This patch uses __atomic_load gcc builtin function.
 * uid_init() were moved outside uid_wrapper_enabled() function.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
TESTS: Get rid of malloc calls in test_glibc_thread_support.c.

Thread structures are allocated on stack now.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
TESTS: Small phtread_attr cleanup.

This change should make valgrind happy.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
TESTS: Added two new tests aimed to setgid() and getgid() functions.

New tests:
 * test_sync_setgid - test if call of setgid() in thread changes gid
                      of main process
 * test_sync_setgid_syscall - test setgid() syscall

Signed-off-by: Robin Hack <hack.robin@gmail.com>
TESTS: test_glibc_thread_support: Add bigger load.

This can help (and helped) with revealing race conditions.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
uwrap: Small optimalization of uwrap_init().

Don't call getenv("UID_WRAPPER") on start of uwrap_init().

Signed-off-by: Robin Hack <hack.robin@gmail.com>
TESTS: Extend test_sync_setgid in test_glibc_thread_support.c

Extend test to case when thread changes gid of main process.
After this change main process start new thread which should have
same gid set as a main process.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
uwrap: Reflect changes of uid/gid in threads to main process.

When thread changes uid/gid this change must be reflected to main
process.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
TESTS: Fix test_sync_setgid_syscall in test_glibc_thread_support.c

When changes of gid (and uid of course) is reflected to main process
test must check if call of setgid syscall changes gid of thread ONLY.

Syscalls changes only uid/gid of thread. Call of libc functions changes
also uid/gid of main process.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
uwrap: Add NOTE to pthread_atfork.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
TESTS: Enable test_glibc_thread_support.c on Mac OS X

Signed-off-by: Robin Hack <hack.robin@gmail.com>
TESTS: Add new test test_sync_setgroups to test_glibc_thread_support.c

This test is almost same as test_sync_setgid but is aimed to setgroups
functions.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
uwrap: Add more authors to AUTHORS file.

Signed-off-by: Robin Hack <hack.robin@gmail.com>