diff options
author | Andreas Schneider <asn@samba.org> | 2017-12-01 16:05:07 +0100 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2017-12-04 12:23:47 +0100 |
commit | 570930cff3511054eeeea1a3e5e8155946b501ef (patch) | |
tree | d88da169abb016ec2013205babaa68f19eef5b1d /src | |
parent | 3d0f65fcb183a0fb0e6ad122d929189ce5c0a2aa (diff) | |
download | socket_wrapper-570930cff3511054eeeea1a3e5e8155946b501ef.tar.gz socket_wrapper-570930cff3511054eeeea1a3e5e8155946b501ef.tar.xz socket_wrapper-570930cff3511054eeeea1a3e5e8155946b501ef.zip |
swrap: Bind all symbols during prepare
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/socket_wrapper.c | 79 |
1 files changed, 72 insertions, 7 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index 8da9d96..f6d7e24 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -694,14 +694,17 @@ static void *_swrap_bind_symbol(enum swrap_lib lib, const char *fn_name) } \ SWRAP_UNLOCK(libc_symbol_binding) -/* - * IMPORTANT +/**************************************************************************** + * IMPORTANT + **************************************************************************** * - * Functions especially from libc need to be loaded individually, you can't load - * all at once or gdb will segfault at startup. The same applies to valgrind and - * has probably something todo with with the linker. - * So we need load each function at the point it is called the first time. - */ + * Functions especially from libc need to be loaded individually, you can't + * load all at once or gdb will segfault at startup. The same applies to + * valgrind and has probably something todo with with the linker. So we need + * load each function at the point it is called the first time. + * + ****************************************************************************/ + #ifdef HAVE_ACCEPT4 static int libc_accept4(int sockfd, struct sockaddr *addr, @@ -1077,6 +1080,59 @@ static ssize_t libc_writev(int fd, const struct iovec *iov, int iovcnt) return swrap.libc.symbols._libc_writev.f(fd, iov, iovcnt); } +/* DO NOT call this function during library initialization! */ +static void swrap_bind_symbol_all(void) +{ +#ifdef HAVE_ACCEPT4 + swrap_bind_symbol_libsocket(accept4); +#else + swrap_bind_symbol_libsocket(accept); +#endif + swrap_bind_symbol_libsocket(bind); + swrap_bind_symbol_libc(close); + swrap_bind_symbol_libsocket(connect); + swrap_bind_symbol_libc(dup); + swrap_bind_symbol_libc(dup2); + swrap_bind_symbol_libc(fcntl); + swrap_bind_symbol_libc(fopen); +#ifdef HAVE_FOPEN64 + swrap_bind_symbol_libc(fopen64); +#endif +#ifdef HAVE_EVENTFD + swrap_bind_symbol_libc(eventfd); +#endif + swrap_bind_symbol_libsocket(getpeername); + swrap_bind_symbol_libsocket(getsockname); + swrap_bind_symbol_libsocket(getsockopt); + swrap_bind_symbol_libc(ioctl); + swrap_bind_symbol_libsocket(listen); + swrap_bind_symbol_libc(open); +#ifdef HAVE_OPEN64 + swrap_bind_symbol_libc(open64); +#endif + swrap_bind_symbol_libc(openat); + swrap_bind_symbol_libsocket(pipe); + swrap_bind_symbol_libc(read); + swrap_bind_symbol_libsocket(readv); + swrap_bind_symbol_libsocket(recv); + swrap_bind_symbol_libsocket(recvfrom); + swrap_bind_symbol_libsocket(recvmsg); + swrap_bind_symbol_libsocket(send); + swrap_bind_symbol_libsocket(sendmsg); + swrap_bind_symbol_libsocket(sendto); + swrap_bind_symbol_libsocket(setsockopt); +#ifdef HAVE_SIGNALFD + swrap_bind_symbol_libsocket(signalfd); +#endif + swrap_bind_symbol_libsocket(socket); + swrap_bind_symbol_libsocket(socketpair); +#ifdef HAVE_TIMERFD_CREATE + swrap_bind_symbol_libc(timerfd_create); +#endif + swrap_bind_symbol_libc(write); + swrap_bind_symbol_libsocket(writev); +} + /********************************************************* * SWRAP HELPER FUNCTIONS *********************************************************/ @@ -5835,6 +5891,15 @@ int pledge(const char *promises, const char *paths[]) static void swrap_thread_prepare(void) { + /* + * This function should only be called here!! + * + * We bind all symobls to avoid deadlocks of the fork is + * interrupted by a signal handler using a symbol of this + * library. + */ + swrap_bind_symbol_all(); + SWRAP_LOCK_ALL; } |