From 939c8edd9763ad5ffc62767b2b51549736fcaa20 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 30 May 2014 19:06:10 +0200 Subject: [PATCH] src: use LIBC_SO from GNU libc, if available Look for gnu/lib-names.h and use the LIBC_SO define to dlopen libc, so the right library is loaded without manually searching for libc.so.N. --- ConfigureChecks.cmake | 1 + config.h.cmake | 1 + src/uid_wrapper.c | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 123128f..4848d28 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -52,6 +52,7 @@ check_include_file(sys/syscall.h HAVE_SYS_SYSCALL_H) check_include_file(syscall.h HAVE_SYSCALL_H) check_include_file(grp.h HAVE_GRP_H) check_include_file(unistd.h HAVE_UNISTD_H) +check_include_file(gnu/lib-names.h HAVE_GNU_LIB_NAMES_H) # FUNCTIONS check_function_exists(strncpy HAVE_STRNCPY) diff --git a/config.h.cmake b/config.h.cmake index 0e67b23..7c2d6df 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -19,6 +19,7 @@ #cmakedefine HAVE_SYSCALL_H 1 #cmakedefine HAVE_UNISTD_H 1 #cmakedefine HAVE_GRP_H 1 +#cmakedefine HAVE_GNU_LIB_NAMES_H 1 /*************************** FUNCTIONS ***************************/ diff --git a/src/uid_wrapper.c b/src/uid_wrapper.c index e9c7d5a..4c7b526 100644 --- a/src/uid_wrapper.c +++ b/src/uid_wrapper.c @@ -37,6 +37,10 @@ #include +#ifdef HAVE_GNU_LIB_NAMES_H +#include +#endif + #ifdef HAVE_GCC_THREAD_LOCAL_STORAGE # define UWRAP_THREAD __thread #else @@ -205,6 +209,13 @@ static void *uwrap_load_lib_handle(enum uwrap_lib lib) /* FALL TROUGH */ case UWRAP_LIBC: handle = uwrap.libc.handle; +#ifdef LIBC_SO + if (handle == NULL) { + handle = dlopen(LIBC_SO, flags); + + uwrap.libc.handle = handle; + } +#endif if (handle == NULL) { for (handle = NULL, i = 10; handle == NULL && i >= 0; i--) { char soname[256] = {0}; -- 2.0.0.rc2