Quiet down getenv

pull/11770/head
ncteisen 8 years ago
parent 85fac6df57
commit 79764a3bfb
  1. 2
      src/core/lib/support/env.h
  2. 35
      src/core/lib/support/env_linux.c
  3. 5
      src/core/lib/support/env_posix.c
  4. 5
      src/core/lib/support/env_windows.c
  5. 9
      src/core/lib/support/log.c

@ -36,6 +36,8 @@ char *gpr_getenv(const char *name);
/* Sets the the environment with the specified name to the specified value. */
void gpr_setenv(const char *name, const char *value);
char *gpr_getenv_silent(const char *name, char** dst);
#ifdef __cplusplus
}
#endif

@ -38,8 +38,10 @@
#include "src/core/lib/support/string.h"
char *gpr_getenv(const char *name) {
#if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
char *gpr_getenv_silent(const char *name, char** dst) {
char* insecure_func_used = NULL;
char* result = NULL;
#if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
typedef char *(*getenv_type)(const char *);
static getenv_type getenv_func = NULL;
/* Check to see which getenv variant is supported (go from most
@ -48,22 +50,29 @@ char *gpr_getenv(const char *name) {
for (size_t i = 0; getenv_func == NULL && i < GPR_ARRAY_SIZE(names); i++) {
getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]);
if (getenv_func != NULL && strstr(names[i], "secure") == NULL) {
gpr_log(GPR_DEBUG,
"Warning: insecure environment read function '%s' used",
names[i]);
insecure_func_used = names[i];
}
}
char *result = getenv_func(name);
return result == NULL ? result : gpr_strdup(result);
result = getenv_func(name);
#elif __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17)
char *result = secure_getenv(name);
return result == NULL ? result : gpr_strdup(result);
result = secure_getenv(name);
#else
gpr_log(GPR_DEBUG, "Warning: insecure environment read function '%s' used",
"getenv");
char *result = getenv(name);
return result == NULL ? result : gpr_strdup(result);
result = getenv(name);
insecure_func_used = "getenv";
#endif
*dst = result == NULL ? result : gpr_strdup(result);
return insecure_func_used;
}
char *gpr_getenv(const char *name) {
char* result = NULL;
char* insecure_func_used = gpr_getenv_silent(name, &result);
if (insecure_func_used != NULL) {
gpr_log(GPR_DEBUG,
"Warning: insecure environment read function '%s' used",
insecure_func_used);
}
return result;
}
void gpr_setenv(const char *name, const char *value) {

@ -29,6 +29,11 @@
#include <grpc/support/string_util.h>
#include "src/core/lib/support/string.h"
char *gpr_getenv_silent(const char *name, char **dst) {
*dst = gpr_getenv(name);
return NULL;
}
char *gpr_getenv(const char *name) {
char *result = getenv(name);
return result == NULL ? result : gpr_strdup(result);

@ -30,6 +30,11 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
char *gpr_getenv_silent(const char *name, char **dst) {
*dst = gpr_getenv(name);
return NULL;
}
char *gpr_getenv(const char *name) {
char *result = NULL;
DWORD size;

@ -64,7 +64,8 @@ void gpr_set_log_verbosity(gpr_log_severity min_severity_to_print) {
}
void gpr_log_verbosity_init() {
char *verbosity = gpr_getenv("GRPC_VERBOSITY");
char *verbosity = NULL;
char *insecure_getenv = gpr_getenv_silent("GRPC_VERBOSITY", &verbosity);
gpr_atm min_severity_to_print = GPR_LOG_SEVERITY_ERROR;
if (verbosity != NULL) {
@ -81,6 +82,12 @@ void gpr_log_verbosity_init() {
GPR_LOG_VERBOSITY_UNSET) {
gpr_atm_no_barrier_store(&g_min_severity_to_print, min_severity_to_print);
}
if (insecure_getenv != NULL) {
gpr_log(GPR_DEBUG,
"Warning: insecure environment read function '%s' used",
insecure_getenv);
}
}
void gpr_set_log_function(gpr_log_func f) {

Loading…
Cancel
Save