diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index 30edbc7251f..d5294b2efa8 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -153,19 +153,14 @@ #if __GLIBC_PREREQ(2, 10) #define GPR_LINUX_SOCKETUTILS 1 #endif -#if __GLIBC_PREREQ(2, 17) -#define GPR_LINUX_ENV 1 -#endif #endif +#define GPR_LINUX_ENV 1 #ifndef GPR_LINUX_EVENTFD #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 #endif #ifndef GPR_LINUX_SOCKETUTILS #define GPR_POSIX_SOCKETUTILS #endif -#ifndef GPR_LINUX_ENV -#define GPR_POSIX_ENV 1 -#endif #define GPR_POSIX_FILE 1 #define GPR_POSIX_STRING 1 #define GPR_POSIX_SUBPROCESS 1 diff --git a/src/core/support/env_linux.c b/src/core/support/env_linux.c index 2e03365e338..183bcd2bd0a 100644 --- a/src/core/support/env_linux.c +++ b/src/core/support/env_linux.c @@ -49,8 +49,20 @@ #include "src/core/support/string.h" +char *__attribute__((weak)) secure_getenv(const char *name); +char *__attribute__((weak)) __secure_getenv(const char *name); + char *gpr_getenv(const char *name) { - char *result = secure_getenv(name); + static char *(*getenv_func)(const char *) = secure_getenv; + if (getenv_func == NULL) { + getenv_func = __secure_getenv; + if (getenv_func == NULL) { + gpr_log(GPR_DEBUG, + "No secure_getenv. Please consider upgrading your libc."); + getenv_func = getenv; + } + } + char *result = getenv_func(name); return result == NULL ? result : gpr_strdup(result); }