Skip to content
Snippets Groups Projects
Commit 1b1e2382 authored by Craig Tiller's avatar Craig Tiller
Browse files

Better dynamic linking

parent 2bf5169f
No related branches found
No related tags found
No related merge requests found
...@@ -340,7 +340,7 @@ endif ...@@ -340,7 +340,7 @@ endif
endif endif
   
ifeq ($(SYSTEM),Linux) ifeq ($(SYSTEM),Linux)
LIBS = rt m pthread LIBS = dl rt m pthread
LDFLAGS += -pthread LDFLAGS += -pthread
endif endif
   
......
...@@ -42,33 +42,23 @@ ...@@ -42,33 +42,23 @@
#include "src/core/support/env.h" #include "src/core/support/env.h"
#include <dlfcn.h>
#include <stdlib.h> #include <stdlib.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include <grpc/support/useful.h>
#include "src/core/support/string.h" #include "src/core/support/string.h"
/* Declare weak symbols for versions of secure_getenv that *may* be
* on a users machine. Older libc's call this __secure_getenv, even
* older don't support the functionality.
*
* If a symbol is not present, these will be equal to NULL.
*/
char *__attribute__((weak)) secure_getenv(const char *name);
char *__attribute__((weak)) __secure_getenv(const char *name);
char *gpr_getenv(const char *name) { char *gpr_getenv(const char *name) {
static char *(*getenv_func)(const char *) = secure_getenv; typedef char *(*getenv_type)(const char *);
static getenv_type getenv_func = NULL;
/* Check to see which getenv variant is supported (go from most /* Check to see which getenv variant is supported (go from most
* to least secure) */ * to least secure) */
if (getenv_func == NULL) { const char *names[] = {"secure_getenv", "__secure_getenv", "getenv"};
getenv_func = __secure_getenv; for (size_t i = 0; getenv_func == NULL && i < GPR_ARRAY_SIZE(names); i++) {
if (getenv_func == NULL) { getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]);
gpr_log(GPR_DEBUG,
"No secure_getenv. Please consider upgrading your libc.");
getenv_func = getenv;
}
} }
char *result = getenv_func(name); char *result = getenv_func(name);
return result == NULL ? result : gpr_strdup(result); return result == NULL ? result : gpr_strdup(result);
......
...@@ -253,7 +253,7 @@ ...@@ -253,7 +253,7 @@
endif endif
ifeq ($(SYSTEM),Linux) ifeq ($(SYSTEM),Linux)
LIBS = rt m pthread LIBS = dl rt m pthread
LDFLAGS += -pthread LDFLAGS += -pthread
endif endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment