summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-12-10 08:21:12 +0100
committerAndreas Schneider <asn@cryptomilk.org>2013-12-10 08:21:12 +0100
commit9f7d7b4bdf1a17619fc4b1bb9569621e6f0b20c9 (patch)
tree84183f42f6d018cec8f052c79f6ddb3372c038d5
parente5899b84480c46c3ba5d7d24a97d9bc63d7baa7c (diff)
downloadsocket_wrapper-9f7d7b4bdf1a17619fc4b1bb9569621e6f0b20c9.zip
socket_wrapper-9f7d7b4bdf1a17619fc4b1bb9569621e6f0b20c9.tar.gz
socket_wrapper-9f7d7b4bdf1a17619fc4b1bb9569621e6f0b20c9.tar.xz
swrap: Remove obsolete init functions.
This fixes preloading libsocket_wrapper.so with gdb.
-rw-r--r--src/socket_wrapper.c150
1 files changed, 1 insertions, 149 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index f2fa8ce..4964ec1 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -432,150 +432,6 @@ static void *_swrap_load_lib_function(enum swrap_lib lib, const char *fn_name)
}
-static void *swrap_libc_fn(void *handle, const char *fn_name)
-{
- void *func;
-
- if (handle == NULL) {
- return NULL;
- }
-
- func = dlsym(handle, fn_name);
- if (func == NULL) {
- SWRAP_LOG(SWRAP_LOG_ERROR,
- "Failed to find %s: %s\n",
- fn_name, dlerror());
- exit(-1);
- }
-
- return func;
-}
-
-static void swrap_libc_init(void)
-{
- int i;
- int flags = RTLD_LAZY;
- void *handle;
-
-#ifdef HAVE_APPLE
- handle = RTLD_NEXT;
-#else /* !HAVE_APPLE */
-
-#ifdef RTLD_DEEPBIND
- flags |= RTLD_DEEPBIND;
-#endif
-
- /* Load libc.so */
- for (swrap.libc_handle = NULL, i = 10; swrap.libc_handle == NULL && i >= 0; i--) {
- char soname[256] = {0};
-
- snprintf(soname, sizeof(soname), "%s.%d", LIBC_NAME, i);
- swrap.libc_handle = dlopen(soname, flags);
- }
-
- if (swrap.libc_handle == NULL) {
- SWRAP_LOG(SWRAP_LOG_ERROR,
- "Failed to dlopen %s.%d: %s\n",
- LIBC_NAME, i, dlerror());
- exit(-1);
- }
-
-#ifdef HAVE_LIBSOCKET
- for (swrap.libsocket_handle = NULL, i = 10; swrap.libsocket_handle == NULL && i >= 0; i--) {
- char soname[256] = {0};
- i = 1;
-
- snprintf(soname, sizeof(soname), "libsocket.so.%d", i);
- swrap.libsocket_handle = dlopen(soname, flags);
- }
-
- if (swrap.libsocket_handle == NULL) {
- SWRAP_LOG(SWRAP_LOG_ERROR,
- "Failed to dlopen libsocket.so: %s",
- dlerror());
- exit(-1);
- }
-#endif /* HAVE_LIBSOCKET */
-
-#endif /* !HAVE_APPLE */
-
- /* Load libc functions */
-#ifndef HAVE_APPLE
- handle = swrap.libc_handle;
-#endif
- *(void **) (&swrap.fns.libc_close) =
- swrap_libc_fn(handle, "close");
- *(void **) (&swrap.fns.libc_dup) =
- swrap_libc_fn(handle, "dup");
- *(void **) (&swrap.fns.libc_dup2) =
- swrap_libc_fn(handle, "dup2");
- *(void **) (&swrap.fns.libc_ioctl) =
- swrap_libc_fn(handle, "ioctl");
- *(void **) (&swrap.fns.libc_read) =
- swrap_libc_fn(handle, "read");
- *(void **) (&swrap.fns.libc_readv) =
- swrap_libc_fn(handle, "readv");
- *(void **) (&swrap.fns.libc_writev) =
- swrap_libc_fn(handle, "writev");
-
- /* Load libsocket funcitons */
-#if !defined(HAVE_APPLE) && defined(HAVE_LIBSOCKET)
- handle = swrap.libsocket_handle;
-#endif
-
- *(void **) (&swrap.fns.libc_accept) =
- swrap_libc_fn(handle, "accept");
- *(void **) (&swrap.fns.libc_bind) =
- swrap_libc_fn(handle, "bind");
- *(void **) (&swrap.fns.libc_connect) =
- swrap_libc_fn(handle, "connect");
- *(void **) (&swrap.fns.libc_getpeername) =
- swrap_libc_fn(handle, "getpeername");
- *(void **) (&swrap.fns.libc_getsockname) =
- swrap_libc_fn(handle, "getsockname");
- *(void **) (&swrap.fns.libc_getsockopt) =
- swrap_libc_fn(handle, "getsockopt");
- *(void **) (&swrap.fns.libc_listen) =
- swrap_libc_fn(handle, "listen");
- *(void **) (&swrap.fns.libc_recv) =
- swrap_libc_fn(handle, "recv");
- *(void **) (&swrap.fns.libc_recvfrom) =
- swrap_libc_fn(handle, "recvfrom");
- *(void **) (&swrap.fns.libc_send) =
- swrap_libc_fn(handle, "send");
- *(void **) (&swrap.fns.libc_sendmsg) =
- swrap_libc_fn(handle, "sendmsg");
- *(void **) (&swrap.fns.libc_sendto) =
- swrap_libc_fn(handle, "sendto");
- *(void **) (&swrap.fns.libc_setsockopt) =
- swrap_libc_fn(handle, "setsockopt");
- *(void **) (&swrap.fns.libc_socket) =
- swrap_libc_fn(handle, "socket");
-}
-
-static void swrap_init(void)
-{
- if (swrap.initialised) {
- return;
- }
-
- swrap.socket_dir = strdup(socket_wrapper_dir());
- if (swrap.socket_dir != NULL) {
- swrap.enabled = true;
- }
-
- swrap_libc_init();
-
- swrap.initialised = true;
-}
-
-static int swrap_enabled(void)
-{
- swrap_init();
-
- return swrap.enabled ? 1 : 0;
-}
-
/*
* IMPORTANT
*
@@ -1174,10 +1030,6 @@ static struct socket_info *find_socket_info(int fd)
{
struct socket_info *i;
- if (!swrap_enabled()) {
- return NULL;
- }
-
for (i = sockets; i; i = i->next) {
struct socket_info_fd *f;
for (f = i->fds; f; f = f->next) {
@@ -2025,7 +1877,7 @@ static int swrap_socket(int family, int type, int protocol)
real_type &= ~SOCK_NONBLOCK;
#endif
- if (!swrap_enabled()) {
+ if (socket_wrapper_dir() == NULL) {
return libc_socket(family, type, protocol);
}