From 96264e07b88e33c3b18fd43b107db1650684d4fe Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 14 Sep 2022 11:53:55 -0700 Subject: [PATCH] Revert "[c++] Move environment functions to C++ (#30937)" (#30986) This reverts commit 74c0d6fe3f755a8817e98c8fd02f7fe918b9b276. --- BUILD | 33 +---- CMakeLists.txt | 6 +- Makefile | 6 +- build_autogenerated.yaml | 8 +- config.m4 | 6 +- config.w32 | 6 +- gRPC-C++.podspec | 4 +- gRPC-Core.podspec | 10 +- grpc.gemspec | 8 +- grpc.gyp | 6 +- package.xml | 8 +- .../ext/filters/client_channel/http_proxy.cc | 25 ++-- .../outlier_detection/outlier_detection.cc | 9 +- .../google_c2p/google_c2p_resolver.cc | 15 +-- src/core/ext/xds/xds_bootstrap.cc | 10 +- src/core/ext/xds/xds_client_grpc.cc | 17 +-- src/core/ext/xds/xds_route_config.cc | 15 +-- src/core/lib/{gprpp => gpr}/env.h | 37 ++---- src/core/lib/{gprpp => gpr}/env_linux.cc | 35 +++--- src/core/lib/{gprpp => gpr}/env_posix.cc | 21 ++-- src/core/lib/{gprpp => gpr}/env_windows.cc | 38 +++--- src/core/lib/gprpp/global_config_env.cc | 13 +- .../aws_external_account_credentials.cc | 31 ++--- .../google_default/credentials_generic.cc | 13 +- .../google_default_credentials.cc | 9 +- src/cpp/client/secure_credentials.cc | 13 +- src/cpp/ext/gcp/BUILD | 2 - src/cpp/ext/gcp/observability_config.cc | 21 ++-- .../tests/CronetTests/CronetUnitTests.mm | 2 +- src/python/grpcio/grpc_core_dependencies.py | 6 +- .../client_channel/http_proxy_mapper_test.cc | 6 +- .../resolvers/google_c2p_resolver_test.cc | 4 +- .../rls_lb_config_parser_test.cc | 2 +- test/core/end2end/fixtures/h2_http_proxy.cc | 4 +- test/core/end2end/fuzzers/api_fuzzer.cc | 8 +- test/core/filters/filter_fuzzer.cc | 8 +- test/core/gpr/env_test.cc | 20 ++-- test/core/gprpp/global_config_env_test.cc | 28 ++--- test/core/gprpp/global_config_test.cc | 2 +- test/core/http/httpscli_test.cc | 2 +- test/core/iomgr/resolve_address_posix_test.cc | 2 +- test/core/security/alts_credentials_fuzzer.cc | 6 +- test/core/security/credentials_test.cc | 113 +++++++++--------- test/core/security/system_roots_test.cc | 2 +- test/core/util/BUILD | 2 - test/core/util/fuzzer_corpus_test.cc | 13 +- test/core/util/test_config.cc | 6 +- test/core/xds/xds_bootstrap_test.cc | 20 ++-- test/core/xds/xds_client_test.cc | 6 +- test/cpp/client/credentials_test.cc | 8 +- test/cpp/end2end/cfstream_test.cc | 4 +- test/cpp/end2end/channelz_service_test.cc | 4 +- .../end2end/client_callback_end2end_test.cc | 4 +- test/cpp/end2end/client_lb_end2end_test.cc | 4 +- test/cpp/end2end/end2end_test.cc | 4 +- test/cpp/end2end/flaky_network_test.cc | 2 +- test/cpp/end2end/grpclb_end2end_test.cc | 4 +- test/cpp/end2end/hybrid_end2end_test.cc | 4 +- test/cpp/end2end/port_sharing_end2end_test.cc | 4 +- test/cpp/end2end/raw_end2end_test.cc | 2 +- test/cpp/end2end/rls_end2end_test.cc | 6 +- test/cpp/end2end/shutdown_test.cc | 2 +- test/cpp/end2end/thread_stress_test.cc | 4 +- .../end2end/xds/xds_cluster_end2end_test.cc | 2 +- .../xds/xds_cluster_type_end2end_test.cc | 4 +- test/cpp/end2end/xds/xds_core_end2end_test.cc | 2 +- test/cpp/end2end/xds/xds_csds_end2end_test.cc | 2 +- test/cpp/end2end/xds/xds_end2end_test.cc | 4 +- test/cpp/end2end/xds/xds_end2end_test_lib.cc | 10 +- test/cpp/end2end/xds/xds_end2end_test_lib.h | 6 +- .../xds/xds_fault_injection_end2end_test.cc | 2 +- .../xds/xds_outlier_detection_end2end_test.cc | 6 +- .../end2end/xds/xds_ring_hash_end2end_test.cc | 4 +- test/cpp/end2end/xds/xds_rls_end2end_test.cc | 4 +- .../end2end/xds/xds_routing_end2end_test.cc | 2 +- test/cpp/ext/gcp/observability_config_test.cc | 16 +-- test/cpp/interop/istio_echo_server.cc | 2 +- test/cpp/interop/xds_interop_client.cc | 2 +- ...resolver_component_tests_runner_invoker.cc | 7 +- test/cpp/qps/client.h | 13 +- test/cpp/qps/driver.cc | 14 ++- test/cpp/qps/json_run_localhost.cc | 4 +- test/cpp/util/channelz_sampler_test.cc | 2 +- test/cpp/util/grpc_tool_test.cc | 10 +- tools/doxygen/Doxyfile.c++.internal | 8 +- tools/doxygen/Doxyfile.core.internal | 8 +- 86 files changed, 435 insertions(+), 442 deletions(-) rename src/core/lib/{gprpp => gpr}/env.h (52%) rename src/core/lib/{gprpp => gpr}/env_linux.cc (69%) rename src/core/lib/{gprpp => gpr}/env_posix.cc (68%) rename src/core/lib/{gprpp => gpr}/env_windows.cc (52%) diff --git a/BUILD b/BUILD index 9a2f21b63a4..7233fa0150d 100644 --- a/BUILD +++ b/BUILD @@ -1021,23 +1021,6 @@ grpc_cc_library( deps = ["gpr_platform"], ) -grpc_cc_library( - name = "env", - srcs = [ - "src/core/lib/gprpp/env_linux.cc", - "src/core/lib/gprpp/env_posix.cc", - "src/core/lib/gprpp/env_windows.cc", - ], - hdrs = [ - "src/core/lib/gprpp/env.h", - ], - external_deps = ["absl/types:optional"], - deps = [ - "gpr_platform", - "tchar", - ], -) - grpc_cc_library( name = "gpr", srcs = [ @@ -1046,6 +1029,9 @@ grpc_cc_library( "src/core/lib/gpr/cpu_linux.cc", "src/core/lib/gpr/cpu_posix.cc", "src/core/lib/gpr/cpu_windows.cc", + "src/core/lib/gpr/env_linux.cc", + "src/core/lib/gpr/env_posix.cc", + "src/core/lib/gpr/env_windows.cc", "src/core/lib/gpr/log.cc", "src/core/lib/gpr/log_android.cc", "src/core/lib/gpr/log_linux.cc", @@ -1079,6 +1065,7 @@ grpc_cc_library( ], hdrs = [ "src/core/lib/gpr/alloc.h", + "src/core/lib/gpr/env.h", "src/core/lib/gpr/string.h", "src/core/lib/gpr/time_precise.h", "src/core/lib/gpr/tmpfile.h", @@ -1116,7 +1103,6 @@ grpc_cc_library( visibility = ["@grpc:public"], deps = [ "construct_destruct", - "env", "examine_stack", "gpr_atm", "gpr_tls", @@ -3844,7 +3830,6 @@ grpc_cc_library( "debug_location", "default_event_engine", "dual_ref_counted", - "env", "gpr", "gpr_atm", "grpc_backend_metric_data", @@ -4470,7 +4455,6 @@ grpc_cc_library( "debug_location", "default_event_engine", "dual_ref_counted", - "env", "envoy_admin_upb", "envoy_config_core_upb", "envoy_config_endpoint_upb", @@ -4599,7 +4583,6 @@ grpc_cc_library( "config", "debug_location", "default_event_engine", - "env", "envoy_admin_upb", "envoy_config_cluster_upb", "envoy_config_cluster_upbdefs", @@ -5184,7 +5167,6 @@ grpc_cc_library( "closure", "config", "debug_location", - "env", "exec_ctx", "gpr", "grpc_base", @@ -5754,7 +5736,6 @@ grpc_cc_library( "alts_util", "config", "debug_location", - "env", "gpr", "grpc_base", "grpc_codegen", @@ -6098,7 +6079,6 @@ grpc_cc_library( tags = ["nofixdeps"], deps = [ "alts_util", - "env", "gpr", "grpc_alts_credentials", "grpc_base", @@ -6321,12 +6301,10 @@ grpc_cc_library( "absl/strings", "absl/strings:str_format", "absl/time", - "absl/types:optional", "libcrypto", ], language = "c++", deps = [ - "env", "gpr", "grpc_base", "grpc_credentials_util", @@ -7198,8 +7176,8 @@ grpc_cc_library( "absl/status:statusor", "absl/strings", "absl/synchronization", - "absl/memory", "absl/types:optional", + "absl/memory", "upb_lib", "protobuf_headers", "absl/container:inlined_vector", @@ -7214,7 +7192,6 @@ grpc_cc_library( "channel_init", "channel_stack_type", "config", - "env", "error", "gpr", "gpr_manual_constructor", diff --git a/CMakeLists.txt b/CMakeLists.txt index dd00c929a54..ccda5fbbef7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1531,6 +1531,9 @@ add_library(gpr src/core/lib/gpr/cpu_linux.cc src/core/lib/gpr/cpu_posix.cc src/core/lib/gpr/cpu_windows.cc + src/core/lib/gpr/env_linux.cc + src/core/lib/gpr/env_posix.cc + src/core/lib/gpr/env_windows.cc src/core/lib/gpr/log.cc src/core/lib/gpr/log_android.cc src/core/lib/gpr/log_linux.cc @@ -1552,9 +1555,6 @@ add_library(gpr src/core/lib/gpr/tmpfile_posix.cc src/core/lib/gpr/tmpfile_windows.cc src/core/lib/gpr/wrap_memcpy.cc - src/core/lib/gprpp/env_linux.cc - src/core/lib/gprpp/env_posix.cc - src/core/lib/gprpp/env_windows.cc src/core/lib/gprpp/examine_stack.cc src/core/lib/gprpp/fork.cc src/core/lib/gprpp/global_config_env.cc diff --git a/Makefile b/Makefile index 5296cebb37e..96a4a6f535b 100644 --- a/Makefile +++ b/Makefile @@ -847,6 +847,9 @@ LIBGPR_SRC = \ src/core/lib/gpr/cpu_linux.cc \ src/core/lib/gpr/cpu_posix.cc \ src/core/lib/gpr/cpu_windows.cc \ + src/core/lib/gpr/env_linux.cc \ + src/core/lib/gpr/env_posix.cc \ + src/core/lib/gpr/env_windows.cc \ src/core/lib/gpr/log.cc \ src/core/lib/gpr/log_android.cc \ src/core/lib/gpr/log_linux.cc \ @@ -868,9 +871,6 @@ LIBGPR_SRC = \ src/core/lib/gpr/tmpfile_posix.cc \ src/core/lib/gpr/tmpfile_windows.cc \ src/core/lib/gpr/wrap_memcpy.cc \ - src/core/lib/gprpp/env_linux.cc \ - src/core/lib/gprpp/env_posix.cc \ - src/core/lib/gprpp/env_windows.cc \ src/core/lib/gprpp/examine_stack.cc \ src/core/lib/gprpp/fork.cc \ src/core/lib/gprpp/global_config_env.cc \ diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index a809b78941d..5d6ef262ef1 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -199,13 +199,13 @@ libs: - include/grpc/support/time.h headers: - src/core/lib/gpr/alloc.h + - src/core/lib/gpr/env.h - src/core/lib/gpr/string.h - src/core/lib/gpr/time_precise.h - src/core/lib/gpr/tls.h - src/core/lib/gpr/tmpfile.h - src/core/lib/gpr/useful.h - src/core/lib/gprpp/construct_destruct.h - - src/core/lib/gprpp/env.h - src/core/lib/gprpp/examine_stack.h - src/core/lib/gprpp/fork.h - src/core/lib/gprpp/global_config.h @@ -228,6 +228,9 @@ libs: - src/core/lib/gpr/cpu_linux.cc - src/core/lib/gpr/cpu_posix.cc - src/core/lib/gpr/cpu_windows.cc + - src/core/lib/gpr/env_linux.cc + - src/core/lib/gpr/env_posix.cc + - src/core/lib/gpr/env_windows.cc - src/core/lib/gpr/log.cc - src/core/lib/gpr/log_android.cc - src/core/lib/gpr/log_linux.cc @@ -249,9 +252,6 @@ libs: - src/core/lib/gpr/tmpfile_posix.cc - src/core/lib/gpr/tmpfile_windows.cc - src/core/lib/gpr/wrap_memcpy.cc - - src/core/lib/gprpp/env_linux.cc - - src/core/lib/gprpp/env_posix.cc - - src/core/lib/gprpp/env_windows.cc - src/core/lib/gprpp/examine_stack.cc - src/core/lib/gprpp/fork.cc - src/core/lib/gprpp/global_config_env.cc diff --git a/config.m4 b/config.m4 index 959e92be8cb..d4d627f2aaa 100644 --- a/config.m4 +++ b/config.m4 @@ -496,6 +496,9 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/gpr/cpu_linux.cc \ src/core/lib/gpr/cpu_posix.cc \ src/core/lib/gpr/cpu_windows.cc \ + src/core/lib/gpr/env_linux.cc \ + src/core/lib/gpr/env_posix.cc \ + src/core/lib/gpr/env_windows.cc \ src/core/lib/gpr/log.cc \ src/core/lib/gpr/log_android.cc \ src/core/lib/gpr/log_linux.cc \ @@ -518,9 +521,6 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/gpr/tmpfile_posix.cc \ src/core/lib/gpr/tmpfile_windows.cc \ src/core/lib/gpr/wrap_memcpy.cc \ - src/core/lib/gprpp/env_linux.cc \ - src/core/lib/gprpp/env_posix.cc \ - src/core/lib/gprpp/env_windows.cc \ src/core/lib/gprpp/examine_stack.cc \ src/core/lib/gprpp/fork.cc \ src/core/lib/gprpp/global_config_env.cc \ diff --git a/config.w32 b/config.w32 index e625fd78b91..9bc4a792503 100644 --- a/config.w32 +++ b/config.w32 @@ -462,6 +462,9 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\gpr\\cpu_linux.cc " + "src\\core\\lib\\gpr\\cpu_posix.cc " + "src\\core\\lib\\gpr\\cpu_windows.cc " + + "src\\core\\lib\\gpr\\env_linux.cc " + + "src\\core\\lib\\gpr\\env_posix.cc " + + "src\\core\\lib\\gpr\\env_windows.cc " + "src\\core\\lib\\gpr\\log.cc " + "src\\core\\lib\\gpr\\log_android.cc " + "src\\core\\lib\\gpr\\log_linux.cc " + @@ -484,9 +487,6 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\gpr\\tmpfile_posix.cc " + "src\\core\\lib\\gpr\\tmpfile_windows.cc " + "src\\core\\lib\\gpr\\wrap_memcpy.cc " + - "src\\core\\lib\\gprpp\\env_linux.cc " + - "src\\core\\lib\\gprpp\\env_posix.cc " + - "src\\core\\lib\\gprpp\\env_windows.cc " + "src\\core\\lib\\gprpp\\examine_stack.cc " + "src\\core\\lib\\gprpp\\fork.cc " + "src\\core\\lib\\gprpp\\global_config_env.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 3cef0948b8f..91442fa917f 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -701,6 +701,7 @@ Pod::Spec.new do |s| 'src/core/lib/experiments/config.h', 'src/core/lib/experiments/experiments.h', 'src/core/lib/gpr/alloc.h', + 'src/core/lib/gpr/env.h', 'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/spinlock.h', 'src/core/lib/gpr/string.h', @@ -715,7 +716,6 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/cpp_impl_of.h', 'src/core/lib/gprpp/debug_location.h', 'src/core/lib/gprpp/dual_ref_counted.h', - 'src/core/lib/gprpp/env.h', 'src/core/lib/gprpp/examine_stack.h', 'src/core/lib/gprpp/fork.h', 'src/core/lib/gprpp/global_config.h', @@ -1563,6 +1563,7 @@ Pod::Spec.new do |s| 'src/core/lib/experiments/config.h', 'src/core/lib/experiments/experiments.h', 'src/core/lib/gpr/alloc.h', + 'src/core/lib/gpr/env.h', 'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/spinlock.h', 'src/core/lib/gpr/string.h', @@ -1577,7 +1578,6 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/cpp_impl_of.h', 'src/core/lib/gprpp/debug_location.h', 'src/core/lib/gprpp/dual_ref_counted.h', - 'src/core/lib/gprpp/env.h', 'src/core/lib/gprpp/examine_stack.h', 'src/core/lib/gprpp/fork.h', 'src/core/lib/gprpp/global_config.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 9cda6c58268..aa425e9e69e 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -1095,6 +1095,10 @@ Pod::Spec.new do |s| 'src/core/lib/gpr/cpu_linux.cc', 'src/core/lib/gpr/cpu_posix.cc', 'src/core/lib/gpr/cpu_windows.cc', + 'src/core/lib/gpr/env.h', + 'src/core/lib/gpr/env_linux.cc', + 'src/core/lib/gpr/env_posix.cc', + 'src/core/lib/gpr/env_windows.cc', 'src/core/lib/gpr/log.cc', 'src/core/lib/gpr/log_android.cc', 'src/core/lib/gpr/log_linux.cc', @@ -1131,10 +1135,6 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/cpp_impl_of.h', 'src/core/lib/gprpp/debug_location.h', 'src/core/lib/gprpp/dual_ref_counted.h', - 'src/core/lib/gprpp/env.h', - 'src/core/lib/gprpp/env_linux.cc', - 'src/core/lib/gprpp/env_posix.cc', - 'src/core/lib/gprpp/env_windows.cc', 'src/core/lib/gprpp/examine_stack.cc', 'src/core/lib/gprpp/examine_stack.h', 'src/core/lib/gprpp/fork.cc', @@ -2191,6 +2191,7 @@ Pod::Spec.new do |s| 'src/core/lib/experiments/config.h', 'src/core/lib/experiments/experiments.h', 'src/core/lib/gpr/alloc.h', + 'src/core/lib/gpr/env.h', 'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/spinlock.h', 'src/core/lib/gpr/string.h', @@ -2205,7 +2206,6 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/cpp_impl_of.h', 'src/core/lib/gprpp/debug_location.h', 'src/core/lib/gprpp/dual_ref_counted.h', - 'src/core/lib/gprpp/env.h', 'src/core/lib/gprpp/examine_stack.h', 'src/core/lib/gprpp/fork.h', 'src/core/lib/gprpp/global_config.h', diff --git a/grpc.gemspec b/grpc.gemspec index 590a6a8448f..ffab9a365cb 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -1008,6 +1008,10 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/gpr/cpu_linux.cc ) s.files += %w( src/core/lib/gpr/cpu_posix.cc ) s.files += %w( src/core/lib/gpr/cpu_windows.cc ) + s.files += %w( src/core/lib/gpr/env.h ) + s.files += %w( src/core/lib/gpr/env_linux.cc ) + s.files += %w( src/core/lib/gpr/env_posix.cc ) + s.files += %w( src/core/lib/gpr/env_windows.cc ) s.files += %w( src/core/lib/gpr/log.cc ) s.files += %w( src/core/lib/gpr/log_android.cc ) s.files += %w( src/core/lib/gpr/log_linux.cc ) @@ -1044,10 +1048,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/gprpp/cpp_impl_of.h ) s.files += %w( src/core/lib/gprpp/debug_location.h ) s.files += %w( src/core/lib/gprpp/dual_ref_counted.h ) - s.files += %w( src/core/lib/gprpp/env.h ) - s.files += %w( src/core/lib/gprpp/env_linux.cc ) - s.files += %w( src/core/lib/gprpp/env_posix.cc ) - s.files += %w( src/core/lib/gprpp/env_windows.cc ) s.files += %w( src/core/lib/gprpp/examine_stack.cc ) s.files += %w( src/core/lib/gprpp/examine_stack.h ) s.files += %w( src/core/lib/gprpp/fork.cc ) diff --git a/grpc.gyp b/grpc.gyp index 31d27a6be64..749adf1981d 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -314,6 +314,9 @@ 'src/core/lib/gpr/cpu_linux.cc', 'src/core/lib/gpr/cpu_posix.cc', 'src/core/lib/gpr/cpu_windows.cc', + 'src/core/lib/gpr/env_linux.cc', + 'src/core/lib/gpr/env_posix.cc', + 'src/core/lib/gpr/env_windows.cc', 'src/core/lib/gpr/log.cc', 'src/core/lib/gpr/log_android.cc', 'src/core/lib/gpr/log_linux.cc', @@ -335,9 +338,6 @@ 'src/core/lib/gpr/tmpfile_posix.cc', 'src/core/lib/gpr/tmpfile_windows.cc', 'src/core/lib/gpr/wrap_memcpy.cc', - 'src/core/lib/gprpp/env_linux.cc', - 'src/core/lib/gprpp/env_posix.cc', - 'src/core/lib/gprpp/env_windows.cc', 'src/core/lib/gprpp/examine_stack.cc', 'src/core/lib/gprpp/fork.cc', 'src/core/lib/gprpp/global_config_env.cc', diff --git a/package.xml b/package.xml index 1a41961f1d1..c70129bb2f1 100644 --- a/package.xml +++ b/package.xml @@ -990,6 +990,10 @@ + + + + @@ -1026,10 +1030,6 @@ - - - - diff --git a/src/core/ext/filters/client_channel/http_proxy.cc b/src/core/ext/filters/client_channel/http_proxy.cc index 4464e9dd6e4..150d947afed 100644 --- a/src/core/ext/filters/client_channel/http_proxy.cc +++ b/src/core/ext/filters/client_channel/http_proxy.cc @@ -40,8 +40,8 @@ #include #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/string.h" -#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/memory.h" #include "src/core/lib/handshaker/proxy_mapper_registry.h" @@ -73,9 +73,16 @@ absl::optional GetHttpProxyServer( */ absl::optional uri_str = args.GetOwnedString(GRPC_ARG_HTTP_PROXY); - if (!uri_str.has_value()) uri_str = GetEnv("grpc_proxy"); - if (!uri_str.has_value()) uri_str = GetEnv("https_proxy"); - if (!uri_str.has_value()) uri_str = GetEnv("http_proxy"); + auto get_env = [](const char* name) -> absl::optional { + char* v = gpr_getenv(name); + if (v == nullptr) return absl::nullopt; + std::string s(v); + gpr_free(v); + return s; + }; + if (!uri_str.has_value()) uri_str = get_env("grpc_proxy"); + if (!uri_str.has_value()) uri_str = get_env("https_proxy"); + if (!uri_str.has_value()) uri_str = get_env("http_proxy"); if (!uri_str.has_value()) return absl::nullopt; // an emtpy value means "don't use proxy" if (uri_str->empty()) return absl::nullopt; @@ -151,11 +158,11 @@ absl::optional HttpProxyMapper::MapName( return absl::nullopt; } /* Prefer using 'no_grpc_proxy'. Fallback on 'no_proxy' if it is not set. */ - auto no_proxy_str = GetEnv("no_grpc_proxy"); - if (!no_proxy_str.has_value()) { - no_proxy_str = GetEnv("no_proxy"); + auto no_proxy_str = UniquePtr(gpr_getenv("no_grpc_proxy")); + if (no_proxy_str == nullptr) { + no_proxy_str = UniquePtr(gpr_getenv("no_proxy")); } - if (no_proxy_str.has_value()) { + if (no_proxy_str != nullptr) { bool use_proxy = true; std::string server_host; std::string server_port; @@ -167,7 +174,7 @@ absl::optional HttpProxyMapper::MapName( std::string(server_uri).c_str()); } else { std::vector no_proxy_hosts = - absl::StrSplit(*no_proxy_str, ',', absl::SkipEmpty()); + absl::StrSplit(no_proxy_str.get(), ',', absl::SkipEmpty()); for (const auto& no_proxy_entry : no_proxy_hosts) { if (absl::EndsWithIgnoreCase(server_host, no_proxy_entry)) { gpr_log(GPR_INFO, "not using proxy for host in no_proxy list '%s'", diff --git a/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc b/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc index ebf85fe0bc0..ab0496d9c67 100644 --- a/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +++ b/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc @@ -42,6 +42,7 @@ #include "absl/types/variant.h" #include +#include #include #include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h" @@ -49,9 +50,9 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/debug/trace.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/debug_location.h" -#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -77,10 +78,10 @@ TraceFlag grpc_outlier_detection_lb_trace(false, "outlier_detection_lb"); // TODO(donnadionne): Remove once outlier detection is no longer experimental bool XdsOutlierDetectionEnabled() { - auto value = GetEnv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION"); - if (!value.has_value()) return false; + char* value = gpr_getenv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION"); bool parsed_value; - bool parse_succeeded = gpr_parse_bool_value(value->c_str(), &parsed_value); + bool parse_succeeded = gpr_parse_bool_value(value, &parsed_value); + gpr_free(value); return parse_succeeded && parsed_value; } diff --git a/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc b/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc index b852fd07621..9bd750fadc0 100644 --- a/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc @@ -42,8 +42,9 @@ #include "src/core/ext/xds/xds_client_grpc.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/core_configuration.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/debug_location.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/time.h" @@ -284,8 +285,8 @@ GoogleCloud2ProdResolver::GoogleCloud2ProdResolver(ResolverArgs args) // they may be talking to a completely different xDS server than we // want to. // TODO(roth): When we implement xDS federation, remove this constraint. - GetEnv("GRPC_XDS_BOOTSTRAP").has_value() || - GetEnv("GRPC_XDS_BOOTSTRAP_CONFIG").has_value()) { + UniquePtr(gpr_getenv("GRPC_XDS_BOOTSTRAP")) != nullptr || + UniquePtr(gpr_getenv("GRPC_XDS_BOOTSTRAP_CONFIG")) != nullptr) { using_dns_ = true; child_resolver_ = CoreConfiguration::Get().resolver_registry().CreateResolver( @@ -372,11 +373,11 @@ void GoogleCloud2ProdResolver::StartXdsResolver() { }; } // Allow the TD server uri to be overridden for testing purposes. - auto override_server = - GetEnv("GRPC_TEST_ONLY_GOOGLE_C2P_RESOLVER_TRAFFIC_DIRECTOR_URI"); + UniquePtr override_server( + gpr_getenv("GRPC_TEST_ONLY_GOOGLE_C2P_RESOLVER_TRAFFIC_DIRECTOR_URI")); const char* server_uri = - override_server.has_value() && !override_server->empty() - ? override_server->c_str() + override_server != nullptr && strlen(override_server.get()) > 0 + ? override_server.get() : "directpath-pa.googleapis.com"; Json xds_server = Json::Array{ Json::Object{ diff --git a/src/core/ext/xds/xds_bootstrap.cc b/src/core/ext/xds/xds_bootstrap.cc index 62e4264e078..d6212c316ef 100644 --- a/src/core/ext/xds/xds_bootstrap.cc +++ b/src/core/ext/xds/xds_bootstrap.cc @@ -18,20 +18,20 @@ #include "src/core/ext/xds/xds_bootstrap.h" -#include "absl/types/optional.h" +#include +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/string.h" -#include "src/core/lib/gprpp/env.h" namespace grpc_core { // TODO(donnadionne): check to see if federation is enabled, this will be // removed once federation is fully integrated and enabled by default. bool XdsFederationEnabled() { - auto value = GetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); - if (!value.has_value()) return false; + char* value = gpr_getenv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); bool parsed_value; - bool parse_succeeded = gpr_parse_bool_value(value->c_str(), &parsed_value); + bool parse_succeeded = gpr_parse_bool_value(value, &parsed_value); + gpr_free(value); return parse_succeeded && parsed_value; } diff --git a/src/core/ext/xds/xds_client_grpc.cc b/src/core/ext/xds/xds_client_grpc.cc index b9271588468..09ff976c49c 100644 --- a/src/core/ext/xds/xds_client_grpc.cc +++ b/src/core/ext/xds/xds_client_grpc.cc @@ -43,8 +43,9 @@ #include "src/core/ext/xds/xds_transport_grpc.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/debug/trace.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/debug_location.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" @@ -92,31 +93,31 @@ namespace { absl::StatusOr GetBootstrapContents(const char* fallback_config) { // First, try GRPC_XDS_BOOTSTRAP env var. - auto path = GetEnv("GRPC_XDS_BOOTSTRAP"); - if (path.has_value()) { + UniquePtr path(gpr_getenv("GRPC_XDS_BOOTSTRAP")); + if (path != nullptr) { if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) { gpr_log(GPR_INFO, "Got bootstrap file location from GRPC_XDS_BOOTSTRAP " "environment variable: %s", - path->c_str()); + path.get()); } grpc_slice contents; grpc_error_handle error = - grpc_load_file(path->c_str(), /*add_null_terminator=*/true, &contents); + grpc_load_file(path.get(), /*add_null_terminator=*/true, &contents); if (!GRPC_ERROR_IS_NONE(error)) return grpc_error_to_absl_status(error); std::string contents_str(StringViewFromSlice(contents)); grpc_slice_unref_internal(contents); return contents_str; } // Next, try GRPC_XDS_BOOTSTRAP_CONFIG env var. - auto env_config = GetEnv("GRPC_XDS_BOOTSTRAP_CONFIG"); - if (env_config.has_value()) { + UniquePtr env_config(gpr_getenv("GRPC_XDS_BOOTSTRAP_CONFIG")); + if (env_config != nullptr) { if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) { gpr_log(GPR_INFO, "Got bootstrap contents from GRPC_XDS_BOOTSTRAP_CONFIG " "environment variable"); } - return std::move(*env_config); + return env_config.get(); } // Finally, try fallback config. if (fallback_config != nullptr) { diff --git a/src/core/ext/xds/xds_route_config.cc b/src/core/ext/xds/xds_route_config.cc index 5938bbfacf4..f8f65560f04 100644 --- a/src/core/ext/xds/xds_route_config.cc +++ b/src/core/ext/xds/xds_route_config.cc @@ -55,6 +55,7 @@ #include "upb/upb.h" #include +#include #include #include "src/core/ext/xds/upb_utils.h" @@ -67,8 +68,8 @@ #include "src/core/ext/xds/xds_routing.h" #include "src/core/lib/channel/status_util.h" #include "src/core/lib/debug/trace.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/string.h" -#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/match.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/error.h" @@ -78,19 +79,19 @@ namespace grpc_core { // TODO(yashykt): Remove once RBAC is no longer experimental bool XdsRbacEnabled() { - auto value = GetEnv("GRPC_XDS_EXPERIMENTAL_RBAC"); - if (!value.has_value()) return false; + char* value = gpr_getenv("GRPC_XDS_EXPERIMENTAL_RBAC"); bool parsed_value; - bool parse_succeeded = gpr_parse_bool_value(value->c_str(), &parsed_value); + bool parse_succeeded = gpr_parse_bool_value(value, &parsed_value); + gpr_free(value); return parse_succeeded && parsed_value; } // TODO(donnadionne): Remove once RLS is no longer experimental bool XdsRlsEnabled() { - auto value = GetEnv("GRPC_EXPERIMENTAL_XDS_RLS_LB"); - if (!value.has_value()) return false; + char* value = gpr_getenv("GRPC_EXPERIMENTAL_XDS_RLS_LB"); bool parsed_value; - bool parse_succeeded = gpr_parse_bool_value(value->c_str(), &parsed_value); + bool parse_succeeded = gpr_parse_bool_value(value, &parsed_value); + gpr_free(value); return parse_succeeded && parsed_value; } diff --git a/src/core/lib/gprpp/env.h b/src/core/lib/gpr/env.h similarity index 52% rename from src/core/lib/gprpp/env.h rename to src/core/lib/gpr/env.h index c332aa2dee2..f5016c6fa06 100644 --- a/src/core/lib/gprpp/env.h +++ b/src/core/lib/gpr/env.h @@ -16,38 +16,25 @@ * */ -#ifndef GRPC_CORE_LIB_GPRPP_ENV_H -#define GRPC_CORE_LIB_GPRPP_ENV_H +#ifndef GRPC_CORE_LIB_GPR_ENV_H +#define GRPC_CORE_LIB_GPR_ENV_H #include -#include +#include -#include "absl/types/optional.h" +/* Env utility functions */ -namespace grpc_core { - -// Gets the environment variable value with the specified name. */ -absl::optional GetEnv(const char* name); +/* Gets the environment variable value with the specified name. + Returns a newly allocated string. It is the responsibility of the caller to + gpr_free the return value if not NULL (which means that the environment + variable exists). */ +char* gpr_getenv(const char* name); /* Sets the environment with the specified name to the specified value. */ -void SetEnv(const char* name, const char* value); -inline void SetEnv(const char* name, const std::string& value) { - SetEnv(name, value.c_str()); -} +void gpr_setenv(const char* name, const char* value); /* Deletes the variable name from the environment. */ -void UnsetEnv(const char* name); - -template -void SetOrUnsetEnv(const char* name, const absl::optional& value) { - if (value.has_value()) { - SetEnv(name, value.value()); - } else { - UnsetEnv(name); - } -} - -} // namespace grpc_core +void gpr_unsetenv(const char* name); -#endif /* GRPC_CORE_LIB_GPRPP_ENV_H */ +#endif /* GRPC_CORE_LIB_GPR_ENV_H */ diff --git a/src/core/lib/gprpp/env_linux.cc b/src/core/lib/gpr/env_linux.cc similarity index 69% rename from src/core/lib/gprpp/env_linux.cc rename to src/core/lib/gpr/env_linux.cc index 9ca479a6268..4b332468104 100644 --- a/src/core/lib/gprpp/env_linux.cc +++ b/src/core/lib/gpr/env_linux.cc @@ -23,24 +23,21 @@ #include -#include - -#include "absl/types/optional.h" - #ifdef GPR_LINUX_ENV -#if defined(GPR_BACKWARDS_COMPATIBILITY_MODE) #include -#endif - #include #include +#include -#include "src/core/lib/gprpp/env.h" +#include +#include -namespace grpc_core { +#include "src/core/lib/gpr/env.h" +#include "src/core/lib/gpr/string.h" +#include "src/core/lib/gpr/useful.h" -absl::optional GetEnv(const char* name) { +char* gpr_getenv(const char* name) { char* result = nullptr; #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE) typedef char* (*getenv_type)(const char*); @@ -48,8 +45,9 @@ absl::optional GetEnv(const char* name) { /* Check to see which getenv variant is supported (go from most * to least secure) */ if (getenv_func == nullptr) { - for (auto name : {"secure_getenv", "__secure_getenv", "getenv"}) { - getenv_func = reinterpret_cast(dlsym(RTLD_DEFAULT, name)); + const char* names[] = {"secure_getenv", "__secure_getenv", "getenv"}; + for (size_t i = 0; i < GPR_ARRAY_SIZE(names); i++) { + getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]); if (getenv_func != nullptr) { break; } @@ -61,20 +59,17 @@ absl::optional GetEnv(const char* name) { #else result = getenv(name); #endif - if (result == nullptr) return absl::nullopt; - return result; + return result == nullptr ? result : gpr_strdup(result); } -void SetEnv(const char* name, const char* value) { +void gpr_setenv(const char* name, const char* value) { int res = setenv(name, value, 1); - if (res != 0) abort(); + GPR_ASSERT(res == 0); } -void UnsetEnv(const char* name) { +void gpr_unsetenv(const char* name) { int res = unsetenv(name); - if (res != 0) abort(); + GPR_ASSERT(res == 0); } -} // namespace grpc_core - #endif /* GPR_LINUX_ENV */ diff --git a/src/core/lib/gprpp/env_posix.cc b/src/core/lib/gpr/env_posix.cc similarity index 68% rename from src/core/lib/gprpp/env_posix.cc rename to src/core/lib/gpr/env_posix.cc index fc85a778001..fb2a21c6699 100644 --- a/src/core/lib/gprpp/env_posix.cc +++ b/src/core/lib/gpr/env_posix.cc @@ -22,26 +22,25 @@ #include -#include "src/core/lib/gprpp/env.h" +#include +#include -namespace grpc_core { +#include "src/core/lib/gpr/env.h" +#include "src/core/lib/gpr/string.h" -absl::optional GetEnv(const char* name) { +char* gpr_getenv(const char* name) { char* result = getenv(name); - if (result == nullptr) return absl::nullopt; - return result; + return result == nullptr ? result : gpr_strdup(result); } -void SetEnv(const char* name, const char* value) { +void gpr_setenv(const char* name, const char* value) { int res = setenv(name, value, 1); - if (res != 0) abort(); + GPR_ASSERT(res == 0); } -void UnsetEnv(const char* name) { +void gpr_unsetenv(const char* name) { int res = unsetenv(name); - if (res != 0) abort(); + GPR_ASSERT(res == 0); } -} // namespace grpc_core - #endif /* GPR_POSIX_ENV */ diff --git a/src/core/lib/gprpp/env_windows.cc b/src/core/lib/gpr/env_windows.cc similarity index 52% rename from src/core/lib/gprpp/env_windows.cc rename to src/core/lib/gpr/env_windows.cc index a588642f069..85015c46840 100644 --- a/src/core/lib/gprpp/env_windows.cc +++ b/src/core/lib/gpr/env_windows.cc @@ -24,33 +24,37 @@ #include -#include "src/core/lib/gprpp/env.h" +#include +#include +#include + +#include "src/core/lib/gpr/env.h" +#include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/tchar.h" -namespace grpc_core { +char* gpr_getenv(const char* name) { + char* result = NULL; + auto tname = grpc_core::CharToTchar(name); + DWORD ret; -absl::optional GetEnv(const char* name) { - auto tname = CharToTchar(name); - DWORD ret = GetEnvironmentVariable(tname.c_str(), NULL, 0); - if (ret == 0) return absl::nullopt; + ret = GetEnvironmentVariable(tname.c_str(), NULL, 0); + if (ret == 0) return NULL; std::unique_ptr tresult(new TCHAR[ret]); ret = GetEnvironmentVariable(tname.c_str(), tresult.get(), ret * sizeof(TCHAR)); - if (ret == 0) return absl::nullopt; - return TcharToChar(tresult.get()); + if (ret == 0) return NULL; + return gpr_strdup(grpc_core::TcharToChar(tresult.get()).c_str()); } -void SetEnv(const char* name, const char* value) { - BOOL res = SetEnvironmentVariable(CharToTchar(name).c_str(), - CharToTchar(value).c_str()); - if (!res) abort(); +void gpr_setenv(const char* name, const char* value) { + BOOL res = SetEnvironmentVariable(grpc_core::CharToTchar(name).c_str(), + grpc_core::CharToTchar(value).c_str()); + GPR_ASSERT(res); } -void UnsetEnv(const char* name) { - BOOL res = SetEnvironmentVariable(CharToTchar(name).c_str(), NULL); - if (!res) abort(); +void gpr_unsetenv(const char* name) { + BOOL res = SetEnvironmentVariable(grpc_core::CharToTchar(name).c_str(), NULL); + GPR_ASSERT(res); } -} // namespace grpc_core - #endif /* GPR_WINDOWS_ENV */ diff --git a/src/core/lib/gprpp/global_config_env.cc b/src/core/lib/gprpp/global_config_env.cc index 6e3caed2fb0..54dc9e700e3 100644 --- a/src/core/lib/gprpp/global_config_env.cc +++ b/src/core/lib/gprpp/global_config_env.cc @@ -28,13 +28,12 @@ #include #include "absl/strings/str_format.h" -#include "absl/types/optional.h" #include #include +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/string.h" -#include "src/core/lib/gprpp/env.h" namespace grpc_core { @@ -61,14 +60,14 @@ void SetGlobalConfigEnvErrorFunction(GlobalConfigEnvErrorFunctionType func) { } UniquePtr GlobalConfigEnv::GetValue() { - auto env = GetEnv(GetName()); - return UniquePtr(env.has_value() ? gpr_strdup(env.value().c_str()) - : nullptr); + return UniquePtr(gpr_getenv(GetName())); } -void GlobalConfigEnv::SetValue(const char* value) { SetEnv(GetName(), value); } +void GlobalConfigEnv::SetValue(const char* value) { + gpr_setenv(GetName(), value); +} -void GlobalConfigEnv::Unset() { UnsetEnv(GetName()); } +void GlobalConfigEnv::Unset() { gpr_unsetenv(GetName()); } char* GlobalConfigEnv::GetName() { // This makes sure that name_ is in a canonical form having uppercase diff --git a/src/core/lib/security/credentials/external/aws_external_account_credentials.cc b/src/core/lib/security/credentials/external/aws_external_account_credentials.cc index 79c651adb99..04c6a48467f 100644 --- a/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +++ b/src/core/lib/security/credentials/external/aws_external_account_credentials.cc @@ -29,7 +29,6 @@ #include "absl/strings/str_format.h" #include "absl/strings/str_replace.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include #include @@ -37,7 +36,8 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" +#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/http/httpcli_ssl_credentials.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/json/json.h" @@ -237,12 +237,12 @@ void AwsExternalAccountCredentials::AddMetadataRequestHeaders( } void AwsExternalAccountCredentials::RetrieveRegion() { - auto region_from_env = GetEnv(kRegionEnvVar); - if (!region_from_env.has_value()) { - region_from_env = GetEnv(kDefaultRegionEnvVar); + UniquePtr region_from_env(gpr_getenv(kRegionEnvVar)); + if (region_from_env == nullptr) { + region_from_env = UniquePtr(gpr_getenv(kDefaultRegionEnvVar)); } - if (region_from_env.has_value()) { - region_ = std::move(*region_from_env); + if (region_from_env != nullptr) { + region_ = std::string(region_from_env.get()); if (url_.empty()) { RetrieveSigningKeys(); } else { @@ -350,14 +350,15 @@ void AwsExternalAccountCredentials::OnRetrieveRoleNameInternal( } void AwsExternalAccountCredentials::RetrieveSigningKeys() { - auto access_key_id_from_env = GetEnv(kAccessKeyIdEnvVar); - auto secret_access_key_from_env = GetEnv(kSecretAccessKeyEnvVar); - auto token_from_env = GetEnv(kSessionTokenEnvVar); - if (access_key_id_from_env.has_value() && - secret_access_key_from_env.has_value() && token_from_env.has_value()) { - access_key_id_ = std::move(*access_key_id_from_env); - secret_access_key_ = std::move(*secret_access_key_from_env); - token_ = std::move(*token_from_env); + UniquePtr access_key_id_from_env(gpr_getenv(kAccessKeyIdEnvVar)); + UniquePtr secret_access_key_from_env( + gpr_getenv(kSecretAccessKeyEnvVar)); + UniquePtr token_from_env(gpr_getenv(kSessionTokenEnvVar)); + if (access_key_id_from_env != nullptr && + secret_access_key_from_env != nullptr && token_from_env != nullptr) { + access_key_id_ = std::string(access_key_id_from_env.get()); + secret_access_key_ = std::string(secret_access_key_from_env.get()); + token_ = std::string(token_from_env.get()); BuildSubjectToken(); return; } diff --git a/src/core/lib/security/credentials/google_default/credentials_generic.cc b/src/core/lib/security/credentials/google_default/credentials_generic.cc index b8e7c71daed..0817fdbf330 100644 --- a/src/core/lib/security/credentials/google_default/credentials_generic.cc +++ b/src/core/lib/security/credentials/google_default/credentials_generic.cc @@ -21,20 +21,23 @@ #include #include "absl/strings/str_cat.h" -#include "absl/types/optional.h" +#include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/credentials/google_default/google_default_credentials.h" std::string grpc_get_well_known_google_credentials_file_path_impl(void) { - auto base = grpc_core::GetEnv(GRPC_GOOGLE_CREDENTIALS_PATH_ENV_VAR); - if (!base.has_value()) { + char* base = gpr_getenv(GRPC_GOOGLE_CREDENTIALS_PATH_ENV_VAR); + if (base == nullptr) { gpr_log(GPR_ERROR, "Could not get " GRPC_GOOGLE_CREDENTIALS_PATH_ENV_VAR " environment variable."); return ""; } - return absl::StrCat(*base, "/", GRPC_GOOGLE_CREDENTIALS_PATH_SUFFIX); + std::string result = + absl::StrCat(base, "/", GRPC_GOOGLE_CREDENTIALS_PATH_SUFFIX); + gpr_free(base); + return result; } diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index 058ccd16977..d5a7fd282a9 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -44,7 +44,7 @@ #include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" @@ -399,9 +399,10 @@ static grpc_core::RefCountedPtr make_default_call_creds( grpc_error_handle err; /* First, try the environment variable. */ - auto path_from_env = grpc_core::GetEnv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR); - if (path_from_env.has_value()) { - err = create_default_creds_from_path(*path_from_env, &call_creds); + char* path_from_env = gpr_getenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR); + if (path_from_env != nullptr) { + err = create_default_creds_from_path(path_from_env, &call_creds); + gpr_free(path_from_env); if (GRPC_ERROR_IS_NONE(err)) return call_creds; *error = grpc_error_add_child(*error, err); } diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index c55955bd963..daf3eaae08e 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -27,11 +27,11 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_join.h" -#include "absl/types/optional.h" #include #include #include +#include #include #include #include @@ -42,7 +42,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/executor.h" @@ -224,22 +224,23 @@ grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options) { } ClearStsCredentialsOptions(options); grpc_slice json_string = grpc_empty_slice(); - auto sts_creds_path = grpc_core::GetEnv("STS_CREDENTIALS"); + char* sts_creds_path = gpr_getenv("STS_CREDENTIALS"); grpc_error_handle error = GRPC_ERROR_NONE; grpc::Status status; // NOLINTNEXTLINE(clang-diagnostic-unused-lambda-capture) - auto cleanup = [&json_string, &error, &status]() { + auto cleanup = [&json_string, &sts_creds_path, &error, &status]() { grpc_slice_unref_internal(json_string); + gpr_free(sts_creds_path); GRPC_ERROR_UNREF(error); return status; }; - if (!sts_creds_path.has_value()) { + if (sts_creds_path == nullptr) { status = grpc::Status(grpc::StatusCode::NOT_FOUND, "STS_CREDENTIALS environment variable not set."); return cleanup(); } - error = grpc_load_file(sts_creds_path->c_str(), 1, &json_string); + error = grpc_load_file(sts_creds_path, 1, &json_string); if (!GRPC_ERROR_IS_NONE(error)) { status = grpc::Status(grpc::StatusCode::NOT_FOUND, grpc_error_std_string(error)); diff --git a/src/cpp/ext/gcp/BUILD b/src/cpp/ext/gcp/BUILD index b686607ce0e..edb4f385dc5 100644 --- a/src/cpp/ext/gcp/BUILD +++ b/src/cpp/ext/gcp/BUILD @@ -67,12 +67,10 @@ grpc_cc_library( "absl/status", "absl/status:statusor", "absl/strings", - "absl/types:optional", ], language = "c++", visibility = ["//test:__subpackages__"], deps = [ - "//:env", "//:gpr", "//:grpc_base", "//:grpc_public_hdrs", diff --git a/src/cpp/ext/gcp/observability_config.cc b/src/cpp/ext/gcp/observability_config.cc index a2747e80ced..026b2d9b054 100644 --- a/src/cpp/ext/gcp/observability_config.cc +++ b/src/cpp/ext/gcp/observability_config.cc @@ -18,16 +18,16 @@ #include "src/cpp/ext/gcp/observability_config.h" -#include +#include #include "absl/status/status.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" +#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/load_file.h" #include "src/core/lib/json/json.h" @@ -46,23 +46,24 @@ namespace { absl::StatusOr GetGcpObservabilityConfigContents() { // First, try GRPC_OBSERVABILITY_CONFIG_FILE std::string contents_str; - auto path = grpc_core::GetEnv("GRPC_OBSERVABILITY_CONFIG_FILE"); - if (path.has_value()) { + grpc_core::UniquePtr path(gpr_getenv("GRPC_OBSERVABILITY_CONFIG_FILE")); + if (path != nullptr) { grpc_slice contents; grpc_error_handle error = - grpc_load_file(path->c_str(), /*add_null_terminator=*/true, &contents); + grpc_load_file(path.get(), /*add_null_terminator=*/true, &contents); if (!GRPC_ERROR_IS_NONE(error)) { return grpc_error_to_absl_status(grpc_error_set_int( error, GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_FAILED_PRECONDITION)); } std::string contents_str(grpc_core::StringViewFromSlice(contents)); grpc_slice_unref_internal(contents); - return std::move(contents_str); + return contents_str; } // Next, try GRPC_OBSERVABILITY_CONFIG env var. - auto env_config = grpc_core::GetEnv("GRPC_OBSERVABILITY_CONFIG"); - if (env_config.has_value()) { - return std::move(*env_config); + grpc_core::UniquePtr env_config( + gpr_getenv("GRPC_OBSERVABILITY_CONFIG")); + if (env_config != nullptr) { + return env_config.get(); } // No observability config found. return absl::FailedPreconditionError( diff --git a/src/objective-c/tests/CronetTests/CronetUnitTests.mm b/src/objective-c/tests/CronetTests/CronetUnitTests.mm index 6bbb75ac550..67e0a64a5f0 100644 --- a/src/objective-c/tests/CronetTests/CronetUnitTests.mm +++ b/src/objective-c/tests/CronetTests/CronetUnitTests.mm @@ -32,9 +32,9 @@ #import #import "src/core/lib/channel/channel_args.h" +#import "src/core/lib/gpr/env.h" #import "src/core/lib/gpr/string.h" #import "src/core/lib/gpr/tmpfile.h" -#import "src/core/lib/gprpp/env.h" #import "src/core/lib/gprpp/host_port.h" #import "test/core/end2end/data/ssl_test_data.h" #import "test/core/util/test_config.h" diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 82c8dc85726..a41ede220f2 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -471,6 +471,9 @@ CORE_SOURCE_FILES = [ 'src/core/lib/gpr/cpu_linux.cc', 'src/core/lib/gpr/cpu_posix.cc', 'src/core/lib/gpr/cpu_windows.cc', + 'src/core/lib/gpr/env_linux.cc', + 'src/core/lib/gpr/env_posix.cc', + 'src/core/lib/gpr/env_windows.cc', 'src/core/lib/gpr/log.cc', 'src/core/lib/gpr/log_android.cc', 'src/core/lib/gpr/log_linux.cc', @@ -493,9 +496,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/gpr/tmpfile_posix.cc', 'src/core/lib/gpr/tmpfile_windows.cc', 'src/core/lib/gpr/wrap_memcpy.cc', - 'src/core/lib/gprpp/env_linux.cc', - 'src/core/lib/gprpp/env_posix.cc', - 'src/core/lib/gprpp/env_windows.cc', 'src/core/lib/gprpp/examine_stack.cc', 'src/core/lib/gprpp/fork.cc', 'src/core/lib/gprpp/global_config_env.cc', diff --git a/test/core/client_channel/http_proxy_mapper_test.cc b/test/core/client_channel/http_proxy_mapper_test.cc index b756e6d26ae..71957de28c4 100644 --- a/test/core/client_channel/http_proxy_mapper_test.cc +++ b/test/core/client_channel/http_proxy_mapper_test.cc @@ -20,7 +20,7 @@ #include "src/core/ext/filters/client_channel/http_proxy.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/transport/http_connect_handshaker.h" #include "test/core/util/test_config.h" @@ -30,10 +30,10 @@ namespace { class ScopedSetEnv { public: - explicit ScopedSetEnv(const char* value) { SetEnv("no_proxy", value); } + explicit ScopedSetEnv(const char* value) { gpr_setenv("no_proxy", value); } ScopedSetEnv(const ScopedSetEnv&) = delete; ScopedSetEnv& operator=(const ScopedSetEnv&) = delete; - ~ScopedSetEnv() { UnsetEnv("no_proxy"); } + ~ScopedSetEnv() { gpr_unsetenv("no_proxy"); } }; // Test that an empty no_proxy works as expected, i.e., proxy is used. diff --git a/test/core/client_channel/resolvers/google_c2p_resolver_test.cc b/test/core/client_channel/resolvers/google_c2p_resolver_test.cc index 9e96b62e777..30c52d490bf 100644 --- a/test/core/client_channel/resolvers/google_c2p_resolver_test.cc +++ b/test/core/client_channel/resolvers/google_c2p_resolver_test.cc @@ -37,7 +37,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/thd.h" #include "test/core/util/fake_udp_and_tcp_server.h" #include "test/core/util/port.h" @@ -105,7 +105,7 @@ TEST(DestroyGoogleC2pChannelWithActiveConnectStressTest, int main(int argc, char** argv) { grpc::testing::TestEnvironment env(&argc, argv); - grpc_core::SetEnv("GRPC_EXPERIMENTAL_GOOGLE_C2P_RESOLVER", "true"); + gpr_setenv("GRPC_EXPERIMENTAL_GOOGLE_C2P_RESOLVER", "true"); ::testing::InitGoogleTest(&argc, argv); grpc_init(); auto result = RUN_ALL_TESTS(); diff --git a/test/core/client_channel/rls_lb_config_parser_test.cc b/test/core/client_channel/rls_lb_config_parser_test.cc index ed29b5be193..fe1e5aac561 100644 --- a/test/core/client_channel/rls_lb_config_parser_test.cc +++ b/test/core/client_channel/rls_lb_config_parser_test.cc @@ -19,7 +19,7 @@ #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/service_config/service_config_impl.h" #include "test/core/util/test_config.h" diff --git a/test/core/end2end/fixtures/h2_http_proxy.cc b/test/core/end2end/fixtures/h2_http_proxy.cc index c647aa4f40b..155070cdc86 100644 --- a/test/core/end2end/fixtures/h2_http_proxy.cc +++ b/test/core/end2end/fixtures/h2_http_proxy.cc @@ -27,7 +27,7 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/host_port.h" #include "test/core/end2end/end2end_tests.h" #include "test/core/end2end/fixtures/http_proxy_fixture.h" @@ -75,7 +75,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, absl::StrFormat("http://%s@%s", proxy_auth_str, grpc_end2end_http_proxy_get_proxy_name(ffd->proxy)); } - grpc_core::SetEnv("http_proxy", proxy_uri.c_str()); + gpr_setenv("http_proxy", proxy_uri.c_str()); grpc_channel_credentials* creds = grpc_insecure_credentials_create(); f->client = grpc_channel_create(ffd->server_addr.c_str(), creds, client_args); grpc_channel_credentials_release(creds); diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index 468a2916275..1d166ee14be 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -53,8 +53,8 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channelz.h" #include "src/core/lib/event_engine/default_event_engine.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/debug_location.h" -#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/endpoint.h" @@ -814,9 +814,9 @@ static grpc_channel_credentials* ReadChannelCreds( DEFINE_PROTO_FUZZER(const api_fuzzer::Msg& msg) { grpc_event_engine::experimental::ResetDefaultEventEngine(); grpc_test_only_set_slice_hash_seed(0); - if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) { - gpr_set_log_function(dont_log); - } + char* grpc_trace_fuzzer = gpr_getenv("GRPC_TRACE_FUZZER"); + if (squelch && grpc_trace_fuzzer == nullptr) gpr_set_log_function(dont_log); + gpr_free(grpc_trace_fuzzer); grpc_set_tcp_client_impl(&fuzz_tcp_client_vtable); grpc_event_engine::experimental::SetDefaultEventEngineFactory( [actions = msg.event_engine_actions()]() { diff --git a/test/core/filters/filter_fuzzer.cc b/test/core/filters/filter_fuzzer.cc index f2f0a830ec0..9d55b399f45 100644 --- a/test/core/filters/filter_fuzzer.cc +++ b/test/core/filters/filter_fuzzer.cc @@ -22,7 +22,7 @@ #include "src/core/ext/filters/http/server/http_server_filter.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_stack_builder_impl.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/timer_manager.h" #include "src/core/lib/resource_quota/resource_quota.h" @@ -585,9 +585,9 @@ DEFINE_PROTO_FUZZER(const filter_fuzzer::Msg& msg) { } grpc_test_only_set_slice_hash_seed(0); - if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) { - gpr_set_log_function(dont_log); - } + char* grpc_trace_fuzzer = gpr_getenv("GRPC_TRACE_FUZZER"); + if (squelch && grpc_trace_fuzzer == nullptr) gpr_set_log_function(dont_log); + gpr_free(grpc_trace_fuzzer); g_now = {1, 0, GPR_CLOCK_MONOTONIC}; grpc_core::TestOnlySetProcessEpoch(g_now); gpr_now_impl = now_impl; diff --git a/test/core/gpr/env_test.cc b/test/core/gpr/env_test.cc index fe67d92e239..49e54264bf4 100644 --- a/test/core/gpr/env_test.cc +++ b/test/core/gpr/env_test.cc @@ -16,7 +16,7 @@ * */ -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include #include @@ -34,24 +34,28 @@ TEST(EnvTest, SetenvGetenv) { const char* name = "FOO"; const char* value = "BAR"; + char* retrieved_value; LOG_TEST_NAME("test_setenv_getenv"); - grpc_core::SetEnv(name, value); - auto retrieved_value = grpc_core::GetEnv(name); - ASSERT_EQ(value, retrieved_value); + gpr_setenv(name, value); + retrieved_value = gpr_getenv(name); + ASSERT_NE(retrieved_value, nullptr); + ASSERT_STREQ(value, retrieved_value); + gpr_free(retrieved_value); } TEST(EnvTest, Unsetenv) { const char* name = "FOO"; const char* value = "BAR"; + char* retrieved_value; LOG_TEST_NAME("test_unsetenv"); - grpc_core::SetEnv(name, value); - grpc_core::UnsetEnv(name); - auto retrieved_value = grpc_core::GetEnv(name); - ASSERT_FALSE(retrieved_value.has_value()); + gpr_setenv(name, value); + gpr_unsetenv(name); + retrieved_value = gpr_getenv(name); + ASSERT_EQ(retrieved_value, nullptr); } int main(int argc, char** argv) { diff --git a/test/core/gprpp/global_config_env_test.cc b/test/core/gprpp/global_config_env_test.cc index 722651ba91a..519c242e445 100644 --- a/test/core/gprpp/global_config_env_test.cc +++ b/test/core/gprpp/global_config_env_test.cc @@ -26,7 +26,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/memory.h" namespace { @@ -59,23 +59,23 @@ GPR_GLOBAL_CONFIG_DEFINE_STRING(string_var, "Apple", ""); TEST_F(GlobalConfigEnvTest, BoolWithEnvTest) { const char* bool_var_name = "BOOL_VAR"; - grpc_core::UnsetEnv(bool_var_name); + gpr_unsetenv(bool_var_name); EXPECT_TRUE(GPR_GLOBAL_CONFIG_GET(bool_var)); - grpc_core::SetEnv(bool_var_name, "true"); + gpr_setenv(bool_var_name, "true"); EXPECT_TRUE(GPR_GLOBAL_CONFIG_GET(bool_var)); - grpc_core::SetEnv(bool_var_name, "false"); + gpr_setenv(bool_var_name, "false"); EXPECT_FALSE(GPR_GLOBAL_CONFIG_GET(bool_var)); EXPECT_FALSE(IsConfigErrorCalled()); - grpc_core::SetEnv(bool_var_name, ""); + gpr_setenv(bool_var_name, ""); GPR_GLOBAL_CONFIG_GET(bool_var); EXPECT_TRUE(IsConfigErrorCalled()); ClearConfigErrorCalled(); - grpc_core::SetEnv(bool_var_name, "!"); + gpr_setenv(bool_var_name, "!"); GPR_GLOBAL_CONFIG_GET(bool_var); EXPECT_TRUE(IsConfigErrorCalled()); ClearConfigErrorCalled(); @@ -84,21 +84,21 @@ TEST_F(GlobalConfigEnvTest, BoolWithEnvTest) { TEST_F(GlobalConfigEnvTest, Int32WithEnvTest) { const char* int32_var_name = "INT32_VAR"; - grpc_core::UnsetEnv(int32_var_name); + gpr_unsetenv(int32_var_name); EXPECT_EQ(1234, GPR_GLOBAL_CONFIG_GET(int32_var)); - grpc_core::SetEnv(int32_var_name, "0"); + gpr_setenv(int32_var_name, "0"); EXPECT_EQ(0, GPR_GLOBAL_CONFIG_GET(int32_var)); - grpc_core::SetEnv(int32_var_name, "-123456789"); + gpr_setenv(int32_var_name, "-123456789"); EXPECT_EQ(-123456789, GPR_GLOBAL_CONFIG_GET(int32_var)); - grpc_core::SetEnv(int32_var_name, "123456789"); + gpr_setenv(int32_var_name, "123456789"); EXPECT_EQ(123456789, GPR_GLOBAL_CONFIG_GET(int32_var)); EXPECT_FALSE(IsConfigErrorCalled()); - grpc_core::SetEnv(int32_var_name, "-1AB"); + gpr_setenv(int32_var_name, "-1AB"); GPR_GLOBAL_CONFIG_GET(int32_var); EXPECT_TRUE(IsConfigErrorCalled()); ClearConfigErrorCalled(); @@ -108,15 +108,15 @@ TEST_F(GlobalConfigEnvTest, StringWithEnvTest) { const char* string_var_name = "STRING_VAR"; grpc_core::UniquePtr value; - grpc_core::UnsetEnv(string_var_name); + gpr_unsetenv(string_var_name); value = GPR_GLOBAL_CONFIG_GET(string_var); EXPECT_EQ(0, strcmp(value.get(), "Apple")); - grpc_core::SetEnv(string_var_name, "Banana"); + gpr_setenv(string_var_name, "Banana"); value = GPR_GLOBAL_CONFIG_GET(string_var); EXPECT_EQ(0, strcmp(value.get(), "Banana")); - grpc_core::SetEnv(string_var_name, ""); + gpr_setenv(string_var_name, ""); value = GPR_GLOBAL_CONFIG_GET(string_var); EXPECT_EQ(0, strcmp(value.get(), "")); } diff --git a/test/core/gprpp/global_config_test.cc b/test/core/gprpp/global_config_test.cc index 419a629635f..31ab94bfb78 100644 --- a/test/core/gprpp/global_config_test.cc +++ b/test/core/gprpp/global_config_test.cc @@ -26,7 +26,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/memory.h" GPR_GLOBAL_CONFIG_DECLARE_BOOL(bool_var); diff --git a/test/core/http/httpscli_test.cc b/test/core/http/httpscli_test.cc index 52223fb550c..2a4582821af 100644 --- a/test/core/http/httpscli_test.cc +++ b/test/core/http/httpscli_test.cc @@ -30,7 +30,7 @@ #include #include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/time_util.h" #include "src/core/lib/http/httpcli.h" diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc index c00fe53488e..0668c662308 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -35,9 +35,9 @@ #include #include "src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/useful.h" -#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/thd.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/executor.h" diff --git a/test/core/security/alts_credentials_fuzzer.cc b/test/core/security/alts_credentials_fuzzer.cc index 3420432ae6d..1f2aa6059ac 100644 --- a/test/core/security/alts_credentials_fuzzer.cc +++ b/test/core/security/alts_credentials_fuzzer.cc @@ -24,7 +24,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/security/credentials/alts/alts_credentials.h" #include "src/core/lib/security/credentials/alts/check_gcp_environment.h" #include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" @@ -60,9 +60,11 @@ static void read_target_service_accounts( } extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) { + char* grpc_trace_fuzzer = gpr_getenv("GRPC_TRACE_FUZZER"); + if (squelch && grpc_trace_fuzzer == nullptr) { gpr_set_log_function(dont_log); } + gpr_free(grpc_trace_fuzzer); input_stream inp = {data, data + size}; grpc_init(); bool is_on_gcp = grpc_alts_is_running_on_gcp(); diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc index 3170a80fd21..243486e256d 100644 --- a/test/core/security/credentials_test.cc +++ b/test/core/security/credentials_test.cc @@ -41,9 +41,9 @@ #include #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/tmpfile.h" -#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/unique_type_name.h" @@ -1512,7 +1512,7 @@ void set_google_default_creds_env_var_with_file_contents( GPR_ASSERT(creds_file != nullptr); GPR_ASSERT(fwrite(contents, 1, contents_len, creds_file) == contents_len); fclose(creds_file); - SetEnv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, creds_file_name); + gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, creds_file_name); gpr_free(creds_file_name); } @@ -1551,7 +1551,7 @@ TEST(CredentialsTest, TestGoogleDefaultCredsAuthKey) { 0); GPR_ASSERT(g_test_gce_tenancy_checker_called == false); creds->Unref(); - SetEnv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ + gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ grpc_override_well_known_credentials_path_getter(nullptr); } @@ -1575,7 +1575,7 @@ TEST(CredentialsTest, TestGoogleDefaultCredsRefreshToken) { GPR_ASSERT(strcmp(refresh->refresh_token().client_id, "32555999999.apps.googleusercontent.com") == 0); creds->Unref(); - SetEnv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ + gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ grpc_override_well_known_credentials_path_getter(nullptr); } @@ -1598,7 +1598,7 @@ TEST(CredentialsTest, TestGoogleDefaultCredsExternalAccountCredentials) { reinterpret_cast(creds->call_creds()); GPR_ASSERT(external != nullptr); creds->Unref(); - SetEnv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ + gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ grpc_override_well_known_credentials_path_getter(nullptr); } @@ -1622,7 +1622,7 @@ TEST(CredentialsTest, reinterpret_cast(creds->call_creds()); GPR_ASSERT(external != nullptr); creds->Unref(); - SetEnv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ + gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ grpc_override_well_known_credentials_path_getter(nullptr); } @@ -1646,7 +1646,7 @@ TEST(CredentialsTest, reinterpret_cast(creds->call_creds()); GPR_ASSERT(external != nullptr); creds->Unref(); - SetEnv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ + gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ grpc_override_well_known_credentials_path_getter(nullptr); } @@ -1673,7 +1673,7 @@ TEST(CredentialsTest, TestGoogleDefaultCredsGce) { GRPC_ERROR_NONE, "authorization: Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"); grpc_flush_cached_google_default_credentials(); - SetEnv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ + gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ grpc_override_well_known_credentials_path_getter( null_well_known_creds_path_getter); set_gce_tenancy_checker_for_testing(test_gce_tenancy_checker); @@ -1709,7 +1709,7 @@ TEST(CredentialsTest, TestGoogleDefaultCredsNonGce) { GRPC_ERROR_NONE, "authorization: Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"); grpc_flush_cached_google_default_credentials(); - SetEnv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ + gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ grpc_override_well_known_credentials_path_getter( null_well_known_creds_path_getter); set_gce_tenancy_checker_for_testing(test_gce_tenancy_checker); @@ -1752,7 +1752,7 @@ int default_creds_gce_detection_httpcli_get_failure_override( TEST(CredentialsTest, TestNoGoogleDefaultCreds) { grpc_flush_cached_google_default_credentials(); - SetEnv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ + gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ grpc_override_well_known_credentials_path_getter( null_well_known_creds_path_getter); set_gce_tenancy_checker_for_testing(test_gce_tenancy_checker); @@ -1987,27 +1987,32 @@ TEST(CredentialsTest, TestMetadataPluginFailure) { } TEST(CredentialsTest, TestGetWellKnownGoogleCredentialsFilePath) { - auto home = GetEnv("HOME"); + char* home = gpr_getenv("HOME"); bool restore_home_env = false; #if defined(GRPC_BAZEL_BUILD) && \ (defined(GPR_POSIX_ENV) || defined(GPR_LINUX_ENV)) // when running under bazel locally, the HOME variable is not set // so we set it to some fake value restore_home_env = true; - SetEnv("HOME", "/fake/home/for/bazel"); + gpr_setenv("HOME", "/fake/home/for/bazel"); #endif /* defined(GRPC_BAZEL_BUILD) && (defined(GPR_POSIX_ENV) || \ defined(GPR_LINUX_ENV)) */ std::string path = grpc_get_well_known_google_credentials_file_path(); GPR_ASSERT(!path.empty()); #if defined(GPR_POSIX_ENV) || defined(GPR_LINUX_ENV) restore_home_env = true; - UnsetEnv("HOME"); + gpr_unsetenv("HOME"); path = grpc_get_well_known_google_credentials_file_path(); GPR_ASSERT(path.empty()); #endif /* GPR_POSIX_ENV || GPR_LINUX_ENV */ if (restore_home_env) { - SetOrUnsetEnv("HOME", home); + if (home) { + gpr_setenv("HOME", home); + } else { + gpr_unsetenv("HOME"); + } } + gpr_free(home); } TEST(CredentialsTest, TestChannelCredsDuplicateWithoutCallCreds) { @@ -2985,7 +2990,7 @@ TEST(CredentialsTest, TestAwsImdsv2ExternalAccountCredsSuccess) { TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionEnvKeysUrl) { ExecCtx exec_ctx; - SetEnv("AWS_REGION", "test_regionz"); + gpr_setenv("AWS_REGION", "test_regionz"); auto credential_source = Json::Parse(valid_aws_external_account_creds_options_credential_source); GPR_ASSERT(credential_source.ok()); @@ -3016,13 +3021,13 @@ TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionEnvKeysUrl) { kTestPath); ExecCtx::Get()->Flush(); HttpRequest::SetOverride(nullptr, nullptr, nullptr); - UnsetEnv("AWS_REGION"); + gpr_unsetenv("AWS_REGION"); } TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathDefaultRegionEnvKeysUrl) { ExecCtx exec_ctx; - SetEnv("AWS_DEFAULT_REGION", "test_regionz"); + gpr_setenv("AWS_DEFAULT_REGION", "test_regionz"); auto credential_source = Json::Parse(valid_aws_external_account_creds_options_credential_source); GPR_ASSERT(credential_source.ok()); @@ -3053,15 +3058,15 @@ TEST(CredentialsTest, kTestPath); ExecCtx::Get()->Flush(); HttpRequest::SetOverride(nullptr, nullptr, nullptr); - UnsetEnv("AWS_DEFAULT_REGION"); + gpr_unsetenv("AWS_DEFAULT_REGION"); } TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathDuplicateRegionEnvKeysUrl) { ExecCtx exec_ctx; // Make sure that AWS_REGION gets used over AWS_DEFAULT_REGION - SetEnv("AWS_REGION", "test_regionz"); - SetEnv("AWS_DEFAULT_REGION", "ERROR_REGION"); + gpr_setenv("AWS_REGION", "test_regionz"); + gpr_setenv("AWS_DEFAULT_REGION", "ERROR_REGION"); auto credential_source = Json::Parse(valid_aws_external_account_creds_options_credential_source); GPR_ASSERT(credential_source.ok()); @@ -3092,15 +3097,15 @@ TEST(CredentialsTest, kTestPath); ExecCtx::Get()->Flush(); HttpRequest::SetOverride(nullptr, nullptr, nullptr); - UnsetEnv("AWS_REGION"); - UnsetEnv("AWS_DEFAULT_REGION"); + gpr_unsetenv("AWS_REGION"); + gpr_unsetenv("AWS_DEFAULT_REGION"); } TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionUrlKeysEnv) { ExecCtx exec_ctx; - SetEnv("AWS_ACCESS_KEY_ID", "test_access_key_id"); - SetEnv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key"); - SetEnv("AWS_SESSION_TOKEN", "test_token"); + gpr_setenv("AWS_ACCESS_KEY_ID", "test_access_key_id"); + gpr_setenv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key"); + gpr_setenv("AWS_SESSION_TOKEN", "test_token"); auto credential_source = Json::Parse(valid_aws_external_account_creds_options_credential_source); GPR_ASSERT(credential_source.ok()); @@ -3131,17 +3136,17 @@ TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionUrlKeysEnv) { kTestPath); ExecCtx::Get()->Flush(); HttpRequest::SetOverride(nullptr, nullptr, nullptr); - UnsetEnv("AWS_ACCESS_KEY_ID"); - UnsetEnv("AWS_SECRET_ACCESS_KEY"); - UnsetEnv("AWS_SESSION_TOKEN"); + gpr_unsetenv("AWS_ACCESS_KEY_ID"); + gpr_unsetenv("AWS_SECRET_ACCESS_KEY"); + gpr_unsetenv("AWS_SESSION_TOKEN"); } TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionEnvKeysEnv) { ExecCtx exec_ctx; - SetEnv("AWS_REGION", "test_regionz"); - SetEnv("AWS_ACCESS_KEY_ID", "test_access_key_id"); - SetEnv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key"); - SetEnv("AWS_SESSION_TOKEN", "test_token"); + gpr_setenv("AWS_REGION", "test_regionz"); + gpr_setenv("AWS_ACCESS_KEY_ID", "test_access_key_id"); + gpr_setenv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key"); + gpr_setenv("AWS_SESSION_TOKEN", "test_token"); auto credential_source = Json::Parse(valid_aws_external_account_creds_options_credential_source); GPR_ASSERT(credential_source.ok()); @@ -3172,10 +3177,10 @@ TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionEnvKeysEnv) { kTestPath); ExecCtx::Get()->Flush(); HttpRequest::SetOverride(nullptr, nullptr, nullptr); - UnsetEnv("AWS_REGION"); - UnsetEnv("AWS_ACCESS_KEY_ID"); - UnsetEnv("AWS_SECRET_ACCESS_KEY"); - UnsetEnv("AWS_SESSION_TOKEN"); + gpr_unsetenv("AWS_REGION"); + gpr_unsetenv("AWS_ACCESS_KEY_ID"); + gpr_unsetenv("AWS_SECRET_ACCESS_KEY"); + gpr_unsetenv("AWS_SESSION_TOKEN"); } TEST(CredentialsTest, @@ -3183,10 +3188,10 @@ TEST(CredentialsTest, std::map emd = { {"authorization", "Bearer token_exchange_access_token"}}; ExecCtx exec_ctx; - SetEnv("AWS_DEFAULT_REGION", "test_regionz"); - SetEnv("AWS_ACCESS_KEY_ID", "test_access_key_id"); - SetEnv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key"); - SetEnv("AWS_SESSION_TOKEN", "test_token"); + gpr_setenv("AWS_DEFAULT_REGION", "test_regionz"); + gpr_setenv("AWS_ACCESS_KEY_ID", "test_access_key_id"); + gpr_setenv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key"); + gpr_setenv("AWS_SESSION_TOKEN", "test_token"); auto credential_source = Json::Parse(valid_aws_external_account_creds_options_credential_source); GPR_ASSERT(credential_source.ok()); @@ -3217,21 +3222,21 @@ TEST(CredentialsTest, kTestPath); ExecCtx::Get()->Flush(); HttpRequest::SetOverride(nullptr, nullptr, nullptr); - UnsetEnv("AWS_DEFAULT_REGION"); - UnsetEnv("AWS_ACCESS_KEY_ID"); - UnsetEnv("AWS_SECRET_ACCESS_KEY"); - UnsetEnv("AWS_SESSION_TOKEN"); + gpr_unsetenv("AWS_DEFAULT_REGION"); + gpr_unsetenv("AWS_ACCESS_KEY_ID"); + gpr_unsetenv("AWS_SECRET_ACCESS_KEY"); + gpr_unsetenv("AWS_SESSION_TOKEN"); } TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathDuplicateRegionEnvKeysEnv) { ExecCtx exec_ctx; // Make sure that AWS_REGION gets used over AWS_DEFAULT_REGION - SetEnv("AWS_REGION", "test_regionz"); - SetEnv("AWS_DEFAULT_REGION", "ERROR_REGION"); - SetEnv("AWS_ACCESS_KEY_ID", "test_access_key_id"); - SetEnv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key"); - SetEnv("AWS_SESSION_TOKEN", "test_token"); + gpr_setenv("AWS_REGION", "test_regionz"); + gpr_setenv("AWS_DEFAULT_REGION", "ERROR_REGION"); + gpr_setenv("AWS_ACCESS_KEY_ID", "test_access_key_id"); + gpr_setenv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key"); + gpr_setenv("AWS_SESSION_TOKEN", "test_token"); auto credential_source = Json::Parse(valid_aws_external_account_creds_options_credential_source); GPR_ASSERT(credential_source.ok()); @@ -3262,11 +3267,11 @@ TEST(CredentialsTest, kTestPath); ExecCtx::Get()->Flush(); HttpRequest::SetOverride(nullptr, nullptr, nullptr); - UnsetEnv("AWS_REGION"); - UnsetEnv("AWS_DEFAULT_REGION"); - UnsetEnv("AWS_ACCESS_KEY_ID"); - UnsetEnv("AWS_SECRET_ACCESS_KEY"); - UnsetEnv("AWS_SESSION_TOKEN"); + gpr_unsetenv("AWS_REGION"); + gpr_unsetenv("AWS_DEFAULT_REGION"); + gpr_unsetenv("AWS_ACCESS_KEY_ID"); + gpr_unsetenv("AWS_SECRET_ACCESS_KEY"); + gpr_unsetenv("AWS_SESSION_TOKEN"); } TEST(CredentialsTest, diff --git a/test/core/security/system_roots_test.cc b/test/core/security/system_roots_test.cc index ef0a96dc819..e34804783f5 100644 --- a/test/core/security/system_roots_test.cc +++ b/test/core/security/system_roots_test.cc @@ -31,8 +31,8 @@ #include #include +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/tmpfile.h" -#include "src/core/lib/gprpp/env.h" #include "src/core/lib/iomgr/load_file.h" #include "src/core/lib/security/context/security_context.h" #include "src/core/lib/security/security_connector/load_system_roots.h" diff --git a/test/core/util/BUILD b/test/core/util/BUILD index 2be51a0f5eb..6b3d3be65f6 100644 --- a/test/core/util/BUILD +++ b/test/core/util/BUILD @@ -126,7 +126,6 @@ grpc_cc_library( "stack_tracer", "//:channel_args_preconditioning", "//:config", - "//:env", "//:gpr", "//:gpr_atm", "//:grpc", @@ -166,7 +165,6 @@ grpc_cc_library( "stack_tracer", "//:channel_args_preconditioning", "//:config", - "//:env", "//:gpr", "//:gpr_atm", "//:grpc_security_base", diff --git a/test/core/util/fuzzer_corpus_test.cc b/test/core/util/fuzzer_corpus_test.cc index 73ce3e3c532..11439f741cb 100644 --- a/test/core/util/fuzzer_corpus_test.cc +++ b/test/core/util/fuzzer_corpus_test.cc @@ -28,14 +28,13 @@ #include "absl/flags/flag.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include "gtest/gtest.h" #include #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/load_file.h" #include "test/core/util/test_config.h" @@ -84,13 +83,12 @@ class ExampleGenerator examples_.push_back(absl::GetFlag(FLAGS_file)); } if (!absl::GetFlag(FLAGS_directory).empty()) { - auto test_srcdir = grpc_core::GetEnv("TEST_SRCDIR"); - gpr_log(GPR_DEBUG, "test_srcdir=\"%s\"", - test_srcdir.has_value() ? test_srcdir->c_str() : "(null)"); + char* test_srcdir = gpr_getenv("TEST_SRCDIR"); + gpr_log(GPR_DEBUG, "test_srcdir=\"%s\"", test_srcdir); std::string directory = absl::GetFlag(FLAGS_directory); - if (test_srcdir.has_value()) { + if (test_srcdir != nullptr) { directory = - *test_srcdir + std::string("/com_github_grpc_grpc/") + directory; + test_srcdir + std::string("/com_github_grpc_grpc/") + directory; } gpr_log(GPR_DEBUG, "Using corpus directory: %s", directory.c_str()); DIR* dp; @@ -109,6 +107,7 @@ class ExampleGenerator perror("Couldn't open the directory"); abort(); } + gpr_free(test_srcdir); } } // Make sure we don't succeed without doing anything, which caused diff --git a/test/core/util/test_config.cc b/test/core/util/test_config.cc index 34788d95deb..be478152654 100644 --- a/test/core/util/test_config.cc +++ b/test/core/util/test_config.cc @@ -32,7 +32,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/surface/init.h" #include "test/core/event_engine/test_init.h" #include "test/core/util/build.h" @@ -108,7 +108,7 @@ void ParseTestArgs(int* argc, char** argv) { int i = 1; while (i < *argc) { if (absl::StartsWith(argv[i], poller_flag)) { - grpc_core::SetEnv("GRPC_POLL_STRATEGY", argv[i] + poller_flag.length()); + gpr_setenv("GRPC_POLL_STRATEGY", argv[i] + poller_flag.length()); // remove the spent argv RmArg(i, argc, argv); continue; @@ -126,7 +126,7 @@ void ParseTestArgs(int* argc, char** argv) { continue; } if (absl::StartsWith(argv[i], experiment_flag)) { - grpc_core::SetEnv("GRPC_EXPERIMENTS", argv[i] + experiment_flag.length()); + gpr_setenv("GRPC_EXPERIMENTS", argv[i] + experiment_flag.length()); // remove the spent argv RmArg(i, argc, argv); continue; diff --git a/test/core/xds/xds_bootstrap_test.cc b/test/core/xds/xds_bootstrap_test.cc index 9762fd857bc..402760bdf20 100644 --- a/test/core/xds/xds_bootstrap_test.cc +++ b/test/core/xds/xds_bootstrap_test.cc @@ -23,8 +23,8 @@ #include "src/core/ext/xds/xds_bootstrap_grpc.h" #include "src/core/ext/xds/xds_client_grpc.h" #include "src/core/lib/config/core_configuration.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/tmpfile.h" -#include "src/core/lib/gprpp/env.h" #include "src/core/lib/security/certificate_provider/certificate_provider_registry.h" #include "test/core/util/test_config.h" @@ -33,7 +33,7 @@ namespace testing { namespace { TEST(XdsBootstrapTest, Basic) { - SetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true"); + gpr_setenv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true"); const char* json_str = "{" " \"xds_servers\": [" @@ -169,7 +169,7 @@ TEST(XdsBootstrapTest, Basic) { ::testing::Property(&Json::string_value, "1"))))); EXPECT_EQ(bootstrap->server_listener_resource_name_template(), "example/resource"); - UnsetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); + gpr_unsetenv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); } TEST(XdsBootstrapTest, ValidWithoutNode) { @@ -226,7 +226,7 @@ TEST(XdsBootstrapTest, GoogleDefaultCreds) { ASSERT_EQ(fwrite(token_str, 1, sizeof(token_str), creds_file), sizeof(token_str)); fclose(creds_file); - SetEnv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, creds_file_name); + gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, creds_file_name); gpr_free(creds_file_name); // Now run test. const char* json_str = @@ -473,7 +473,7 @@ TEST(XdsBootstrapTest, CertificateProvidersUnrecognizedPluginName) { } TEST(XdsBootstrapTest, AuthorityXdsServerInvalidResourceTemplate) { - SetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true"); + gpr_setenv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true"); const char* json_str = "{" " \"xds_servers\": [" @@ -508,11 +508,11 @@ TEST(XdsBootstrapTest, AuthorityXdsServerInvalidResourceTemplate) { ".client_listener_resource_name_template error:" "field must begin with \"xdstp://xds.example.com/\"]") << bootstrap.status(); - UnsetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); + gpr_unsetenv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); } TEST(XdsBootstrapTest, AuthorityXdsServerMissingServerUri) { - SetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true"); + gpr_setenv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true"); const char* json_str = "{" " \"xds_servers\": [" @@ -539,7 +539,7 @@ TEST(XdsBootstrapTest, AuthorityXdsServerMissingServerUri) { "field:authorities[\"xds.example.com\"].xds_servers[0].server_uri " "error:field not present]") << bootstrap.status(); - UnsetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); + gpr_unsetenv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); } class FakeCertificateProviderFactory : public CertificateProviderFactory { @@ -681,7 +681,7 @@ TEST(XdsBootstrapTest, CertificateProvidersFakePluginEmptyConfig) { } TEST(XdsBootstrapTest, XdsServerToJsonAndParse) { - SetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true"); + gpr_setenv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true"); const char* json_str = " {" " \"server_uri\": \"fake:///lb\"," @@ -702,7 +702,7 @@ TEST(XdsBootstrapTest, XdsServerToJsonAndParse) { LoadFromJson(output); ASSERT_TRUE(output_xds_server.ok()) << output_xds_server.status(); EXPECT_EQ(*xds_server, *output_xds_server); - UnsetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); + gpr_unsetenv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); } } // namespace diff --git a/test/core/xds/xds_client_test.cc b/test/core/xds/xds_client_test.cc index 5b60b5a421f..13ab78a0e7d 100644 --- a/test/core/xds/xds_client_test.cc +++ b/test/core/xds/xds_client_test.cc @@ -30,7 +30,7 @@ #include "src/core/ext/xds/xds_bootstrap.h" #include "src/core/ext/xds/xds_resource_type_impl.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/json/json.h" #include "src/core/lib/json/json_object_loader.h" @@ -476,10 +476,10 @@ class XdsClientTest : public ::testing::Test { class ScopedExperimentalEnvVar { public: explicit ScopedExperimentalEnvVar(const char* env_var) : env_var_(env_var) { - SetEnv(env_var_, "true"); + gpr_setenv(env_var_, "true"); } - ~ScopedExperimentalEnvVar() { UnsetEnv(env_var_); } + ~ScopedExperimentalEnvVar() { gpr_unsetenv(env_var_); } private: const char* env_var_; diff --git a/test/cpp/client/credentials_test.cc b/test/cpp/client/credentials_test.cc index bbe793877ef..cc5ade2d1db 100644 --- a/test/cpp/client/credentials_test.cc +++ b/test/cpp/client/credentials_test.cc @@ -28,8 +28,8 @@ #include #include +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/tmpfile.h" -#include "src/core/lib/gprpp/env.h" #include "src/cpp/client/secure_credentials.h" #include "test/cpp/util/tls_test_utils.h" @@ -228,7 +228,7 @@ TEST(CredentialsTest, StsCredentialsOptionsJson) { TEST(CredentialsTest, StsCredentialsOptionsFromEnv) { // Unset env and check expected failure. - grpc_core::UnsetEnv("STS_CREDENTIALS"); + gpr_unsetenv("STS_CREDENTIALS"); grpc::experimental::StsCredentialsOptions options; auto status = grpc::experimental::StsCredentialsOptionsFromEnv(&options); EXPECT_EQ(grpc::StatusCode::NOT_FOUND, status.error_code()); @@ -247,7 +247,7 @@ TEST(CredentialsTest, StsCredentialsOptionsFromEnv) { ASSERT_EQ(sizeof(valid_json), fwrite(valid_json, 1, sizeof(valid_json), creds_file)); fclose(creds_file); - grpc_core::SetEnv("STS_CREDENTIALS", creds_file_name); + gpr_setenv("STS_CREDENTIALS", creds_file_name); gpr_free(creds_file_name); status = grpc::experimental::StsCredentialsOptionsFromEnv(&options); EXPECT_TRUE(status.ok()); @@ -262,7 +262,7 @@ TEST(CredentialsTest, StsCredentialsOptionsFromEnv) { EXPECT_EQ(options.actor_token_type, ""); // Cleanup. - grpc_core::UnsetEnv("STS_CREDENTIALS"); + gpr_unsetenv("STS_CREDENTIALS"); } TEST(CredentialsTest, TlsChannelCredentialsWithDefaultRootsAndDefaultVerifier) { diff --git a/test/cpp/end2end/cfstream_test.cc b/test/cpp/end2end/cfstream_test.cc index 94bfaa910b7..03a5180a98d 100644 --- a/test/cpp/end2end/cfstream_test.cc +++ b/test/cpp/end2end/cfstream_test.cc @@ -38,7 +38,7 @@ #include #include "src/core/lib/backoff/backoff.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/port.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" @@ -472,7 +472,7 @@ TEST_P(CFStreamTest, ConcurrentRpc) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); grpc::testing::TestEnvironment env(&argc, argv); - grpc_core::SetEnv("grpc_cfstream", "1"); + gpr_setenv("grpc_cfstream", "1"); const auto result = RUN_ALL_TESTS(); return result; } diff --git a/test/cpp/end2end/channelz_service_test.cc b/test/cpp/end2end/channelz_service_test.cc index 33029a5aa1b..61050b8d200 100644 --- a/test/cpp/end2end/channelz_service_test.cc +++ b/test/cpp/end2end/channelz_service_test.cc @@ -34,7 +34,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/load_file.h" #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h" #include "src/core/lib/security/security_connector/ssl_utils.h" @@ -186,7 +186,7 @@ class ChannelzServerTest : public ::testing::TestWithParam { static void SetUpTestCase() { #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif } void SetUp() override { diff --git a/test/cpp/end2end/client_callback_end2end_test.cc b/test/cpp/end2end/client_callback_end2end_test.cc index 0c1377c8e88..12a9d2fa1bc 100644 --- a/test/cpp/end2end/client_callback_end2end_test.cc +++ b/test/cpp/end2end/client_callback_end2end_test.cc @@ -37,7 +37,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" @@ -1524,7 +1524,7 @@ TEST_P(ClientCallbackEnd2endTest, std::vector CreateTestScenarios(bool test_insecure) { #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif std::vector scenarios; diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index ee093b54749..7c714fd4395 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -54,8 +54,8 @@ #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/backoff/backoff.h" #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/debug_location.h" -#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/tcp_client.h" @@ -242,7 +242,7 @@ class ClientLbEnd2endTest : public ::testing::Test { GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 9f3467d34b6..4c9f0a28edf 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -42,7 +42,7 @@ #include #include "src/core/ext/filters/client_channel/backup_poller.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" @@ -2252,7 +2252,7 @@ std::vector CreateTestScenarios(bool use_proxy, kClientChannelBackupPollIntervalMs); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif if (test_secure) { diff --git a/test/cpp/end2end/flaky_network_test.cc b/test/cpp/end2end/flaky_network_test.cc index 10de61eb81d..17b3af710e4 100644 --- a/test/cpp/end2end/flaky_network_test.cc +++ b/test/cpp/end2end/flaky_network_test.cc @@ -43,7 +43,7 @@ #include #include "src/core/lib/backoff/backoff.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index e286672c02e..b18f9487ef2 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -46,7 +46,7 @@ #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" #include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/resolver/server_address.h" @@ -377,7 +377,7 @@ class GrpclbEnd2endTest : public ::testing::Test { GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif grpc_init(); } diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc index f803e3362f9..2c0d11dcc87 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -30,7 +30,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" @@ -233,7 +233,7 @@ class HybridEnd2endTest : public ::testing::TestWithParam { static void SetUpTestCase() { #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif } diff --git a/test/cpp/end2end/port_sharing_end2end_test.cc b/test/cpp/end2end/port_sharing_end2end_test.cc index a172b73c0f5..4abb75387fe 100644 --- a/test/cpp/end2end/port_sharing_end2end_test.cc +++ b/test/cpp/end2end/port_sharing_end2end_test.cc @@ -34,7 +34,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/endpoint.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/pollset.h" @@ -313,7 +313,7 @@ std::vector CreateTestScenarios() { #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif credentials_types = GetCredentialsProvider()->GetSecureCredentialsTypeList(); diff --git a/test/cpp/end2end/raw_end2end_test.cc b/test/cpp/end2end/raw_end2end_test.cc index 4839fe79a58..4bbda44eb68 100644 --- a/test/cpp/end2end/raw_end2end_test.cc +++ b/test/cpp/end2end/raw_end2end_test.cc @@ -33,7 +33,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/port.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" diff --git a/test/cpp/end2end/rls_end2end_test.cc b/test/cpp/end2end/rls_end2end_test.cc index b801155185f..13a44b6530c 100644 --- a/test/cpp/end2end/rls_end2end_test.cc +++ b/test/cpp/end2end/rls_end2end_test.cc @@ -43,7 +43,7 @@ #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" #include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/iomgr/sockaddr.h" @@ -158,7 +158,7 @@ class FakeResolverResponseGeneratorWrapper { class RlsEnd2endTest : public ::testing::Test { protected: static void SetUpTestSuite() { - grpc_core::SetEnv("GRPC_EXPERIMENTAL_ENABLE_RLS_LB_POLICY", "true"); + gpr_setenv("GRPC_EXPERIMENTAL_ENABLE_RLS_LB_POLICY", "true"); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); grpc_core::CoreConfiguration::RegisterBuilder( grpc_core::RegisterFixedAddressLoadBalancingPolicy); @@ -167,7 +167,7 @@ class RlsEnd2endTest : public ::testing::Test { static void TearDownTestSuite() { grpc_shutdown_blocking(); - grpc_core::UnsetEnv("GRPC_EXPERIMENTAL_ENABLE_RLS_LB_POLICY"); + gpr_unsetenv("GRPC_EXPERIMENTAL_ENABLE_RLS_LB_POLICY"); grpc_core::CoreConfiguration::Reset(); } diff --git a/test/cpp/end2end/shutdown_test.cc b/test/cpp/end2end/shutdown_test.cc index 82e8ca81b65..af8739964fb 100644 --- a/test/cpp/end2end/shutdown_test.cc +++ b/test/cpp/end2end/shutdown_test.cc @@ -30,7 +30,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 6a90b2b007e..9be625fadbd 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -33,7 +33,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/surface/api_trace.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" @@ -75,7 +75,7 @@ class CommonStressTest { CommonStressTest() : kMaxMessageSize_(8192) { #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif } virtual ~CommonStressTest() {} diff --git a/test/cpp/end2end/xds/xds_cluster_end2end_test.cc b/test/cpp/end2end/xds/xds_cluster_end2end_test.cc index cef45769fb0..16cfa1369b1 100644 --- a/test/cpp/end2end/xds/xds_cluster_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_cluster_end2end_test.cc @@ -1732,7 +1732,7 @@ int main(int argc, char** argv) { GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif grpc_init(); grpc::testing::ConnectionAttemptInjector::Init(); diff --git a/test/cpp/end2end/xds/xds_cluster_type_end2end_test.cc b/test/cpp/end2end/xds/xds_cluster_type_end2end_test.cc index 5521cc6b664..194ea5bc048 100644 --- a/test/cpp/end2end/xds/xds_cluster_type_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_cluster_type_end2end_test.cc @@ -27,7 +27,7 @@ #include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h" #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" #include "src/core/lib/address_utils/sockaddr_utils.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/resolver/server_address.h" #include "src/proto/grpc/testing/xds/v3/aggregate_cluster.grpc.pb.h" #include "test/cpp/end2end/connection_attempt_injector.h" @@ -784,7 +784,7 @@ int main(int argc, char** argv) { GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif grpc_init(); grpc::testing::ConnectionAttemptInjector::Init(); diff --git a/test/cpp/end2end/xds/xds_core_end2end_test.cc b/test/cpp/end2end/xds/xds_core_end2end_test.cc index 07cf5683874..6dadb621130 100644 --- a/test/cpp/end2end/xds/xds_core_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_core_end2end_test.cc @@ -1357,7 +1357,7 @@ int main(int argc, char** argv) { GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif grpc_init(); const auto result = RUN_ALL_TESTS(); diff --git a/test/cpp/end2end/xds/xds_csds_end2end_test.cc b/test/cpp/end2end/xds/xds_csds_end2end_test.cc index 63aeed36e0a..47f7f7f4841 100644 --- a/test/cpp/end2end/xds/xds_csds_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_csds_end2end_test.cc @@ -707,7 +707,7 @@ int main(int argc, char** argv) { GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif grpc_init(); const auto result = RUN_ALL_TESTS(); diff --git a/test/cpp/end2end/xds/xds_end2end_test.cc b/test/cpp/end2end/xds/xds_end2end_test.cc index fd796a7fb11..9862085b1e5 100644 --- a/test/cpp/end2end/xds/xds_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_end2end_test.cc @@ -69,10 +69,10 @@ #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/core_configuration.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gpr/tmpfile.h" -#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/time.h" @@ -4047,7 +4047,7 @@ int main(int argc, char** argv) { GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif grpc::testing::FakeCertificateProvider::CertDataMapWrapper cert_data_map_1; grpc::testing::g_fake1_cert_data_map = &cert_data_map_1; diff --git a/test/cpp/end2end/xds/xds_end2end_test_lib.cc b/test/cpp/end2end/xds/xds_end2end_test_lib.cc index f52736806b1..007167db320 100644 --- a/test/cpp/end2end/xds/xds_end2end_test_lib.cc +++ b/test/cpp/end2end/xds/xds_end2end_test_lib.cc @@ -39,8 +39,8 @@ #include "src/core/ext/filters/http/server/http_server_filter.h" #include "src/core/ext/xds/xds_channel_args.h" #include "src/core/ext/xds/xds_client_grpc.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/tmpfile.h" -#include "src/core/lib/gprpp/env.h" #include "src/core/lib/iomgr/load_file.h" #include "src/core/lib/surface/server.h" #include "src/cpp/client/secure_credentials.h" @@ -522,8 +522,8 @@ void XdsEnd2endTest::TearDown() { // Clear global xDS channel args, since they will go out of scope // when this test object is destroyed. grpc_core::internal::SetXdsChannelArgsForTest(nullptr); - grpc_core::UnsetEnv("GRPC_XDS_BOOTSTRAP"); - grpc_core::UnsetEnv("GRPC_XDS_BOOTSTRAP_CONFIG"); + gpr_unsetenv("GRPC_XDS_BOOTSTRAP"); + gpr_unsetenv("GRPC_XDS_BOOTSTRAP_CONFIG"); if (bootstrap_file_ != nullptr) { remove(bootstrap_file_); gpr_free(bootstrap_file_); @@ -751,12 +751,12 @@ void XdsEnd2endTest::InitClient(BootstrapBuilder builder, if (GetParam().use_v2()) builder.SetV2(); bootstrap_ = builder.Build(); if (GetParam().bootstrap_source() == XdsTestType::kBootstrapFromEnvVar) { - grpc_core::SetEnv("GRPC_XDS_BOOTSTRAP_CONFIG", bootstrap_.c_str()); + gpr_setenv("GRPC_XDS_BOOTSTRAP_CONFIG", bootstrap_.c_str()); } else if (GetParam().bootstrap_source() == XdsTestType::kBootstrapFromFile) { FILE* out = gpr_tmpfile("xds_bootstrap_v3", &bootstrap_file_); fputs(bootstrap_.c_str(), out); fclose(out); - grpc_core::SetEnv("GRPC_XDS_BOOTSTRAP", bootstrap_file_); + gpr_setenv("GRPC_XDS_BOOTSTRAP", bootstrap_file_); } if (GetParam().bootstrap_source() != XdsTestType::kBootstrapFromChannelArg) { // If getting bootstrap from channel arg, we'll pass these args in diff --git a/test/cpp/end2end/xds/xds_end2end_test_lib.h b/test/cpp/end2end/xds/xds_end2end_test_lib.h index de5d7a5b5b4..390346fdb6b 100644 --- a/test/cpp/end2end/xds/xds_end2end_test_lib.h +++ b/test/cpp/end2end/xds/xds_end2end_test_lib.h @@ -33,7 +33,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/security/credentials/fake/fake_credentials.h" #include "src/core/lib/security/security_connector/ssl_utils.h" #include "src/cpp/server/secure_server_credentials.h" @@ -466,10 +466,10 @@ class XdsEnd2endTest : public ::testing::TestWithParam { class ScopedExperimentalEnvVar { public: explicit ScopedExperimentalEnvVar(const char* env_var) : env_var_(env_var) { - grpc_core::SetEnv(env_var_, "true"); + gpr_setenv(env_var_, "true"); } - ~ScopedExperimentalEnvVar() { grpc_core::UnsetEnv(env_var_); } + ~ScopedExperimentalEnvVar() { gpr_unsetenv(env_var_); } private: const char* env_var_; diff --git a/test/cpp/end2end/xds/xds_fault_injection_end2end_test.cc b/test/cpp/end2end/xds/xds_fault_injection_end2end_test.cc index 61bba6561b3..39b8b33d104 100644 --- a/test/cpp/end2end/xds/xds_fault_injection_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_fault_injection_end2end_test.cc @@ -563,7 +563,7 @@ int main(int argc, char** argv) { GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif grpc_init(); const auto result = RUN_ALL_TESTS(); diff --git a/test/cpp/end2end/xds/xds_outlier_detection_end2end_test.cc b/test/cpp/end2end/xds/xds_outlier_detection_end2end_test.cc index df37137547a..451bce29144 100644 --- a/test/cpp/end2end/xds/xds_outlier_detection_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_outlier_detection_end2end_test.cc @@ -1245,16 +1245,16 @@ int main(int argc, char** argv) { GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif // TODO(roth): This is a hack to ensure that the outlier_detection LB policy // is always registered at gRPC init time. When the LB policy registry is // moved to the new CoreConfiguration system, change this to use // CoreConfiguration::BuildSpecialConfiguration() instead. - grpc_core::SetEnv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION", "true"); + gpr_setenv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION", "true"); grpc_init(); const auto result = RUN_ALL_TESTS(); grpc_shutdown(); - grpc_core::UnsetEnv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION"); + gpr_unsetenv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION"); return result; } diff --git a/test/cpp/end2end/xds/xds_ring_hash_end2end_test.cc b/test/cpp/end2end/xds/xds_ring_hash_end2end_test.cc index e55e6ce48ad..59083d1cbb7 100644 --- a/test/cpp/end2end/xds/xds_ring_hash_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_ring_hash_end2end_test.cc @@ -28,7 +28,7 @@ #include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h" #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" #include "src/core/lib/address_utils/sockaddr_utils.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/proto/grpc/testing/xds/v3/aggregate_cluster.grpc.pb.h" #include "src/proto/grpc/testing/xds/v3/cluster.grpc.pb.h" #include "test/cpp/end2end/connection_attempt_injector.h" @@ -1274,7 +1274,7 @@ int main(int argc, char** argv) { GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif grpc_init(); grpc::testing::ConnectionAttemptInjector::Init(); diff --git a/test/cpp/end2end/xds/xds_rls_end2end_test.cc b/test/cpp/end2end/xds/xds_rls_end2end_test.cc index 39f2e25e93e..490e2dcf7fb 100644 --- a/test/cpp/end2end/xds/xds_rls_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_rls_end2end_test.cc @@ -22,7 +22,7 @@ #include "absl/strings/str_cat.h" #include "src/core/ext/filters/client_channel/backup_poller.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/proto/grpc/lookup/v1/rls.grpc.pb.h" #include "src/proto/grpc/lookup/v1/rls.pb.h" #include "src/proto/grpc/lookup/v1/rls_config.pb.h" @@ -354,7 +354,7 @@ int main(int argc, char** argv) { GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif grpc_init(); const auto result = RUN_ALL_TESTS(); diff --git a/test/cpp/end2end/xds/xds_routing_end2end_test.cc b/test/cpp/end2end/xds/xds_routing_end2end_test.cc index f696f4bdbee..7fda2b49424 100644 --- a/test/cpp/end2end/xds/xds_routing_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_routing_end2end_test.cc @@ -3183,7 +3183,7 @@ int main(int argc, char** argv) { GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); #if TARGET_OS_IPHONE // Workaround Apple CFStream bug - grpc_core::SetEnv("grpc_cfstream", "0"); + gpr_setenv("grpc_cfstream", "0"); #endif grpc_init(); grpc_core::XdsHttpFilterRegistry::RegisterFilter( diff --git a/test/cpp/ext/gcp/observability_config_test.cc b/test/cpp/ext/gcp/observability_config_test.cc index 14173b3a307..45f3fdbb01a 100644 --- a/test/cpp/ext/gcp/observability_config_test.cc +++ b/test/cpp/ext/gcp/observability_config_test.cc @@ -21,8 +21,8 @@ #include +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/tmpfile.h" -#include "src/core/lib/gprpp/env.h" #include "test/core/util/test_config.h" namespace grpc { @@ -82,15 +82,15 @@ TEST(GcpEnvParsingTest, NoEnvironmentVariableSet) { } TEST(GcpEnvParsingTest, ConfigFileDoesNotExist) { - grpc_core::SetEnv("GRPC_OBSERVABILITY_CONFIG_FILE", - "/tmp/gcp_observability_config_does_not_exist"); + gpr_setenv("GRPC_OBSERVABILITY_CONFIG_FILE", + "/tmp/gcp_observability_config_does_not_exist"); auto config = GcpObservabilityConfig::ReadFromEnv(); EXPECT_EQ(config.status(), absl::FailedPreconditionError("Failed to load file")); - grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG_FILE"); + gpr_unsetenv("GRPC_OBSERVABILITY_CONFIG_FILE"); } class EnvParsingTestType { @@ -131,13 +131,13 @@ class EnvParsingTest : public ::testing::TestWithParam { ~EnvParsingTest() override { if (GetParam().config_source() == EnvParsingTestType::ConfigSource::kFile) { if (tmp_file_name != nullptr) { - grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG_FILE"); + gpr_unsetenv("GRPC_OBSERVABILITY_CONFIG_FILE"); remove(tmp_file_name); gpr_free(tmp_file_name); } } else if (GetParam().config_source() == EnvParsingTestType::ConfigSource::kEnvVar) { - grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG"); + gpr_unsetenv("GRPC_OBSERVABILITY_CONFIG"); } } @@ -148,10 +148,10 @@ class EnvParsingTest : public ::testing::TestWithParam { gpr_tmpfile("gcp_observability_config", &tmp_file_name); fputs(json, tmp_config_file); fclose(tmp_config_file); - grpc_core::SetEnv("GRPC_OBSERVABILITY_CONFIG_FILE", tmp_file_name); + gpr_setenv("GRPC_OBSERVABILITY_CONFIG_FILE", tmp_file_name); } else if (GetParam().config_source() == EnvParsingTestType::ConfigSource::kEnvVar) { - grpc_core::SetEnv("GRPC_OBSERVABILITY_CONFIG", json); + gpr_setenv("GRPC_OBSERVABILITY_CONFIG", json); } } diff --git a/test/cpp/interop/istio_echo_server.cc b/test/cpp/interop/istio_echo_server.cc index 3987b76da2c..adba842ae4d 100644 --- a/test/cpp/interop/istio_echo_server.cc +++ b/test/cpp/interop/istio_echo_server.cc @@ -44,7 +44,7 @@ #include #include "src/core/lib/channel/status_util.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/iomgr/gethostname.h" #include "src/proto/grpc/testing/istio_echo.pb.h" diff --git a/test/cpp/interop/xds_interop_client.cc b/test/cpp/interop/xds_interop_client.cc index 627ed1083bd..3bd18952d94 100644 --- a/test/cpp/interop/xds_interop_client.cc +++ b/test/cpp/interop/xds_interop_client.cc @@ -40,7 +40,7 @@ #include #include "src/core/lib/channel/status_util.h" -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/proto/grpc/testing/empty.pb.h" #include "src/proto/grpc/testing/messages.pb.h" #include "src/proto/grpc/testing/test.grpc.pb.h" diff --git a/test/cpp/naming/resolver_component_tests_runner_invoker.cc b/test/cpp/naming/resolver_component_tests_runner_invoker.cc index ab5f0ac0e7f..efbb41c9962 100644 --- a/test/cpp/naming/resolver_component_tests_runner_invoker.cc +++ b/test/cpp/naming/resolver_component_tests_runner_invoker.cc @@ -35,7 +35,7 @@ #include #endif -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" #include "test/cpp/util/subprocess.h" @@ -129,9 +129,9 @@ int main(int argc, char** argv) { .empty()); // Use bazel's TEST_SRCDIR environment variable to locate the "test data" // binaries. - auto test_srcdir = grpc_core::GetEnv("TEST_SRCDIR"); + char* test_srcdir = gpr_getenv("TEST_SRCDIR"); std::string const bin_dir = - test_srcdir.value() + + test_srcdir + absl::GetFlag(FLAGS_grpc_test_directory_relative_to_test_srcdir) + std::string("/test/cpp/naming"); // Invoke bazel's executeable links to the .sh and .py scripts (don't use @@ -143,6 +143,7 @@ int main(int argc, char** argv) { bin_dir + "/utils/dns_server", bin_dir + "/resolver_test_record_groups.yaml", bin_dir + "/utils/dns_resolver", bin_dir + "/utils/tcp_connect"); + gpr_free(test_srcdir); } else { // Get the current binary's directory relative to repo root to invoke the // correct build config (asan/tsan/dbg, etc.). diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index 4ef14cd07f6..1ec0dda0656 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -37,7 +37,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/cpp/util/core_stats.h" #include "src/proto/grpc/testing/benchmark_service.grpc.pb.h" #include "src/proto/grpc/testing/payloads.pb.h" @@ -457,15 +457,16 @@ class ClientImpl : public Client { /* Allow optionally overriding connect_deadline in order * to deal with benchmark environments in which the server * can take a long time to become ready. */ - auto channel_connect_timeout_str = - grpc_core::GetEnv("QPS_WORKER_CHANNEL_CONNECT_TIMEOUT"); - if (channel_connect_timeout_str.has_value() && - !channel_connect_timeout_str->empty()) { - connect_deadline_seconds = atoi(channel_connect_timeout_str->c_str()); + char* channel_connect_timeout_str = + gpr_getenv("QPS_WORKER_CHANNEL_CONNECT_TIMEOUT"); + if (channel_connect_timeout_str != nullptr && + strcmp(channel_connect_timeout_str, "") != 0) { + connect_deadline_seconds = atoi(channel_connect_timeout_str); } gpr_log(GPR_INFO, "Waiting for up to %d seconds for all channels to connect", connect_deadline_seconds); + gpr_free(channel_connect_timeout_str); gpr_timespec connect_deadline = gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(connect_deadline_seconds, GPR_TIMESPAN)); diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 462c7f9bd30..29ed3488cc4 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -34,7 +34,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/host_port.h" #include "src/proto/grpc/testing/worker_service.grpc.pb.h" #include "test/core/util/port.h" @@ -61,11 +61,14 @@ static std::string get_host(const std::string& worker) { static deque get_workers(const string& env_name) { deque out; - auto env = grpc_core::GetEnv(env_name.c_str()).value_or(""); - const char* p = env.c_str(); - if (!env.empty()) { + char* env = gpr_getenv(env_name.c_str()); + if (!env) { + env = gpr_strdup(""); + } + char* p = env; + if (strlen(env) != 0) { for (;;) { - const char* comma = strchr(p, ','); + char* comma = strchr(p, ','); if (comma) { out.emplace_back(p, comma); p = comma + 1; @@ -84,6 +87,7 @@ static deque get_workers(const string& env_name) { "%s=\"serverhost1:1234,clienthost1:1234,clienthost2:1234\"", env_name.c_str(), env_name.c_str()); } + gpr_free(env); return out; } diff --git a/test/cpp/qps/json_run_localhost.cc b/test/cpp/qps/json_run_localhost.cc index 96f7bca8e32..b515efebf8d 100644 --- a/test/cpp/qps/json_run_localhost.cc +++ b/test/cpp/qps/json_run_localhost.cc @@ -30,7 +30,7 @@ #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "test/core/util/port.h" #include "test/cpp/util/subprocess.h" @@ -101,7 +101,7 @@ int main(int argc, char** argv) { first = false; } - grpc_core::SetEnv("QPS_WORKERS", env.str().c_str()); + gpr_setenv("QPS_WORKERS", env.str().c_str()); std::vector args = {bin_dir + "/qps_json_driver"}; for (int i = 1; i < argc; i++) { args.push_back(argv[i]); diff --git a/test/cpp/util/channelz_sampler_test.cc b/test/cpp/util/channelz_sampler_test.cc index 9757fcd129e..dd23c9899fa 100644 --- a/test/cpp/util/channelz_sampler_test.cc +++ b/test/cpp/util/channelz_sampler_test.cc @@ -42,7 +42,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/cpp/server/channelz/channelz_service.h" #include "src/proto/grpc/testing/test.grpc.pb.h" #include "test/core/util/port.h" diff --git a/test/cpp/util/grpc_tool_test.cc b/test/cpp/util/grpc_tool_test.cc index 2a927a606e8..2aac9c7df37 100644 --- a/test/cpp/util/grpc_tool_test.cc +++ b/test/cpp/util/grpc_tool_test.cc @@ -36,7 +36,7 @@ #include #include -#include "src/core/lib/gprpp/env.h" +#include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/load_file.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/echo.pb.h" @@ -1264,10 +1264,10 @@ TEST_F(GrpcToolTest, CallCommandWithBadMetadata) { "grpc.testing.EchoTestService.Echo", "message: 'Hello'"}; absl::SetFlag(&FLAGS_protofiles, "src/proto/grpc/testing/echo.proto"); - auto test_srcdir = grpc_core::GetEnv("TEST_SRCDIR"); - if (test_srcdir.has_value()) { + char* test_srcdir = gpr_getenv("TEST_SRCDIR"); + if (test_srcdir != nullptr) { absl::SetFlag(&FLAGS_proto_path, - *test_srcdir + std::string("/com_github_grpc_grpc")); + test_srcdir + std::string("/com_github_grpc_grpc")); } { @@ -1294,6 +1294,8 @@ TEST_F(GrpcToolTest, CallCommandWithBadMetadata) { absl::SetFlag(&FLAGS_metadata, ""); absl::SetFlag(&FLAGS_protofiles, ""); + + gpr_free(test_srcdir); } TEST_F(GrpcToolTest, ListCommand_OverrideSslHostName) { diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index e412d176247..c7883774c65 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1991,6 +1991,10 @@ src/core/lib/gpr/cpu_iphone.cc \ src/core/lib/gpr/cpu_linux.cc \ src/core/lib/gpr/cpu_posix.cc \ src/core/lib/gpr/cpu_windows.cc \ +src/core/lib/gpr/env.h \ +src/core/lib/gpr/env_linux.cc \ +src/core/lib/gpr/env_posix.cc \ +src/core/lib/gpr/env_windows.cc \ src/core/lib/gpr/log.cc \ src/core/lib/gpr/log_android.cc \ src/core/lib/gpr/log_linux.cc \ @@ -2027,10 +2031,6 @@ src/core/lib/gprpp/construct_destruct.h \ src/core/lib/gprpp/cpp_impl_of.h \ src/core/lib/gprpp/debug_location.h \ src/core/lib/gprpp/dual_ref_counted.h \ -src/core/lib/gprpp/env.h \ -src/core/lib/gprpp/env_linux.cc \ -src/core/lib/gprpp/env_posix.cc \ -src/core/lib/gprpp/env_windows.cc \ src/core/lib/gprpp/examine_stack.cc \ src/core/lib/gprpp/examine_stack.h \ src/core/lib/gprpp/fork.cc \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 1ddfb76fc7c..50fa2db61a9 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1782,6 +1782,10 @@ src/core/lib/gpr/cpu_iphone.cc \ src/core/lib/gpr/cpu_linux.cc \ src/core/lib/gpr/cpu_posix.cc \ src/core/lib/gpr/cpu_windows.cc \ +src/core/lib/gpr/env.h \ +src/core/lib/gpr/env_linux.cc \ +src/core/lib/gpr/env_posix.cc \ +src/core/lib/gpr/env_windows.cc \ src/core/lib/gpr/log.cc \ src/core/lib/gpr/log_android.cc \ src/core/lib/gpr/log_linux.cc \ @@ -1819,10 +1823,6 @@ src/core/lib/gprpp/construct_destruct.h \ src/core/lib/gprpp/cpp_impl_of.h \ src/core/lib/gprpp/debug_location.h \ src/core/lib/gprpp/dual_ref_counted.h \ -src/core/lib/gprpp/env.h \ -src/core/lib/gprpp/env_linux.cc \ -src/core/lib/gprpp/env_posix.cc \ -src/core/lib/gprpp/env_windows.cc \ src/core/lib/gprpp/examine_stack.cc \ src/core/lib/gprpp/examine_stack.h \ src/core/lib/gprpp/fork.cc \