diff options
author | Vijay Pai <vpai@google.com> | 2016-02-25 18:10:24 -0800 |
---|---|---|
committer | Vijay Pai <vpai@google.com> | 2016-02-25 18:10:24 -0800 |
commit | e9ef53645150f7a0400a5f9be770eb2b4ba335b5 (patch) | |
tree | 34a8b7094b851589eec500b2ca419b64c9051d89 /src/core/security | |
parent | e3cd25684051de21e4b1ba93173c06e72fa5ffad (diff) |
Revert "Add an implementation firewall against pollset_set"
Diffstat (limited to 'src/core/security')
-rw-r--r-- | src/core/security/google_default_credentials.c | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/src/core/security/google_default_credentials.c b/src/core/security/google_default_credentials.c index 1f4f3e4aa5..458d0d3ac3 100644 --- a/src/core/security/google_default_credentials.c +++ b/src/core/security/google_default_credentials.c @@ -52,14 +52,13 @@ static grpc_channel_credentials *default_credentials = NULL; static int compute_engine_detection_done = 0; -static gpr_mu g_state_mu; -static gpr_mu *g_polling_mu; +static gpr_mu g_mu; static gpr_once g_once = GPR_ONCE_INIT; -static void init_default_credentials(void) { gpr_mu_init(&g_state_mu); } +static void init_default_credentials(void) { gpr_mu_init(&g_mu); } typedef struct { - grpc_pollset *pollset; + grpc_pollset pollset; int is_done; int success; } compute_engine_detector; @@ -81,10 +80,10 @@ static void on_compute_engine_detection_http_response( } } } - gpr_mu_lock(g_polling_mu); + gpr_mu_lock(GRPC_POLLSET_MU(&detector->pollset)); detector->is_done = 1; - grpc_pollset_kick(detector->pollset, NULL); - gpr_mu_unlock(g_polling_mu); + grpc_pollset_kick(&detector->pollset, NULL); + gpr_mu_unlock(GRPC_POLLSET_MU(&detector->pollset)); } static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool s) { @@ -102,8 +101,7 @@ static int is_stack_running_on_compute_engine(void) { on compute engine. */ gpr_timespec max_detection_delay = gpr_time_from_seconds(1, GPR_TIMESPAN); - detector.pollset = gpr_malloc(grpc_pollset_size()); - grpc_pollset_init(detector.pollset, &g_polling_mu); + grpc_pollset_init(&detector.pollset); detector.is_done = 0; detector.success = 0; @@ -114,7 +112,7 @@ static int is_stack_running_on_compute_engine(void) { grpc_httpcli_context_init(&context); grpc_httpcli_get( - &exec_ctx, &context, detector.pollset, &request, + &exec_ctx, &context, &detector.pollset, &request, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), max_detection_delay), on_compute_engine_detection_http_response, &detector); @@ -122,22 +120,19 @@ static int is_stack_running_on_compute_engine(void) { /* Block until we get the response. This is not ideal but this should only be called once for the lifetime of the process by the default credentials. */ - gpr_mu_lock(g_polling_mu); + gpr_mu_lock(GRPC_POLLSET_MU(&detector.pollset)); while (!detector.is_done) { grpc_pollset_worker *worker = NULL; - grpc_pollset_work(&exec_ctx, detector.pollset, &worker, + grpc_pollset_work(&exec_ctx, &detector.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC), gpr_inf_future(GPR_CLOCK_MONOTONIC)); } - gpr_mu_unlock(g_polling_mu); + gpr_mu_unlock(GRPC_POLLSET_MU(&detector.pollset)); grpc_httpcli_context_destroy(&context); - grpc_closure_init(&destroy_closure, destroy_pollset, detector.pollset); - grpc_pollset_shutdown(&exec_ctx, detector.pollset, &destroy_closure); + grpc_closure_init(&destroy_closure, destroy_pollset, &detector.pollset); + grpc_pollset_shutdown(&exec_ctx, &detector.pollset, &destroy_closure); grpc_exec_ctx_finish(&exec_ctx); - g_polling_mu = NULL; - - gpr_free(detector.pollset); return detector.success; } @@ -189,7 +184,7 @@ grpc_channel_credentials *grpc_google_default_credentials_create(void) { gpr_once_init(&g_once, init_default_credentials); - gpr_mu_lock(&g_state_mu); + gpr_mu_lock(&g_mu); if (default_credentials != NULL) { result = grpc_channel_credentials_ref(default_credentials); @@ -235,19 +230,19 @@ end: gpr_log(GPR_ERROR, "Could not create google default credentials."); } } - gpr_mu_unlock(&g_state_mu); + gpr_mu_unlock(&g_mu); return result; } void grpc_flush_cached_google_default_credentials(void) { gpr_once_init(&g_once, init_default_credentials); - gpr_mu_lock(&g_state_mu); + gpr_mu_lock(&g_mu); if (default_credentials != NULL) { grpc_channel_credentials_unref(default_credentials); default_credentials = NULL; } compute_engine_detection_done = 0; - gpr_mu_unlock(&g_state_mu); + gpr_mu_unlock(&g_mu); } /* -- Well known credentials path. -- */ |