Revert "[c++] Move environment functions to C++ (#30937)" (#30986)

This reverts commit 74c0d6fe3f.
pull/30987/head
Craig Tiller 2 years ago committed by GitHub
parent 61ee1656d2
commit 96264e07b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      BUILD
  2. 6
      CMakeLists.txt
  3. 6
      Makefile
  4. 8
      build_autogenerated.yaml
  5. 6
      config.m4
  6. 6
      config.w32
  7. 4
      gRPC-C++.podspec
  8. 10
      gRPC-Core.podspec
  9. 8
      grpc.gemspec
  10. 6
      grpc.gyp
  11. 8
      package.xml
  12. 25
      src/core/ext/filters/client_channel/http_proxy.cc
  13. 9
      src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc
  14. 15
      src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc
  15. 10
      src/core/ext/xds/xds_bootstrap.cc
  16. 17
      src/core/ext/xds/xds_client_grpc.cc
  17. 15
      src/core/ext/xds/xds_route_config.cc
  18. 37
      src/core/lib/gpr/env.h
  19. 35
      src/core/lib/gpr/env_linux.cc
  20. 21
      src/core/lib/gpr/env_posix.cc
  21. 38
      src/core/lib/gpr/env_windows.cc
  22. 13
      src/core/lib/gprpp/global_config_env.cc
  23. 31
      src/core/lib/security/credentials/external/aws_external_account_credentials.cc
  24. 13
      src/core/lib/security/credentials/google_default/credentials_generic.cc
  25. 9
      src/core/lib/security/credentials/google_default/google_default_credentials.cc
  26. 13
      src/cpp/client/secure_credentials.cc
  27. 2
      src/cpp/ext/gcp/BUILD
  28. 21
      src/cpp/ext/gcp/observability_config.cc
  29. 2
      src/objective-c/tests/CronetTests/CronetUnitTests.mm
  30. 6
      src/python/grpcio/grpc_core_dependencies.py
  31. 6
      test/core/client_channel/http_proxy_mapper_test.cc
  32. 4
      test/core/client_channel/resolvers/google_c2p_resolver_test.cc
  33. 2
      test/core/client_channel/rls_lb_config_parser_test.cc
  34. 4
      test/core/end2end/fixtures/h2_http_proxy.cc
  35. 8
      test/core/end2end/fuzzers/api_fuzzer.cc
  36. 8
      test/core/filters/filter_fuzzer.cc
  37. 20
      test/core/gpr/env_test.cc
  38. 28
      test/core/gprpp/global_config_env_test.cc
  39. 2
      test/core/gprpp/global_config_test.cc
  40. 2
      test/core/http/httpscli_test.cc
  41. 2
      test/core/iomgr/resolve_address_posix_test.cc
  42. 6
      test/core/security/alts_credentials_fuzzer.cc
  43. 113
      test/core/security/credentials_test.cc
  44. 2
      test/core/security/system_roots_test.cc
  45. 2
      test/core/util/BUILD
  46. 13
      test/core/util/fuzzer_corpus_test.cc
  47. 6
      test/core/util/test_config.cc
  48. 20
      test/core/xds/xds_bootstrap_test.cc
  49. 6
      test/core/xds/xds_client_test.cc
  50. 8
      test/cpp/client/credentials_test.cc
  51. 4
      test/cpp/end2end/cfstream_test.cc
  52. 4
      test/cpp/end2end/channelz_service_test.cc
  53. 4
      test/cpp/end2end/client_callback_end2end_test.cc
  54. 4
      test/cpp/end2end/client_lb_end2end_test.cc
  55. 4
      test/cpp/end2end/end2end_test.cc
  56. 2
      test/cpp/end2end/flaky_network_test.cc
  57. 4
      test/cpp/end2end/grpclb_end2end_test.cc
  58. 4
      test/cpp/end2end/hybrid_end2end_test.cc
  59. 4
      test/cpp/end2end/port_sharing_end2end_test.cc
  60. 2
      test/cpp/end2end/raw_end2end_test.cc
  61. 6
      test/cpp/end2end/rls_end2end_test.cc
  62. 2
      test/cpp/end2end/shutdown_test.cc
  63. 4
      test/cpp/end2end/thread_stress_test.cc
  64. 2
      test/cpp/end2end/xds/xds_cluster_end2end_test.cc
  65. 4
      test/cpp/end2end/xds/xds_cluster_type_end2end_test.cc
  66. 2
      test/cpp/end2end/xds/xds_core_end2end_test.cc
  67. 2
      test/cpp/end2end/xds/xds_csds_end2end_test.cc
  68. 4
      test/cpp/end2end/xds/xds_end2end_test.cc
  69. 10
      test/cpp/end2end/xds/xds_end2end_test_lib.cc
  70. 6
      test/cpp/end2end/xds/xds_end2end_test_lib.h
  71. 2
      test/cpp/end2end/xds/xds_fault_injection_end2end_test.cc
  72. 6
      test/cpp/end2end/xds/xds_outlier_detection_end2end_test.cc
  73. 4
      test/cpp/end2end/xds/xds_ring_hash_end2end_test.cc
  74. 4
      test/cpp/end2end/xds/xds_rls_end2end_test.cc
  75. 2
      test/cpp/end2end/xds/xds_routing_end2end_test.cc
  76. 14
      test/cpp/ext/gcp/observability_config_test.cc
  77. 2
      test/cpp/interop/istio_echo_server.cc
  78. 2
      test/cpp/interop/xds_interop_client.cc
  79. 7
      test/cpp/naming/resolver_component_tests_runner_invoker.cc
  80. 13
      test/cpp/qps/client.h
  81. 14
      test/cpp/qps/driver.cc
  82. 4
      test/cpp/qps/json_run_localhost.cc
  83. 2
      test/cpp/util/channelz_sampler_test.cc
  84. 10
      test/cpp/util/grpc_tool_test.cc
  85. 8
      tools/doxygen/Doxyfile.c++.internal
  86. 8
      tools/doxygen/Doxyfile.core.internal

33
BUILD

@ -1021,23 +1021,6 @@ grpc_cc_library(
deps = ["gpr_platform"], 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( grpc_cc_library(
name = "gpr", name = "gpr",
srcs = [ srcs = [
@ -1046,6 +1029,9 @@ grpc_cc_library(
"src/core/lib/gpr/cpu_linux.cc", "src/core/lib/gpr/cpu_linux.cc",
"src/core/lib/gpr/cpu_posix.cc", "src/core/lib/gpr/cpu_posix.cc",
"src/core/lib/gpr/cpu_windows.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.cc",
"src/core/lib/gpr/log_android.cc", "src/core/lib/gpr/log_android.cc",
"src/core/lib/gpr/log_linux.cc", "src/core/lib/gpr/log_linux.cc",
@ -1079,6 +1065,7 @@ grpc_cc_library(
], ],
hdrs = [ hdrs = [
"src/core/lib/gpr/alloc.h", "src/core/lib/gpr/alloc.h",
"src/core/lib/gpr/env.h",
"src/core/lib/gpr/string.h", "src/core/lib/gpr/string.h",
"src/core/lib/gpr/time_precise.h", "src/core/lib/gpr/time_precise.h",
"src/core/lib/gpr/tmpfile.h", "src/core/lib/gpr/tmpfile.h",
@ -1116,7 +1103,6 @@ grpc_cc_library(
visibility = ["@grpc:public"], visibility = ["@grpc:public"],
deps = [ deps = [
"construct_destruct", "construct_destruct",
"env",
"examine_stack", "examine_stack",
"gpr_atm", "gpr_atm",
"gpr_tls", "gpr_tls",
@ -3844,7 +3830,6 @@ grpc_cc_library(
"debug_location", "debug_location",
"default_event_engine", "default_event_engine",
"dual_ref_counted", "dual_ref_counted",
"env",
"gpr", "gpr",
"gpr_atm", "gpr_atm",
"grpc_backend_metric_data", "grpc_backend_metric_data",
@ -4470,7 +4455,6 @@ grpc_cc_library(
"debug_location", "debug_location",
"default_event_engine", "default_event_engine",
"dual_ref_counted", "dual_ref_counted",
"env",
"envoy_admin_upb", "envoy_admin_upb",
"envoy_config_core_upb", "envoy_config_core_upb",
"envoy_config_endpoint_upb", "envoy_config_endpoint_upb",
@ -4599,7 +4583,6 @@ grpc_cc_library(
"config", "config",
"debug_location", "debug_location",
"default_event_engine", "default_event_engine",
"env",
"envoy_admin_upb", "envoy_admin_upb",
"envoy_config_cluster_upb", "envoy_config_cluster_upb",
"envoy_config_cluster_upbdefs", "envoy_config_cluster_upbdefs",
@ -5184,7 +5167,6 @@ grpc_cc_library(
"closure", "closure",
"config", "config",
"debug_location", "debug_location",
"env",
"exec_ctx", "exec_ctx",
"gpr", "gpr",
"grpc_base", "grpc_base",
@ -5754,7 +5736,6 @@ grpc_cc_library(
"alts_util", "alts_util",
"config", "config",
"debug_location", "debug_location",
"env",
"gpr", "gpr",
"grpc_base", "grpc_base",
"grpc_codegen", "grpc_codegen",
@ -6098,7 +6079,6 @@ grpc_cc_library(
tags = ["nofixdeps"], tags = ["nofixdeps"],
deps = [ deps = [
"alts_util", "alts_util",
"env",
"gpr", "gpr",
"grpc_alts_credentials", "grpc_alts_credentials",
"grpc_base", "grpc_base",
@ -6321,12 +6301,10 @@ grpc_cc_library(
"absl/strings", "absl/strings",
"absl/strings:str_format", "absl/strings:str_format",
"absl/time", "absl/time",
"absl/types:optional",
"libcrypto", "libcrypto",
], ],
language = "c++", language = "c++",
deps = [ deps = [
"env",
"gpr", "gpr",
"grpc_base", "grpc_base",
"grpc_credentials_util", "grpc_credentials_util",
@ -7198,8 +7176,8 @@ grpc_cc_library(
"absl/status:statusor", "absl/status:statusor",
"absl/strings", "absl/strings",
"absl/synchronization", "absl/synchronization",
"absl/memory",
"absl/types:optional", "absl/types:optional",
"absl/memory",
"upb_lib", "upb_lib",
"protobuf_headers", "protobuf_headers",
"absl/container:inlined_vector", "absl/container:inlined_vector",
@ -7214,7 +7192,6 @@ grpc_cc_library(
"channel_init", "channel_init",
"channel_stack_type", "channel_stack_type",
"config", "config",
"env",
"error", "error",
"gpr", "gpr",
"gpr_manual_constructor", "gpr_manual_constructor",

6
CMakeLists.txt generated

@ -1531,6 +1531,9 @@ add_library(gpr
src/core/lib/gpr/cpu_linux.cc src/core/lib/gpr/cpu_linux.cc
src/core/lib/gpr/cpu_posix.cc src/core/lib/gpr/cpu_posix.cc
src/core/lib/gpr/cpu_windows.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.cc
src/core/lib/gpr/log_android.cc src/core/lib/gpr/log_android.cc
src/core/lib/gpr/log_linux.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_posix.cc
src/core/lib/gpr/tmpfile_windows.cc src/core/lib/gpr/tmpfile_windows.cc
src/core/lib/gpr/wrap_memcpy.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/examine_stack.cc
src/core/lib/gprpp/fork.cc src/core/lib/gprpp/fork.cc
src/core/lib/gprpp/global_config_env.cc src/core/lib/gprpp/global_config_env.cc

6
Makefile generated

@ -847,6 +847,9 @@ LIBGPR_SRC = \
src/core/lib/gpr/cpu_linux.cc \ src/core/lib/gpr/cpu_linux.cc \
src/core/lib/gpr/cpu_posix.cc \ src/core/lib/gpr/cpu_posix.cc \
src/core/lib/gpr/cpu_windows.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.cc \
src/core/lib/gpr/log_android.cc \ src/core/lib/gpr/log_android.cc \
src/core/lib/gpr/log_linux.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_posix.cc \
src/core/lib/gpr/tmpfile_windows.cc \ src/core/lib/gpr/tmpfile_windows.cc \
src/core/lib/gpr/wrap_memcpy.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/examine_stack.cc \
src/core/lib/gprpp/fork.cc \ src/core/lib/gprpp/fork.cc \
src/core/lib/gprpp/global_config_env.cc \ src/core/lib/gprpp/global_config_env.cc \

@ -199,13 +199,13 @@ libs:
- include/grpc/support/time.h - include/grpc/support/time.h
headers: headers:
- src/core/lib/gpr/alloc.h - src/core/lib/gpr/alloc.h
- src/core/lib/gpr/env.h
- src/core/lib/gpr/string.h - src/core/lib/gpr/string.h
- src/core/lib/gpr/time_precise.h - src/core/lib/gpr/time_precise.h
- src/core/lib/gpr/tls.h - src/core/lib/gpr/tls.h
- src/core/lib/gpr/tmpfile.h - src/core/lib/gpr/tmpfile.h
- src/core/lib/gpr/useful.h - src/core/lib/gpr/useful.h
- src/core/lib/gprpp/construct_destruct.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/examine_stack.h
- src/core/lib/gprpp/fork.h - src/core/lib/gprpp/fork.h
- src/core/lib/gprpp/global_config.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_linux.cc
- src/core/lib/gpr/cpu_posix.cc - src/core/lib/gpr/cpu_posix.cc
- src/core/lib/gpr/cpu_windows.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.cc
- src/core/lib/gpr/log_android.cc - src/core/lib/gpr/log_android.cc
- src/core/lib/gpr/log_linux.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_posix.cc
- src/core/lib/gpr/tmpfile_windows.cc - src/core/lib/gpr/tmpfile_windows.cc
- src/core/lib/gpr/wrap_memcpy.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/examine_stack.cc
- src/core/lib/gprpp/fork.cc - src/core/lib/gprpp/fork.cc
- src/core/lib/gprpp/global_config_env.cc - src/core/lib/gprpp/global_config_env.cc

6
config.m4 generated

@ -496,6 +496,9 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/gpr/cpu_linux.cc \ src/core/lib/gpr/cpu_linux.cc \
src/core/lib/gpr/cpu_posix.cc \ src/core/lib/gpr/cpu_posix.cc \
src/core/lib/gpr/cpu_windows.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.cc \
src/core/lib/gpr/log_android.cc \ src/core/lib/gpr/log_android.cc \
src/core/lib/gpr/log_linux.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_posix.cc \
src/core/lib/gpr/tmpfile_windows.cc \ src/core/lib/gpr/tmpfile_windows.cc \
src/core/lib/gpr/wrap_memcpy.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/examine_stack.cc \
src/core/lib/gprpp/fork.cc \ src/core/lib/gprpp/fork.cc \
src/core/lib/gprpp/global_config_env.cc \ src/core/lib/gprpp/global_config_env.cc \

6
config.w32 generated

@ -462,6 +462,9 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\gpr\\cpu_linux.cc " + "src\\core\\lib\\gpr\\cpu_linux.cc " +
"src\\core\\lib\\gpr\\cpu_posix.cc " + "src\\core\\lib\\gpr\\cpu_posix.cc " +
"src\\core\\lib\\gpr\\cpu_windows.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.cc " +
"src\\core\\lib\\gpr\\log_android.cc " + "src\\core\\lib\\gpr\\log_android.cc " +
"src\\core\\lib\\gpr\\log_linux.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_posix.cc " +
"src\\core\\lib\\gpr\\tmpfile_windows.cc " + "src\\core\\lib\\gpr\\tmpfile_windows.cc " +
"src\\core\\lib\\gpr\\wrap_memcpy.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\\examine_stack.cc " +
"src\\core\\lib\\gprpp\\fork.cc " + "src\\core\\lib\\gprpp\\fork.cc " +
"src\\core\\lib\\gprpp\\global_config_env.cc " + "src\\core\\lib\\gprpp\\global_config_env.cc " +

4
gRPC-C++.podspec generated

@ -701,6 +701,7 @@ Pod::Spec.new do |s|
'src/core/lib/experiments/config.h', 'src/core/lib/experiments/config.h',
'src/core/lib/experiments/experiments.h', 'src/core/lib/experiments/experiments.h',
'src/core/lib/gpr/alloc.h', 'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h', 'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.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/cpp_impl_of.h',
'src/core/lib/gprpp/debug_location.h', 'src/core/lib/gprpp/debug_location.h',
'src/core/lib/gprpp/dual_ref_counted.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/examine_stack.h',
'src/core/lib/gprpp/fork.h', 'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/global_config.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/config.h',
'src/core/lib/experiments/experiments.h', 'src/core/lib/experiments/experiments.h',
'src/core/lib/gpr/alloc.h', 'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h', 'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.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/cpp_impl_of.h',
'src/core/lib/gprpp/debug_location.h', 'src/core/lib/gprpp/debug_location.h',
'src/core/lib/gprpp/dual_ref_counted.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/examine_stack.h',
'src/core/lib/gprpp/fork.h', 'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/global_config.h', 'src/core/lib/gprpp/global_config.h',

10
gRPC-Core.podspec generated

@ -1095,6 +1095,10 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/cpu_linux.cc', 'src/core/lib/gpr/cpu_linux.cc',
'src/core/lib/gpr/cpu_posix.cc', 'src/core/lib/gpr/cpu_posix.cc',
'src/core/lib/gpr/cpu_windows.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.cc',
'src/core/lib/gpr/log_android.cc', 'src/core/lib/gpr/log_android.cc',
'src/core/lib/gpr/log_linux.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/cpp_impl_of.h',
'src/core/lib/gprpp/debug_location.h', 'src/core/lib/gprpp/debug_location.h',
'src/core/lib/gprpp/dual_ref_counted.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.cc',
'src/core/lib/gprpp/examine_stack.h', 'src/core/lib/gprpp/examine_stack.h',
'src/core/lib/gprpp/fork.cc', '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/config.h',
'src/core/lib/experiments/experiments.h', 'src/core/lib/experiments/experiments.h',
'src/core/lib/gpr/alloc.h', 'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/murmur_hash.h', 'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h', 'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.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/cpp_impl_of.h',
'src/core/lib/gprpp/debug_location.h', 'src/core/lib/gprpp/debug_location.h',
'src/core/lib/gprpp/dual_ref_counted.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/examine_stack.h',
'src/core/lib/gprpp/fork.h', 'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/global_config.h', 'src/core/lib/gprpp/global_config.h',

8
grpc.gemspec generated

@ -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_linux.cc )
s.files += %w( src/core/lib/gpr/cpu_posix.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/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.cc )
s.files += %w( src/core/lib/gpr/log_android.cc ) s.files += %w( src/core/lib/gpr/log_android.cc )
s.files += %w( src/core/lib/gpr/log_linux.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/cpp_impl_of.h )
s.files += %w( src/core/lib/gprpp/debug_location.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/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.cc )
s.files += %w( src/core/lib/gprpp/examine_stack.h ) s.files += %w( src/core/lib/gprpp/examine_stack.h )
s.files += %w( src/core/lib/gprpp/fork.cc ) s.files += %w( src/core/lib/gprpp/fork.cc )

6
grpc.gyp generated

@ -314,6 +314,9 @@
'src/core/lib/gpr/cpu_linux.cc', 'src/core/lib/gpr/cpu_linux.cc',
'src/core/lib/gpr/cpu_posix.cc', 'src/core/lib/gpr/cpu_posix.cc',
'src/core/lib/gpr/cpu_windows.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.cc',
'src/core/lib/gpr/log_android.cc', 'src/core/lib/gpr/log_android.cc',
'src/core/lib/gpr/log_linux.cc', 'src/core/lib/gpr/log_linux.cc',
@ -335,9 +338,6 @@
'src/core/lib/gpr/tmpfile_posix.cc', 'src/core/lib/gpr/tmpfile_posix.cc',
'src/core/lib/gpr/tmpfile_windows.cc', 'src/core/lib/gpr/tmpfile_windows.cc',
'src/core/lib/gpr/wrap_memcpy.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/examine_stack.cc',
'src/core/lib/gprpp/fork.cc', 'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/global_config_env.cc', 'src/core/lib/gprpp/global_config_env.cc',

8
package.xml generated

@ -990,6 +990,10 @@
<file baseinstalldir="/" name="src/core/lib/gpr/cpu_linux.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/cpu_linux.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/cpu_posix.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/cpu_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/cpu_windows.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/cpu_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/env.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/env_linux.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/env_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/env_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/log.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log_android.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/log_android.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log_linux.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gpr/log_linux.cc" role="src" />
@ -1026,10 +1030,6 @@
<file baseinstalldir="/" name="src/core/lib/gprpp/cpp_impl_of.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/cpp_impl_of.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/debug_location.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/debug_location.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/dual_ref_counted.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/dual_ref_counted.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/env.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/env_linux.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/env_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/env_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/examine_stack.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/examine_stack.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/examine_stack.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/examine_stack.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/fork.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/fork.cc" role="src" />

@ -40,8 +40,8 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h" #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/string.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gprpp/host_port.h" #include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/handshaker/proxy_mapper_registry.h" #include "src/core/lib/handshaker/proxy_mapper_registry.h"
@ -73,9 +73,16 @@ absl::optional<std::string> GetHttpProxyServer(
*/ */
absl::optional<std::string> uri_str = absl::optional<std::string> uri_str =
args.GetOwnedString(GRPC_ARG_HTTP_PROXY); args.GetOwnedString(GRPC_ARG_HTTP_PROXY);
if (!uri_str.has_value()) uri_str = GetEnv("grpc_proxy"); auto get_env = [](const char* name) -> absl::optional<std::string> {
if (!uri_str.has_value()) uri_str = GetEnv("https_proxy"); char* v = gpr_getenv(name);
if (!uri_str.has_value()) uri_str = GetEnv("http_proxy"); 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; if (!uri_str.has_value()) return absl::nullopt;
// an emtpy value means "don't use proxy" // an emtpy value means "don't use proxy"
if (uri_str->empty()) return absl::nullopt; if (uri_str->empty()) return absl::nullopt;
@ -151,11 +158,11 @@ absl::optional<std::string> HttpProxyMapper::MapName(
return absl::nullopt; return absl::nullopt;
} }
/* Prefer using 'no_grpc_proxy'. Fallback on 'no_proxy' if it is not set. */ /* Prefer using 'no_grpc_proxy'. Fallback on 'no_proxy' if it is not set. */
auto no_proxy_str = GetEnv("no_grpc_proxy"); auto no_proxy_str = UniquePtr<char>(gpr_getenv("no_grpc_proxy"));
if (!no_proxy_str.has_value()) { if (no_proxy_str == nullptr) {
no_proxy_str = GetEnv("no_proxy"); no_proxy_str = UniquePtr<char>(gpr_getenv("no_proxy"));
} }
if (no_proxy_str.has_value()) { if (no_proxy_str != nullptr) {
bool use_proxy = true; bool use_proxy = true;
std::string server_host; std::string server_host;
std::string server_port; std::string server_port;
@ -167,7 +174,7 @@ absl::optional<std::string> HttpProxyMapper::MapName(
std::string(server_uri).c_str()); std::string(server_uri).c_str());
} else { } else {
std::vector<absl::string_view> no_proxy_hosts = std::vector<absl::string_view> 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) { for (const auto& no_proxy_entry : no_proxy_hosts) {
if (absl::EndsWithIgnoreCase(server_host, no_proxy_entry)) { if (absl::EndsWithIgnoreCase(server_host, no_proxy_entry)) {
gpr_log(GPR_INFO, "not using proxy for host in no_proxy list '%s'", gpr_log(GPR_INFO, "not using proxy for host in no_proxy list '%s'",

@ -42,6 +42,7 @@
#include "absl/types/variant.h" #include "absl/types/variant.h"
#include <grpc/impl/codegen/connectivity_state.h> #include <grpc/impl/codegen/connectivity_state.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h" #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/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h" #include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.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/gpr/string.h"
#include "src/core/lib/gprpp/debug_location.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/orphanable.h"
#include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted.h"
#include "src/core/lib/gprpp/ref_counted_ptr.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 // TODO(donnadionne): Remove once outlier detection is no longer experimental
bool XdsOutlierDetectionEnabled() { bool XdsOutlierDetectionEnabled() {
auto value = GetEnv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION"); char* value = gpr_getenv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION");
if (!value.has_value()) return false;
bool parsed_value; 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; return parse_succeeded && parsed_value;
} }

@ -42,8 +42,9 @@
#include "src/core/ext/xds/xds_client_grpc.h" #include "src/core/ext/xds/xds_client_grpc.h"
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.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/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/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/time.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 // they may be talking to a completely different xDS server than we
// want to. // want to.
// TODO(roth): When we implement xDS federation, remove this constraint. // TODO(roth): When we implement xDS federation, remove this constraint.
GetEnv("GRPC_XDS_BOOTSTRAP").has_value() || UniquePtr<char>(gpr_getenv("GRPC_XDS_BOOTSTRAP")) != nullptr ||
GetEnv("GRPC_XDS_BOOTSTRAP_CONFIG").has_value()) { UniquePtr<char>(gpr_getenv("GRPC_XDS_BOOTSTRAP_CONFIG")) != nullptr) {
using_dns_ = true; using_dns_ = true;
child_resolver_ = child_resolver_ =
CoreConfiguration::Get().resolver_registry().CreateResolver( CoreConfiguration::Get().resolver_registry().CreateResolver(
@ -372,11 +373,11 @@ void GoogleCloud2ProdResolver::StartXdsResolver() {
}; };
} }
// Allow the TD server uri to be overridden for testing purposes. // Allow the TD server uri to be overridden for testing purposes.
auto override_server = UniquePtr<char> override_server(
GetEnv("GRPC_TEST_ONLY_GOOGLE_C2P_RESOLVER_TRAFFIC_DIRECTOR_URI"); gpr_getenv("GRPC_TEST_ONLY_GOOGLE_C2P_RESOLVER_TRAFFIC_DIRECTOR_URI"));
const char* server_uri = const char* server_uri =
override_server.has_value() && !override_server->empty() override_server != nullptr && strlen(override_server.get()) > 0
? override_server->c_str() ? override_server.get()
: "directpath-pa.googleapis.com"; : "directpath-pa.googleapis.com";
Json xds_server = Json::Array{ Json xds_server = Json::Array{
Json::Object{ Json::Object{

@ -18,20 +18,20 @@
#include "src/core/ext/xds/xds_bootstrap.h" #include "src/core/ext/xds/xds_bootstrap.h"
#include "absl/types/optional.h" #include <grpc/support/alloc.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/env.h"
namespace grpc_core { namespace grpc_core {
// TODO(donnadionne): check to see if federation is enabled, this will be // TODO(donnadionne): check to see if federation is enabled, this will be
// removed once federation is fully integrated and enabled by default. // removed once federation is fully integrated and enabled by default.
bool XdsFederationEnabled() { bool XdsFederationEnabled() {
auto value = GetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); char* value = gpr_getenv("GRPC_EXPERIMENTAL_XDS_FEDERATION");
if (!value.has_value()) return false;
bool parsed_value; 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; return parse_succeeded && parsed_value;
} }

@ -43,8 +43,9 @@
#include "src/core/ext/xds/xds_transport_grpc.h" #include "src/core/ext/xds/xds_transport_grpc.h"
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/debug/trace.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/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/orphanable.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/sync.h"
@ -92,31 +93,31 @@ namespace {
absl::StatusOr<std::string> GetBootstrapContents(const char* fallback_config) { absl::StatusOr<std::string> GetBootstrapContents(const char* fallback_config) {
// First, try GRPC_XDS_BOOTSTRAP env var. // First, try GRPC_XDS_BOOTSTRAP env var.
auto path = GetEnv("GRPC_XDS_BOOTSTRAP"); UniquePtr<char> path(gpr_getenv("GRPC_XDS_BOOTSTRAP"));
if (path.has_value()) { if (path != nullptr) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) { if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"Got bootstrap file location from GRPC_XDS_BOOTSTRAP " "Got bootstrap file location from GRPC_XDS_BOOTSTRAP "
"environment variable: %s", "environment variable: %s",
path->c_str()); path.get());
} }
grpc_slice contents; grpc_slice contents;
grpc_error_handle error = 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); if (!GRPC_ERROR_IS_NONE(error)) return grpc_error_to_absl_status(error);
std::string contents_str(StringViewFromSlice(contents)); std::string contents_str(StringViewFromSlice(contents));
grpc_slice_unref_internal(contents); grpc_slice_unref_internal(contents);
return contents_str; return contents_str;
} }
// Next, try GRPC_XDS_BOOTSTRAP_CONFIG env var. // Next, try GRPC_XDS_BOOTSTRAP_CONFIG env var.
auto env_config = GetEnv("GRPC_XDS_BOOTSTRAP_CONFIG"); UniquePtr<char> env_config(gpr_getenv("GRPC_XDS_BOOTSTRAP_CONFIG"));
if (env_config.has_value()) { if (env_config != nullptr) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) { if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"Got bootstrap contents from GRPC_XDS_BOOTSTRAP_CONFIG " "Got bootstrap contents from GRPC_XDS_BOOTSTRAP_CONFIG "
"environment variable"); "environment variable");
} }
return std::move(*env_config); return env_config.get();
} }
// Finally, try fallback config. // Finally, try fallback config.
if (fallback_config != nullptr) { if (fallback_config != nullptr) {

@ -55,6 +55,7 @@
#include "upb/upb.h" #include "upb/upb.h"
#include <grpc/status.h> #include <grpc/status.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/ext/xds/upb_utils.h" #include "src/core/ext/xds/upb_utils.h"
@ -67,8 +68,8 @@
#include "src/core/ext/xds/xds_routing.h" #include "src/core/ext/xds/xds_routing.h"
#include "src/core/lib/channel/status_util.h" #include "src/core/lib/channel/status_util.h"
#include "src/core/lib/debug/trace.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/gpr/string.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gprpp/match.h" #include "src/core/lib/gprpp/match.h"
#include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/error.h"
@ -78,19 +79,19 @@ namespace grpc_core {
// TODO(yashykt): Remove once RBAC is no longer experimental // TODO(yashykt): Remove once RBAC is no longer experimental
bool XdsRbacEnabled() { bool XdsRbacEnabled() {
auto value = GetEnv("GRPC_XDS_EXPERIMENTAL_RBAC"); char* value = gpr_getenv("GRPC_XDS_EXPERIMENTAL_RBAC");
if (!value.has_value()) return false;
bool parsed_value; 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; return parse_succeeded && parsed_value;
} }
// TODO(donnadionne): Remove once RLS is no longer experimental // TODO(donnadionne): Remove once RLS is no longer experimental
bool XdsRlsEnabled() { bool XdsRlsEnabled() {
auto value = GetEnv("GRPC_EXPERIMENTAL_XDS_RLS_LB"); char* value = gpr_getenv("GRPC_EXPERIMENTAL_XDS_RLS_LB");
if (!value.has_value()) return false;
bool parsed_value; 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; return parse_succeeded && parsed_value;
} }

@ -16,38 +16,25 @@
* *
*/ */
#ifndef GRPC_CORE_LIB_GPRPP_ENV_H #ifndef GRPC_CORE_LIB_GPR_ENV_H
#define GRPC_CORE_LIB_GPRPP_ENV_H #define GRPC_CORE_LIB_GPR_ENV_H
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
#include <string> #include <stdio.h>
#include "absl/types/optional.h" /* Env utility functions */
namespace grpc_core { /* Gets the environment variable value with the specified name.
Returns a newly allocated string. It is the responsibility of the caller to
// Gets the environment variable value with the specified name. */ gpr_free the return value if not NULL (which means that the environment
absl::optional<std::string> GetEnv(const char* name); variable exists). */
char* gpr_getenv(const char* name);
/* Sets the environment with the specified name to the specified value. */ /* Sets the environment with the specified name to the specified value. */
void SetEnv(const char* name, const char* value); void gpr_setenv(const char* name, const char* value);
inline void SetEnv(const char* name, const std::string& value) {
SetEnv(name, value.c_str());
}
/* Deletes the variable name from the environment. */ /* Deletes the variable name from the environment. */
void UnsetEnv(const char* name); void gpr_unsetenv(const char* name);
template <typename T>
void SetOrUnsetEnv(const char* name, const absl::optional<T>& value) {
if (value.has_value()) {
SetEnv(name, value.value());
} else {
UnsetEnv(name);
}
}
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPRPP_ENV_H */ #endif /* GRPC_CORE_LIB_GPR_ENV_H */

@ -23,24 +23,21 @@
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
#include <string>
#include "absl/types/optional.h"
#ifdef GPR_LINUX_ENV #ifdef GPR_LINUX_ENV
#if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
#include <dlfcn.h> #include <dlfcn.h>
#endif
#include <features.h> #include <features.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "src/core/lib/gprpp/env.h" #include <grpc/support/log.h>
#include <grpc/support/string_util.h>
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<std::string> GetEnv(const char* name) { char* gpr_getenv(const char* name) {
char* result = nullptr; char* result = nullptr;
#if defined(GPR_BACKWARDS_COMPATIBILITY_MODE) #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
typedef char* (*getenv_type)(const char*); typedef char* (*getenv_type)(const char*);
@ -48,8 +45,9 @@ absl::optional<std::string> GetEnv(const char* name) {
/* Check to see which getenv variant is supported (go from most /* Check to see which getenv variant is supported (go from most
* to least secure) */ * to least secure) */
if (getenv_func == nullptr) { if (getenv_func == nullptr) {
for (auto name : {"secure_getenv", "__secure_getenv", "getenv"}) { const char* names[] = {"secure_getenv", "__secure_getenv", "getenv"};
getenv_func = reinterpret_cast<getenv_type>(dlsym(RTLD_DEFAULT, name)); for (size_t i = 0; i < GPR_ARRAY_SIZE(names); i++) {
getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]);
if (getenv_func != nullptr) { if (getenv_func != nullptr) {
break; break;
} }
@ -61,20 +59,17 @@ absl::optional<std::string> GetEnv(const char* name) {
#else #else
result = getenv(name); result = getenv(name);
#endif #endif
if (result == nullptr) return absl::nullopt; return result == nullptr ? result : gpr_strdup(result);
return result;
} }
void SetEnv(const char* name, const char* value) { void gpr_setenv(const char* name, const char* value) {
int res = setenv(name, value, 1); 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); int res = unsetenv(name);
if (res != 0) abort(); GPR_ASSERT(res == 0);
} }
} // namespace grpc_core
#endif /* GPR_LINUX_ENV */ #endif /* GPR_LINUX_ENV */

@ -22,26 +22,25 @@
#include <stdlib.h> #include <stdlib.h>
#include "src/core/lib/gprpp/env.h" #include <grpc/support/log.h>
#include <grpc/support/string_util.h>
namespace grpc_core { #include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h"
absl::optional<std::string> GetEnv(const char* name) { char* gpr_getenv(const char* name) {
char* result = getenv(name); char* result = getenv(name);
if (result == nullptr) return absl::nullopt; return result == nullptr ? result : gpr_strdup(result);
return result;
} }
void SetEnv(const char* name, const char* value) { void gpr_setenv(const char* name, const char* value) {
int res = setenv(name, value, 1); 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); int res = unsetenv(name);
if (res != 0) abort(); GPR_ASSERT(res == 0);
} }
} // namespace grpc_core
#endif /* GPR_POSIX_ENV */ #endif /* GPR_POSIX_ENV */

@ -24,33 +24,37 @@
#include <memory> #include <memory>
#include "src/core/lib/gprpp/env.h" #include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/tchar.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<std::string> GetEnv(const char* name) { ret = GetEnvironmentVariable(tname.c_str(), NULL, 0);
auto tname = CharToTchar(name); if (ret == 0) return NULL;
DWORD ret = GetEnvironmentVariable(tname.c_str(), NULL, 0);
if (ret == 0) return absl::nullopt;
std::unique_ptr<TCHAR[]> tresult(new TCHAR[ret]); std::unique_ptr<TCHAR[]> tresult(new TCHAR[ret]);
ret = ret =
GetEnvironmentVariable(tname.c_str(), tresult.get(), ret * sizeof(TCHAR)); GetEnvironmentVariable(tname.c_str(), tresult.get(), ret * sizeof(TCHAR));
if (ret == 0) return absl::nullopt; if (ret == 0) return NULL;
return TcharToChar(tresult.get()); return gpr_strdup(grpc_core::TcharToChar(tresult.get()).c_str());
} }
void SetEnv(const char* name, const char* value) { void gpr_setenv(const char* name, const char* value) {
BOOL res = SetEnvironmentVariable(CharToTchar(name).c_str(), BOOL res = SetEnvironmentVariable(grpc_core::CharToTchar(name).c_str(),
CharToTchar(value).c_str()); grpc_core::CharToTchar(value).c_str());
if (!res) abort(); GPR_ASSERT(res);
} }
void UnsetEnv(const char* name) { void gpr_unsetenv(const char* name) {
BOOL res = SetEnvironmentVariable(CharToTchar(name).c_str(), NULL); BOOL res = SetEnvironmentVariable(grpc_core::CharToTchar(name).c_str(), NULL);
if (!res) abort(); GPR_ASSERT(res);
} }
} // namespace grpc_core
#endif /* GPR_WINDOWS_ENV */ #endif /* GPR_WINDOWS_ENV */

@ -28,13 +28,12 @@
#include <type_traits> #include <type_traits>
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "absl/types/optional.h"
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/env.h"
namespace grpc_core { namespace grpc_core {
@ -61,14 +60,14 @@ void SetGlobalConfigEnvErrorFunction(GlobalConfigEnvErrorFunctionType func) {
} }
UniquePtr<char> GlobalConfigEnv::GetValue() { UniquePtr<char> GlobalConfigEnv::GetValue() {
auto env = GetEnv(GetName()); return UniquePtr<char>(gpr_getenv(GetName()));
return UniquePtr<char>(env.has_value() ? gpr_strdup(env.value().c_str())
: nullptr);
} }
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() { char* GlobalConfigEnv::GetName() {
// This makes sure that name_ is in a canonical form having uppercase // This makes sure that name_ is in a canonical form having uppercase

@ -29,7 +29,6 @@
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "absl/strings/str_replace.h" #include "absl/strings/str_replace.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc/grpc_security.h> #include <grpc/grpc_security.h>
@ -37,7 +36,8 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#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/http/httpcli_ssl_credentials.h"
#include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/json/json.h" #include "src/core/lib/json/json.h"
@ -237,12 +237,12 @@ void AwsExternalAccountCredentials::AddMetadataRequestHeaders(
} }
void AwsExternalAccountCredentials::RetrieveRegion() { void AwsExternalAccountCredentials::RetrieveRegion() {
auto region_from_env = GetEnv(kRegionEnvVar); UniquePtr<char> region_from_env(gpr_getenv(kRegionEnvVar));
if (!region_from_env.has_value()) { if (region_from_env == nullptr) {
region_from_env = GetEnv(kDefaultRegionEnvVar); region_from_env = UniquePtr<char>(gpr_getenv(kDefaultRegionEnvVar));
} }
if (region_from_env.has_value()) { if (region_from_env != nullptr) {
region_ = std::move(*region_from_env); region_ = std::string(region_from_env.get());
if (url_.empty()) { if (url_.empty()) {
RetrieveSigningKeys(); RetrieveSigningKeys();
} else { } else {
@ -350,14 +350,15 @@ void AwsExternalAccountCredentials::OnRetrieveRoleNameInternal(
} }
void AwsExternalAccountCredentials::RetrieveSigningKeys() { void AwsExternalAccountCredentials::RetrieveSigningKeys() {
auto access_key_id_from_env = GetEnv(kAccessKeyIdEnvVar); UniquePtr<char> access_key_id_from_env(gpr_getenv(kAccessKeyIdEnvVar));
auto secret_access_key_from_env = GetEnv(kSecretAccessKeyEnvVar); UniquePtr<char> secret_access_key_from_env(
auto token_from_env = GetEnv(kSessionTokenEnvVar); gpr_getenv(kSecretAccessKeyEnvVar));
if (access_key_id_from_env.has_value() && UniquePtr<char> token_from_env(gpr_getenv(kSessionTokenEnvVar));
secret_access_key_from_env.has_value() && token_from_env.has_value()) { if (access_key_id_from_env != nullptr &&
access_key_id_ = std::move(*access_key_id_from_env); secret_access_key_from_env != nullptr && token_from_env != nullptr) {
secret_access_key_ = std::move(*secret_access_key_from_env); access_key_id_ = std::string(access_key_id_from_env.get());
token_ = std::move(*token_from_env); secret_access_key_ = std::string(secret_access_key_from_env.get());
token_ = std::string(token_from_env.get());
BuildSubjectToken(); BuildSubjectToken();
return; return;
} }

@ -21,20 +21,23 @@
#include <string> #include <string>
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/types/optional.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#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/credentials.h"
#include "src/core/lib/security/credentials/google_default/google_default_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) { std::string grpc_get_well_known_google_credentials_file_path_impl(void) {
auto base = grpc_core::GetEnv(GRPC_GOOGLE_CREDENTIALS_PATH_ENV_VAR); char* base = gpr_getenv(GRPC_GOOGLE_CREDENTIALS_PATH_ENV_VAR);
if (!base.has_value()) { if (base == nullptr) {
gpr_log(GPR_ERROR, "Could not get " GRPC_GOOGLE_CREDENTIALS_PATH_ENV_VAR gpr_log(GPR_ERROR, "Could not get " GRPC_GOOGLE_CREDENTIALS_PATH_ENV_VAR
" environment variable."); " environment variable.");
return ""; 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;
} }

@ -44,7 +44,7 @@
#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h" #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/channel/channel_args.h"
#include "src/core/lib/debug/trace.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/host_port.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/sync.h"
@ -399,9 +399,10 @@ static grpc_core::RefCountedPtr<grpc_call_credentials> make_default_call_creds(
grpc_error_handle err; grpc_error_handle err;
/* First, try the environment variable. */ /* First, try the environment variable. */
auto path_from_env = grpc_core::GetEnv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR); char* path_from_env = gpr_getenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR);
if (path_from_env.has_value()) { if (path_from_env != nullptr) {
err = create_default_creds_from_path(*path_from_env, &call_creds); 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; if (GRPC_ERROR_IS_NONE(err)) return call_creds;
*error = grpc_error_add_child(*error, err); *error = grpc_error_add_child(*error, err);
} }

@ -27,11 +27,11 @@
#include "absl/status/status.h" #include "absl/status/status.h"
#include "absl/status/statusor.h" #include "absl/status/statusor.h"
#include "absl/strings/str_join.h" #include "absl/strings/str_join.h"
#include "absl/types/optional.h"
#include <grpc/grpc_security_constants.h> #include <grpc/grpc_security_constants.h>
#include <grpc/impl/codegen/gpr_types.h> #include <grpc/impl/codegen/gpr_types.h>
#include <grpc/slice.h> #include <grpc/slice.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include <grpc/support/time.h> #include <grpc/support/time.h>
@ -42,7 +42,7 @@
#include <grpcpp/support/slice.h> #include <grpcpp/support/slice.h>
#include <grpcpp/support/status.h> #include <grpcpp/support/status.h>
#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/closure.h"
#include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/executor.h"
@ -224,22 +224,23 @@ grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options) {
} }
ClearStsCredentialsOptions(options); ClearStsCredentialsOptions(options);
grpc_slice json_string = grpc_empty_slice(); 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_error_handle error = GRPC_ERROR_NONE;
grpc::Status status; grpc::Status status;
// NOLINTNEXTLINE(clang-diagnostic-unused-lambda-capture) // 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); grpc_slice_unref_internal(json_string);
gpr_free(sts_creds_path);
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
return status; return status;
}; };
if (!sts_creds_path.has_value()) { if (sts_creds_path == nullptr) {
status = grpc::Status(grpc::StatusCode::NOT_FOUND, status = grpc::Status(grpc::StatusCode::NOT_FOUND,
"STS_CREDENTIALS environment variable not set."); "STS_CREDENTIALS environment variable not set.");
return cleanup(); 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)) { if (!GRPC_ERROR_IS_NONE(error)) {
status = status =
grpc::Status(grpc::StatusCode::NOT_FOUND, grpc_error_std_string(error)); grpc::Status(grpc::StatusCode::NOT_FOUND, grpc_error_std_string(error));

@ -67,12 +67,10 @@ grpc_cc_library(
"absl/status", "absl/status",
"absl/status:statusor", "absl/status:statusor",
"absl/strings", "absl/strings",
"absl/types:optional",
], ],
language = "c++", language = "c++",
visibility = ["//test:__subpackages__"], visibility = ["//test:__subpackages__"],
deps = [ deps = [
"//:env",
"//:gpr", "//:gpr",
"//:grpc_base", "//:grpc_base",
"//:grpc_public_hdrs", "//:grpc_public_hdrs",

@ -18,16 +18,16 @@
#include "src/cpp/ext/gcp/observability_config.h" #include "src/cpp/ext/gcp/observability_config.h"
#include <utility> #include <memory>
#include "absl/status/status.h" #include "absl/status/status.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include <grpc/slice.h> #include <grpc/slice.h>
#include <grpc/status.h> #include <grpc/status.h>
#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/error.h"
#include "src/core/lib/iomgr/load_file.h" #include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/json/json.h" #include "src/core/lib/json/json.h"
@ -46,23 +46,24 @@ namespace {
absl::StatusOr<std::string> GetGcpObservabilityConfigContents() { absl::StatusOr<std::string> GetGcpObservabilityConfigContents() {
// First, try GRPC_OBSERVABILITY_CONFIG_FILE // First, try GRPC_OBSERVABILITY_CONFIG_FILE
std::string contents_str; std::string contents_str;
auto path = grpc_core::GetEnv("GRPC_OBSERVABILITY_CONFIG_FILE"); grpc_core::UniquePtr<char> path(gpr_getenv("GRPC_OBSERVABILITY_CONFIG_FILE"));
if (path.has_value()) { if (path != nullptr) {
grpc_slice contents; grpc_slice contents;
grpc_error_handle error = 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)) { if (!GRPC_ERROR_IS_NONE(error)) {
return grpc_error_to_absl_status(grpc_error_set_int( return grpc_error_to_absl_status(grpc_error_set_int(
error, GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_FAILED_PRECONDITION)); error, GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_FAILED_PRECONDITION));
} }
std::string contents_str(grpc_core::StringViewFromSlice(contents)); std::string contents_str(grpc_core::StringViewFromSlice(contents));
grpc_slice_unref_internal(contents); grpc_slice_unref_internal(contents);
return std::move(contents_str); return contents_str;
} }
// Next, try GRPC_OBSERVABILITY_CONFIG env var. // Next, try GRPC_OBSERVABILITY_CONFIG env var.
auto env_config = grpc_core::GetEnv("GRPC_OBSERVABILITY_CONFIG"); grpc_core::UniquePtr<char> env_config(
if (env_config.has_value()) { gpr_getenv("GRPC_OBSERVABILITY_CONFIG"));
return std::move(*env_config); if (env_config != nullptr) {
return env_config.get();
} }
// No observability config found. // No observability config found.
return absl::FailedPreconditionError( return absl::FailedPreconditionError(

@ -32,9 +32,9 @@
#import <grpc/support/log.h> #import <grpc/support/log.h>
#import "src/core/lib/channel/channel_args.h" #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/string.h"
#import "src/core/lib/gpr/tmpfile.h" #import "src/core/lib/gpr/tmpfile.h"
#import "src/core/lib/gprpp/env.h"
#import "src/core/lib/gprpp/host_port.h" #import "src/core/lib/gprpp/host_port.h"
#import "test/core/end2end/data/ssl_test_data.h" #import "test/core/end2end/data/ssl_test_data.h"
#import "test/core/util/test_config.h" #import "test/core/util/test_config.h"

@ -471,6 +471,9 @@ CORE_SOURCE_FILES = [
'src/core/lib/gpr/cpu_linux.cc', 'src/core/lib/gpr/cpu_linux.cc',
'src/core/lib/gpr/cpu_posix.cc', 'src/core/lib/gpr/cpu_posix.cc',
'src/core/lib/gpr/cpu_windows.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.cc',
'src/core/lib/gpr/log_android.cc', 'src/core/lib/gpr/log_android.cc',
'src/core/lib/gpr/log_linux.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_posix.cc',
'src/core/lib/gpr/tmpfile_windows.cc', 'src/core/lib/gpr/tmpfile_windows.cc',
'src/core/lib/gpr/wrap_memcpy.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/examine_stack.cc',
'src/core/lib/gprpp/fork.cc', 'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/global_config_env.cc', 'src/core/lib/gprpp/global_config_env.cc',

@ -20,7 +20,7 @@
#include "src/core/ext/filters/client_channel/http_proxy.h" #include "src/core/ext/filters/client_channel/http_proxy.h"
#include "src/core/lib/channel/channel_args.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 "src/core/lib/transport/http_connect_handshaker.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
@ -30,10 +30,10 @@ namespace {
class ScopedSetEnv { class ScopedSetEnv {
public: 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(const ScopedSetEnv&) = delete;
ScopedSetEnv& operator=(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. // Test that an empty no_proxy works as expected, i.e., proxy is used.

@ -37,7 +37,7 @@
#include <grpcpp/server.h> #include <grpcpp/server.h>
#include <grpcpp/server_builder.h> #include <grpcpp/server_builder.h>
#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gpr/env.h"
#include "src/core/lib/gprpp/thd.h" #include "src/core/lib/gprpp/thd.h"
#include "test/core/util/fake_udp_and_tcp_server.h" #include "test/core/util/fake_udp_and_tcp_server.h"
#include "test/core/util/port.h" #include "test/core/util/port.h"
@ -105,7 +105,7 @@ TEST(DestroyGoogleC2pChannelWithActiveConnectStressTest,
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, 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); ::testing::InitGoogleTest(&argc, argv);
grpc_init(); grpc_init();
auto result = RUN_ALL_TESTS(); auto result = RUN_ALL_TESTS();

@ -19,7 +19,7 @@
#include <grpc/grpc.h> #include <grpc/grpc.h>
#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 "src/core/lib/service_config/service_config_impl.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"

@ -27,7 +27,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.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/host_port.h"
#include "test/core/end2end/end2end_tests.h" #include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/http_proxy_fixture.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, absl::StrFormat("http://%s@%s", proxy_auth_str,
grpc_end2end_http_proxy_get_proxy_name(ffd->proxy)); 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(); grpc_channel_credentials* creds = grpc_insecure_credentials_create();
f->client = grpc_channel_create(ffd->server_addr.c_str(), creds, client_args); f->client = grpc_channel_create(ffd->server_addr.c_str(), creds, client_args);
grpc_channel_credentials_release(creds); grpc_channel_credentials_release(creds);

@ -53,8 +53,8 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channelz.h" #include "src/core/lib/channel/channelz.h"
#include "src/core/lib/event_engine/default_event_engine.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/debug_location.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/endpoint.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) { DEFINE_PROTO_FUZZER(const api_fuzzer::Msg& msg) {
grpc_event_engine::experimental::ResetDefaultEventEngine(); grpc_event_engine::experimental::ResetDefaultEventEngine();
grpc_test_only_set_slice_hash_seed(0); grpc_test_only_set_slice_hash_seed(0);
if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) { char* grpc_trace_fuzzer = gpr_getenv("GRPC_TRACE_FUZZER");
gpr_set_log_function(dont_log); 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_set_tcp_client_impl(&fuzz_tcp_client_vtable);
grpc_event_engine::experimental::SetDefaultEventEngineFactory( grpc_event_engine::experimental::SetDefaultEventEngineFactory(
[actions = msg.event_engine_actions()]() { [actions = msg.event_engine_actions()]() {

@ -22,7 +22,7 @@
#include "src/core/ext/filters/http/server/http_server_filter.h" #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_args.h"
#include "src/core/lib/channel/channel_stack_builder_impl.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/executor.h"
#include "src/core/lib/iomgr/timer_manager.h" #include "src/core/lib/iomgr/timer_manager.h"
#include "src/core/lib/resource_quota/resource_quota.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); grpc_test_only_set_slice_hash_seed(0);
if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) { char* grpc_trace_fuzzer = gpr_getenv("GRPC_TRACE_FUZZER");
gpr_set_log_function(dont_log); if (squelch && grpc_trace_fuzzer == nullptr) gpr_set_log_function(dont_log);
} gpr_free(grpc_trace_fuzzer);
g_now = {1, 0, GPR_CLOCK_MONOTONIC}; g_now = {1, 0, GPR_CLOCK_MONOTONIC};
grpc_core::TestOnlySetProcessEpoch(g_now); grpc_core::TestOnlySetProcessEpoch(g_now);
gpr_now_impl = now_impl; gpr_now_impl = now_impl;

@ -16,7 +16,7 @@
* *
*/ */
#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gpr/env.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -34,24 +34,28 @@
TEST(EnvTest, SetenvGetenv) { TEST(EnvTest, SetenvGetenv) {
const char* name = "FOO"; const char* name = "FOO";
const char* value = "BAR"; const char* value = "BAR";
char* retrieved_value;
LOG_TEST_NAME("test_setenv_getenv"); LOG_TEST_NAME("test_setenv_getenv");
grpc_core::SetEnv(name, value); gpr_setenv(name, value);
auto retrieved_value = grpc_core::GetEnv(name); retrieved_value = gpr_getenv(name);
ASSERT_EQ(value, retrieved_value); ASSERT_NE(retrieved_value, nullptr);
ASSERT_STREQ(value, retrieved_value);
gpr_free(retrieved_value);
} }
TEST(EnvTest, Unsetenv) { TEST(EnvTest, Unsetenv) {
const char* name = "FOO"; const char* name = "FOO";
const char* value = "BAR"; const char* value = "BAR";
char* retrieved_value;
LOG_TEST_NAME("test_unsetenv"); LOG_TEST_NAME("test_unsetenv");
grpc_core::SetEnv(name, value); gpr_setenv(name, value);
grpc_core::UnsetEnv(name); gpr_unsetenv(name);
auto retrieved_value = grpc_core::GetEnv(name); retrieved_value = gpr_getenv(name);
ASSERT_FALSE(retrieved_value.has_value()); ASSERT_EQ(retrieved_value, nullptr);
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {

@ -26,7 +26,7 @@
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#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/gprpp/memory.h"
namespace { namespace {
@ -59,23 +59,23 @@ GPR_GLOBAL_CONFIG_DEFINE_STRING(string_var, "Apple", "");
TEST_F(GlobalConfigEnvTest, BoolWithEnvTest) { TEST_F(GlobalConfigEnvTest, BoolWithEnvTest) {
const char* bool_var_name = "BOOL_VAR"; 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)); 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)); 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(GPR_GLOBAL_CONFIG_GET(bool_var));
EXPECT_FALSE(IsConfigErrorCalled()); EXPECT_FALSE(IsConfigErrorCalled());
grpc_core::SetEnv(bool_var_name, ""); gpr_setenv(bool_var_name, "");
GPR_GLOBAL_CONFIG_GET(bool_var); GPR_GLOBAL_CONFIG_GET(bool_var);
EXPECT_TRUE(IsConfigErrorCalled()); EXPECT_TRUE(IsConfigErrorCalled());
ClearConfigErrorCalled(); ClearConfigErrorCalled();
grpc_core::SetEnv(bool_var_name, "!"); gpr_setenv(bool_var_name, "!");
GPR_GLOBAL_CONFIG_GET(bool_var); GPR_GLOBAL_CONFIG_GET(bool_var);
EXPECT_TRUE(IsConfigErrorCalled()); EXPECT_TRUE(IsConfigErrorCalled());
ClearConfigErrorCalled(); ClearConfigErrorCalled();
@ -84,21 +84,21 @@ TEST_F(GlobalConfigEnvTest, BoolWithEnvTest) {
TEST_F(GlobalConfigEnvTest, Int32WithEnvTest) { TEST_F(GlobalConfigEnvTest, Int32WithEnvTest) {
const char* int32_var_name = "INT32_VAR"; 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)); 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)); 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)); 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_EQ(123456789, GPR_GLOBAL_CONFIG_GET(int32_var));
EXPECT_FALSE(IsConfigErrorCalled()); EXPECT_FALSE(IsConfigErrorCalled());
grpc_core::SetEnv(int32_var_name, "-1AB"); gpr_setenv(int32_var_name, "-1AB");
GPR_GLOBAL_CONFIG_GET(int32_var); GPR_GLOBAL_CONFIG_GET(int32_var);
EXPECT_TRUE(IsConfigErrorCalled()); EXPECT_TRUE(IsConfigErrorCalled());
ClearConfigErrorCalled(); ClearConfigErrorCalled();
@ -108,15 +108,15 @@ TEST_F(GlobalConfigEnvTest, StringWithEnvTest) {
const char* string_var_name = "STRING_VAR"; const char* string_var_name = "STRING_VAR";
grpc_core::UniquePtr<char> value; grpc_core::UniquePtr<char> value;
grpc_core::UnsetEnv(string_var_name); gpr_unsetenv(string_var_name);
value = GPR_GLOBAL_CONFIG_GET(string_var); value = GPR_GLOBAL_CONFIG_GET(string_var);
EXPECT_EQ(0, strcmp(value.get(), "Apple")); 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); value = GPR_GLOBAL_CONFIG_GET(string_var);
EXPECT_EQ(0, strcmp(value.get(), "Banana")); 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); value = GPR_GLOBAL_CONFIG_GET(string_var);
EXPECT_EQ(0, strcmp(value.get(), "")); EXPECT_EQ(0, strcmp(value.get(), ""));
} }

@ -26,7 +26,7 @@
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#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/gprpp/memory.h"
GPR_GLOBAL_CONFIG_DECLARE_BOOL(bool_var); GPR_GLOBAL_CONFIG_DECLARE_BOOL(bool_var);

@ -30,7 +30,7 @@
#include <grpc/support/sync.h> #include <grpc/support/sync.h>
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h" #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.h"
#include "src/core/lib/gprpp/time_util.h" #include "src/core/lib/gprpp/time_util.h"
#include "src/core/lib/http/httpcli.h" #include "src/core/lib/http/httpcli.h"

@ -35,9 +35,9 @@
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h" #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/string.h"
#include "src/core/lib/gpr/useful.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/thd.h"
#include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/executor.h"

@ -24,7 +24,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#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/alts_credentials.h"
#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" #include "src/core/lib/security/credentials/alts/check_gcp_environment.h"
#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.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) { 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_set_log_function(dont_log);
} }
gpr_free(grpc_trace_fuzzer);
input_stream inp = {data, data + size}; input_stream inp = {data, data + size};
grpc_init(); grpc_init();
bool is_on_gcp = grpc_alts_is_running_on_gcp(); bool is_on_gcp = grpc_alts_is_running_on_gcp();

@ -41,9 +41,9 @@
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h" #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/string.h"
#include "src/core/lib/gpr/tmpfile.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/host_port.h"
#include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/time.h"
#include "src/core/lib/gprpp/unique_type_name.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(creds_file != nullptr);
GPR_ASSERT(fwrite(contents, 1, contents_len, creds_file) == contents_len); GPR_ASSERT(fwrite(contents, 1, contents_len, creds_file) == contents_len);
fclose(creds_file); 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); gpr_free(creds_file_name);
} }
@ -1551,7 +1551,7 @@ TEST(CredentialsTest, TestGoogleDefaultCredsAuthKey) {
0); 0);
GPR_ASSERT(g_test_gce_tenancy_checker_called == false); GPR_ASSERT(g_test_gce_tenancy_checker_called == false);
creds->Unref(); 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); grpc_override_well_known_credentials_path_getter(nullptr);
} }
@ -1575,7 +1575,7 @@ TEST(CredentialsTest, TestGoogleDefaultCredsRefreshToken) {
GPR_ASSERT(strcmp(refresh->refresh_token().client_id, GPR_ASSERT(strcmp(refresh->refresh_token().client_id,
"32555999999.apps.googleusercontent.com") == 0); "32555999999.apps.googleusercontent.com") == 0);
creds->Unref(); 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); grpc_override_well_known_credentials_path_getter(nullptr);
} }
@ -1598,7 +1598,7 @@ TEST(CredentialsTest, TestGoogleDefaultCredsExternalAccountCredentials) {
reinterpret_cast<const ExternalAccountCredentials*>(creds->call_creds()); reinterpret_cast<const ExternalAccountCredentials*>(creds->call_creds());
GPR_ASSERT(external != nullptr); GPR_ASSERT(external != nullptr);
creds->Unref(); 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); grpc_override_well_known_credentials_path_getter(nullptr);
} }
@ -1622,7 +1622,7 @@ TEST(CredentialsTest,
reinterpret_cast<const ExternalAccountCredentials*>(creds->call_creds()); reinterpret_cast<const ExternalAccountCredentials*>(creds->call_creds());
GPR_ASSERT(external != nullptr); GPR_ASSERT(external != nullptr);
creds->Unref(); 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); grpc_override_well_known_credentials_path_getter(nullptr);
} }
@ -1646,7 +1646,7 @@ TEST(CredentialsTest,
reinterpret_cast<const ExternalAccountCredentials*>(creds->call_creds()); reinterpret_cast<const ExternalAccountCredentials*>(creds->call_creds());
GPR_ASSERT(external != nullptr); GPR_ASSERT(external != nullptr);
creds->Unref(); 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); grpc_override_well_known_credentials_path_getter(nullptr);
} }
@ -1673,7 +1673,7 @@ TEST(CredentialsTest, TestGoogleDefaultCredsGce) {
GRPC_ERROR_NONE, GRPC_ERROR_NONE,
"authorization: Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"); "authorization: Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_");
grpc_flush_cached_google_default_credentials(); 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( grpc_override_well_known_credentials_path_getter(
null_well_known_creds_path_getter); null_well_known_creds_path_getter);
set_gce_tenancy_checker_for_testing(test_gce_tenancy_checker); set_gce_tenancy_checker_for_testing(test_gce_tenancy_checker);
@ -1709,7 +1709,7 @@ TEST(CredentialsTest, TestGoogleDefaultCredsNonGce) {
GRPC_ERROR_NONE, GRPC_ERROR_NONE,
"authorization: Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"); "authorization: Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_");
grpc_flush_cached_google_default_credentials(); 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( grpc_override_well_known_credentials_path_getter(
null_well_known_creds_path_getter); null_well_known_creds_path_getter);
set_gce_tenancy_checker_for_testing(test_gce_tenancy_checker); 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) { TEST(CredentialsTest, TestNoGoogleDefaultCreds) {
grpc_flush_cached_google_default_credentials(); 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( grpc_override_well_known_credentials_path_getter(
null_well_known_creds_path_getter); null_well_known_creds_path_getter);
set_gce_tenancy_checker_for_testing(test_gce_tenancy_checker); set_gce_tenancy_checker_for_testing(test_gce_tenancy_checker);
@ -1987,27 +1987,32 @@ TEST(CredentialsTest, TestMetadataPluginFailure) {
} }
TEST(CredentialsTest, TestGetWellKnownGoogleCredentialsFilePath) { TEST(CredentialsTest, TestGetWellKnownGoogleCredentialsFilePath) {
auto home = GetEnv("HOME"); char* home = gpr_getenv("HOME");
bool restore_home_env = false; bool restore_home_env = false;
#if defined(GRPC_BAZEL_BUILD) && \ #if defined(GRPC_BAZEL_BUILD) && \
(defined(GPR_POSIX_ENV) || defined(GPR_LINUX_ENV)) (defined(GPR_POSIX_ENV) || defined(GPR_LINUX_ENV))
// when running under bazel locally, the HOME variable is not set // when running under bazel locally, the HOME variable is not set
// so we set it to some fake value // so we set it to some fake value
restore_home_env = true; 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) || \ #endif /* defined(GRPC_BAZEL_BUILD) && (defined(GPR_POSIX_ENV) || \
defined(GPR_LINUX_ENV)) */ defined(GPR_LINUX_ENV)) */
std::string path = grpc_get_well_known_google_credentials_file_path(); std::string path = grpc_get_well_known_google_credentials_file_path();
GPR_ASSERT(!path.empty()); GPR_ASSERT(!path.empty());
#if defined(GPR_POSIX_ENV) || defined(GPR_LINUX_ENV) #if defined(GPR_POSIX_ENV) || defined(GPR_LINUX_ENV)
restore_home_env = true; restore_home_env = true;
UnsetEnv("HOME"); gpr_unsetenv("HOME");
path = grpc_get_well_known_google_credentials_file_path(); path = grpc_get_well_known_google_credentials_file_path();
GPR_ASSERT(path.empty()); GPR_ASSERT(path.empty());
#endif /* GPR_POSIX_ENV || GPR_LINUX_ENV */ #endif /* GPR_POSIX_ENV || GPR_LINUX_ENV */
if (restore_home_env) { if (restore_home_env) {
SetOrUnsetEnv("HOME", home); if (home) {
gpr_setenv("HOME", home);
} else {
gpr_unsetenv("HOME");
}
} }
gpr_free(home);
} }
TEST(CredentialsTest, TestChannelCredsDuplicateWithoutCallCreds) { TEST(CredentialsTest, TestChannelCredsDuplicateWithoutCallCreds) {
@ -2985,7 +2990,7 @@ TEST(CredentialsTest, TestAwsImdsv2ExternalAccountCredsSuccess) {
TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionEnvKeysUrl) { TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionEnvKeysUrl) {
ExecCtx exec_ctx; ExecCtx exec_ctx;
SetEnv("AWS_REGION", "test_regionz"); gpr_setenv("AWS_REGION", "test_regionz");
auto credential_source = auto credential_source =
Json::Parse(valid_aws_external_account_creds_options_credential_source); Json::Parse(valid_aws_external_account_creds_options_credential_source);
GPR_ASSERT(credential_source.ok()); GPR_ASSERT(credential_source.ok());
@ -3016,13 +3021,13 @@ TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionEnvKeysUrl) {
kTestPath); kTestPath);
ExecCtx::Get()->Flush(); ExecCtx::Get()->Flush();
HttpRequest::SetOverride(nullptr, nullptr, nullptr); HttpRequest::SetOverride(nullptr, nullptr, nullptr);
UnsetEnv("AWS_REGION"); gpr_unsetenv("AWS_REGION");
} }
TEST(CredentialsTest, TEST(CredentialsTest,
TestAwsExternalAccountCredsSuccessPathDefaultRegionEnvKeysUrl) { TestAwsExternalAccountCredsSuccessPathDefaultRegionEnvKeysUrl) {
ExecCtx exec_ctx; ExecCtx exec_ctx;
SetEnv("AWS_DEFAULT_REGION", "test_regionz"); gpr_setenv("AWS_DEFAULT_REGION", "test_regionz");
auto credential_source = auto credential_source =
Json::Parse(valid_aws_external_account_creds_options_credential_source); Json::Parse(valid_aws_external_account_creds_options_credential_source);
GPR_ASSERT(credential_source.ok()); GPR_ASSERT(credential_source.ok());
@ -3053,15 +3058,15 @@ TEST(CredentialsTest,
kTestPath); kTestPath);
ExecCtx::Get()->Flush(); ExecCtx::Get()->Flush();
HttpRequest::SetOverride(nullptr, nullptr, nullptr); HttpRequest::SetOverride(nullptr, nullptr, nullptr);
UnsetEnv("AWS_DEFAULT_REGION"); gpr_unsetenv("AWS_DEFAULT_REGION");
} }
TEST(CredentialsTest, TEST(CredentialsTest,
TestAwsExternalAccountCredsSuccessPathDuplicateRegionEnvKeysUrl) { TestAwsExternalAccountCredsSuccessPathDuplicateRegionEnvKeysUrl) {
ExecCtx exec_ctx; ExecCtx exec_ctx;
// Make sure that AWS_REGION gets used over AWS_DEFAULT_REGION // Make sure that AWS_REGION gets used over AWS_DEFAULT_REGION
SetEnv("AWS_REGION", "test_regionz"); gpr_setenv("AWS_REGION", "test_regionz");
SetEnv("AWS_DEFAULT_REGION", "ERROR_REGION"); gpr_setenv("AWS_DEFAULT_REGION", "ERROR_REGION");
auto credential_source = auto credential_source =
Json::Parse(valid_aws_external_account_creds_options_credential_source); Json::Parse(valid_aws_external_account_creds_options_credential_source);
GPR_ASSERT(credential_source.ok()); GPR_ASSERT(credential_source.ok());
@ -3092,15 +3097,15 @@ TEST(CredentialsTest,
kTestPath); kTestPath);
ExecCtx::Get()->Flush(); ExecCtx::Get()->Flush();
HttpRequest::SetOverride(nullptr, nullptr, nullptr); HttpRequest::SetOverride(nullptr, nullptr, nullptr);
UnsetEnv("AWS_REGION"); gpr_unsetenv("AWS_REGION");
UnsetEnv("AWS_DEFAULT_REGION"); gpr_unsetenv("AWS_DEFAULT_REGION");
} }
TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionUrlKeysEnv) { TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionUrlKeysEnv) {
ExecCtx exec_ctx; ExecCtx exec_ctx;
SetEnv("AWS_ACCESS_KEY_ID", "test_access_key_id"); gpr_setenv("AWS_ACCESS_KEY_ID", "test_access_key_id");
SetEnv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key"); gpr_setenv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key");
SetEnv("AWS_SESSION_TOKEN", "test_token"); gpr_setenv("AWS_SESSION_TOKEN", "test_token");
auto credential_source = auto credential_source =
Json::Parse(valid_aws_external_account_creds_options_credential_source); Json::Parse(valid_aws_external_account_creds_options_credential_source);
GPR_ASSERT(credential_source.ok()); GPR_ASSERT(credential_source.ok());
@ -3131,17 +3136,17 @@ TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionUrlKeysEnv) {
kTestPath); kTestPath);
ExecCtx::Get()->Flush(); ExecCtx::Get()->Flush();
HttpRequest::SetOverride(nullptr, nullptr, nullptr); HttpRequest::SetOverride(nullptr, nullptr, nullptr);
UnsetEnv("AWS_ACCESS_KEY_ID"); gpr_unsetenv("AWS_ACCESS_KEY_ID");
UnsetEnv("AWS_SECRET_ACCESS_KEY"); gpr_unsetenv("AWS_SECRET_ACCESS_KEY");
UnsetEnv("AWS_SESSION_TOKEN"); gpr_unsetenv("AWS_SESSION_TOKEN");
} }
TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionEnvKeysEnv) { TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionEnvKeysEnv) {
ExecCtx exec_ctx; ExecCtx exec_ctx;
SetEnv("AWS_REGION", "test_regionz"); gpr_setenv("AWS_REGION", "test_regionz");
SetEnv("AWS_ACCESS_KEY_ID", "test_access_key_id"); gpr_setenv("AWS_ACCESS_KEY_ID", "test_access_key_id");
SetEnv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key"); gpr_setenv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key");
SetEnv("AWS_SESSION_TOKEN", "test_token"); gpr_setenv("AWS_SESSION_TOKEN", "test_token");
auto credential_source = auto credential_source =
Json::Parse(valid_aws_external_account_creds_options_credential_source); Json::Parse(valid_aws_external_account_creds_options_credential_source);
GPR_ASSERT(credential_source.ok()); GPR_ASSERT(credential_source.ok());
@ -3172,10 +3177,10 @@ TEST(CredentialsTest, TestAwsExternalAccountCredsSuccessPathRegionEnvKeysEnv) {
kTestPath); kTestPath);
ExecCtx::Get()->Flush(); ExecCtx::Get()->Flush();
HttpRequest::SetOverride(nullptr, nullptr, nullptr); HttpRequest::SetOverride(nullptr, nullptr, nullptr);
UnsetEnv("AWS_REGION"); gpr_unsetenv("AWS_REGION");
UnsetEnv("AWS_ACCESS_KEY_ID"); gpr_unsetenv("AWS_ACCESS_KEY_ID");
UnsetEnv("AWS_SECRET_ACCESS_KEY"); gpr_unsetenv("AWS_SECRET_ACCESS_KEY");
UnsetEnv("AWS_SESSION_TOKEN"); gpr_unsetenv("AWS_SESSION_TOKEN");
} }
TEST(CredentialsTest, TEST(CredentialsTest,
@ -3183,10 +3188,10 @@ TEST(CredentialsTest,
std::map<std::string, std::string> emd = { std::map<std::string, std::string> emd = {
{"authorization", "Bearer token_exchange_access_token"}}; {"authorization", "Bearer token_exchange_access_token"}};
ExecCtx exec_ctx; ExecCtx exec_ctx;
SetEnv("AWS_DEFAULT_REGION", "test_regionz"); gpr_setenv("AWS_DEFAULT_REGION", "test_regionz");
SetEnv("AWS_ACCESS_KEY_ID", "test_access_key_id"); gpr_setenv("AWS_ACCESS_KEY_ID", "test_access_key_id");
SetEnv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key"); gpr_setenv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key");
SetEnv("AWS_SESSION_TOKEN", "test_token"); gpr_setenv("AWS_SESSION_TOKEN", "test_token");
auto credential_source = auto credential_source =
Json::Parse(valid_aws_external_account_creds_options_credential_source); Json::Parse(valid_aws_external_account_creds_options_credential_source);
GPR_ASSERT(credential_source.ok()); GPR_ASSERT(credential_source.ok());
@ -3217,21 +3222,21 @@ TEST(CredentialsTest,
kTestPath); kTestPath);
ExecCtx::Get()->Flush(); ExecCtx::Get()->Flush();
HttpRequest::SetOverride(nullptr, nullptr, nullptr); HttpRequest::SetOverride(nullptr, nullptr, nullptr);
UnsetEnv("AWS_DEFAULT_REGION"); gpr_unsetenv("AWS_DEFAULT_REGION");
UnsetEnv("AWS_ACCESS_KEY_ID"); gpr_unsetenv("AWS_ACCESS_KEY_ID");
UnsetEnv("AWS_SECRET_ACCESS_KEY"); gpr_unsetenv("AWS_SECRET_ACCESS_KEY");
UnsetEnv("AWS_SESSION_TOKEN"); gpr_unsetenv("AWS_SESSION_TOKEN");
} }
TEST(CredentialsTest, TEST(CredentialsTest,
TestAwsExternalAccountCredsSuccessPathDuplicateRegionEnvKeysEnv) { TestAwsExternalAccountCredsSuccessPathDuplicateRegionEnvKeysEnv) {
ExecCtx exec_ctx; ExecCtx exec_ctx;
// Make sure that AWS_REGION gets used over AWS_DEFAULT_REGION // Make sure that AWS_REGION gets used over AWS_DEFAULT_REGION
SetEnv("AWS_REGION", "test_regionz"); gpr_setenv("AWS_REGION", "test_regionz");
SetEnv("AWS_DEFAULT_REGION", "ERROR_REGION"); gpr_setenv("AWS_DEFAULT_REGION", "ERROR_REGION");
SetEnv("AWS_ACCESS_KEY_ID", "test_access_key_id"); gpr_setenv("AWS_ACCESS_KEY_ID", "test_access_key_id");
SetEnv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key"); gpr_setenv("AWS_SECRET_ACCESS_KEY", "test_secret_access_key");
SetEnv("AWS_SESSION_TOKEN", "test_token"); gpr_setenv("AWS_SESSION_TOKEN", "test_token");
auto credential_source = auto credential_source =
Json::Parse(valid_aws_external_account_creds_options_credential_source); Json::Parse(valid_aws_external_account_creds_options_credential_source);
GPR_ASSERT(credential_source.ok()); GPR_ASSERT(credential_source.ok());
@ -3262,11 +3267,11 @@ TEST(CredentialsTest,
kTestPath); kTestPath);
ExecCtx::Get()->Flush(); ExecCtx::Get()->Flush();
HttpRequest::SetOverride(nullptr, nullptr, nullptr); HttpRequest::SetOverride(nullptr, nullptr, nullptr);
UnsetEnv("AWS_REGION"); gpr_unsetenv("AWS_REGION");
UnsetEnv("AWS_DEFAULT_REGION"); gpr_unsetenv("AWS_DEFAULT_REGION");
UnsetEnv("AWS_ACCESS_KEY_ID"); gpr_unsetenv("AWS_ACCESS_KEY_ID");
UnsetEnv("AWS_SECRET_ACCESS_KEY"); gpr_unsetenv("AWS_SECRET_ACCESS_KEY");
UnsetEnv("AWS_SESSION_TOKEN"); gpr_unsetenv("AWS_SESSION_TOKEN");
} }
TEST(CredentialsTest, TEST(CredentialsTest,

@ -31,8 +31,8 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/tmpfile.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/iomgr/load_file.h"
#include "src/core/lib/security/context/security_context.h" #include "src/core/lib/security/context/security_context.h"
#include "src/core/lib/security/security_connector/load_system_roots.h" #include "src/core/lib/security/security_connector/load_system_roots.h"

@ -126,7 +126,6 @@ grpc_cc_library(
"stack_tracer", "stack_tracer",
"//:channel_args_preconditioning", "//:channel_args_preconditioning",
"//:config", "//:config",
"//:env",
"//:gpr", "//:gpr",
"//:gpr_atm", "//:gpr_atm",
"//:grpc", "//:grpc",
@ -166,7 +165,6 @@ grpc_cc_library(
"stack_tracer", "stack_tracer",
"//:channel_args_preconditioning", "//:channel_args_preconditioning",
"//:config", "//:config",
"//:env",
"//:gpr", "//:gpr",
"//:gpr_atm", "//:gpr_atm",
"//:grpc_security_base", "//:grpc_security_base",

@ -28,14 +28,13 @@
#include "absl/flags/flag.h" #include "absl/flags/flag.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include <grpc/slice.h> #include <grpc/slice.h>
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#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/error.h"
#include "src/core/lib/iomgr/load_file.h" #include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
@ -84,13 +83,12 @@ class ExampleGenerator
examples_.push_back(absl::GetFlag(FLAGS_file)); examples_.push_back(absl::GetFlag(FLAGS_file));
} }
if (!absl::GetFlag(FLAGS_directory).empty()) { if (!absl::GetFlag(FLAGS_directory).empty()) {
auto test_srcdir = grpc_core::GetEnv("TEST_SRCDIR"); char* test_srcdir = gpr_getenv("TEST_SRCDIR");
gpr_log(GPR_DEBUG, "test_srcdir=\"%s\"", gpr_log(GPR_DEBUG, "test_srcdir=\"%s\"", test_srcdir);
test_srcdir.has_value() ? test_srcdir->c_str() : "(null)");
std::string directory = absl::GetFlag(FLAGS_directory); std::string directory = absl::GetFlag(FLAGS_directory);
if (test_srcdir.has_value()) { if (test_srcdir != nullptr) {
directory = 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()); gpr_log(GPR_DEBUG, "Using corpus directory: %s", directory.c_str());
DIR* dp; DIR* dp;
@ -109,6 +107,7 @@ class ExampleGenerator
perror("Couldn't open the directory"); perror("Couldn't open the directory");
abort(); abort();
} }
gpr_free(test_srcdir);
} }
} }
// Make sure we don't succeed without doing anything, which caused // Make sure we don't succeed without doing anything, which caused

@ -32,7 +32,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gpr/env.h"
#include "src/core/lib/surface/init.h" #include "src/core/lib/surface/init.h"
#include "test/core/event_engine/test_init.h" #include "test/core/event_engine/test_init.h"
#include "test/core/util/build.h" #include "test/core/util/build.h"
@ -108,7 +108,7 @@ void ParseTestArgs(int* argc, char** argv) {
int i = 1; int i = 1;
while (i < *argc) { while (i < *argc) {
if (absl::StartsWith(argv[i], poller_flag)) { 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 // remove the spent argv
RmArg(i, argc, argv); RmArg(i, argc, argv);
continue; continue;
@ -126,7 +126,7 @@ void ParseTestArgs(int* argc, char** argv) {
continue; continue;
} }
if (absl::StartsWith(argv[i], experiment_flag)) { 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 // remove the spent argv
RmArg(i, argc, argv); RmArg(i, argc, argv);
continue; continue;

@ -23,8 +23,8 @@
#include "src/core/ext/xds/xds_bootstrap_grpc.h" #include "src/core/ext/xds/xds_bootstrap_grpc.h"
#include "src/core/ext/xds/xds_client_grpc.h" #include "src/core/ext/xds/xds_client_grpc.h"
#include "src/core/lib/config/core_configuration.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/gpr/tmpfile.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/security/certificate_provider/certificate_provider_registry.h" #include "src/core/lib/security/certificate_provider/certificate_provider_registry.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
@ -33,7 +33,7 @@ namespace testing {
namespace { namespace {
TEST(XdsBootstrapTest, Basic) { TEST(XdsBootstrapTest, Basic) {
SetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true"); gpr_setenv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true");
const char* json_str = const char* json_str =
"{" "{"
" \"xds_servers\": [" " \"xds_servers\": ["
@ -169,7 +169,7 @@ TEST(XdsBootstrapTest, Basic) {
::testing::Property(&Json::string_value, "1"))))); ::testing::Property(&Json::string_value, "1")))));
EXPECT_EQ(bootstrap->server_listener_resource_name_template(), EXPECT_EQ(bootstrap->server_listener_resource_name_template(),
"example/resource"); "example/resource");
UnsetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); gpr_unsetenv("GRPC_EXPERIMENTAL_XDS_FEDERATION");
} }
TEST(XdsBootstrapTest, ValidWithoutNode) { TEST(XdsBootstrapTest, ValidWithoutNode) {
@ -226,7 +226,7 @@ TEST(XdsBootstrapTest, GoogleDefaultCreds) {
ASSERT_EQ(fwrite(token_str, 1, sizeof(token_str), creds_file), ASSERT_EQ(fwrite(token_str, 1, sizeof(token_str), creds_file),
sizeof(token_str)); sizeof(token_str));
fclose(creds_file); 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); gpr_free(creds_file_name);
// Now run test. // Now run test.
const char* json_str = const char* json_str =
@ -473,7 +473,7 @@ TEST(XdsBootstrapTest, CertificateProvidersUnrecognizedPluginName) {
} }
TEST(XdsBootstrapTest, AuthorityXdsServerInvalidResourceTemplate) { TEST(XdsBootstrapTest, AuthorityXdsServerInvalidResourceTemplate) {
SetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true"); gpr_setenv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true");
const char* json_str = const char* json_str =
"{" "{"
" \"xds_servers\": [" " \"xds_servers\": ["
@ -508,11 +508,11 @@ TEST(XdsBootstrapTest, AuthorityXdsServerInvalidResourceTemplate) {
".client_listener_resource_name_template error:" ".client_listener_resource_name_template error:"
"field must begin with \"xdstp://xds.example.com/\"]") "field must begin with \"xdstp://xds.example.com/\"]")
<< bootstrap.status(); << bootstrap.status();
UnsetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); gpr_unsetenv("GRPC_EXPERIMENTAL_XDS_FEDERATION");
} }
TEST(XdsBootstrapTest, AuthorityXdsServerMissingServerUri) { TEST(XdsBootstrapTest, AuthorityXdsServerMissingServerUri) {
SetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true"); gpr_setenv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true");
const char* json_str = const char* json_str =
"{" "{"
" \"xds_servers\": [" " \"xds_servers\": ["
@ -539,7 +539,7 @@ TEST(XdsBootstrapTest, AuthorityXdsServerMissingServerUri) {
"field:authorities[\"xds.example.com\"].xds_servers[0].server_uri " "field:authorities[\"xds.example.com\"].xds_servers[0].server_uri "
"error:field not present]") "error:field not present]")
<< bootstrap.status(); << bootstrap.status();
UnsetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); gpr_unsetenv("GRPC_EXPERIMENTAL_XDS_FEDERATION");
} }
class FakeCertificateProviderFactory : public CertificateProviderFactory { class FakeCertificateProviderFactory : public CertificateProviderFactory {
@ -681,7 +681,7 @@ TEST(XdsBootstrapTest, CertificateProvidersFakePluginEmptyConfig) {
} }
TEST(XdsBootstrapTest, XdsServerToJsonAndParse) { TEST(XdsBootstrapTest, XdsServerToJsonAndParse) {
SetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true"); gpr_setenv("GRPC_EXPERIMENTAL_XDS_FEDERATION", "true");
const char* json_str = const char* json_str =
" {" " {"
" \"server_uri\": \"fake:///lb\"," " \"server_uri\": \"fake:///lb\","
@ -702,7 +702,7 @@ TEST(XdsBootstrapTest, XdsServerToJsonAndParse) {
LoadFromJson<GrpcXdsBootstrap::GrpcXdsServer>(output); LoadFromJson<GrpcXdsBootstrap::GrpcXdsServer>(output);
ASSERT_TRUE(output_xds_server.ok()) << output_xds_server.status(); ASSERT_TRUE(output_xds_server.ok()) << output_xds_server.status();
EXPECT_EQ(*xds_server, *output_xds_server); EXPECT_EQ(*xds_server, *output_xds_server);
UnsetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION"); gpr_unsetenv("GRPC_EXPERIMENTAL_XDS_FEDERATION");
} }
} // namespace } // namespace

@ -30,7 +30,7 @@
#include "src/core/ext/xds/xds_bootstrap.h" #include "src/core/ext/xds/xds_bootstrap.h"
#include "src/core/ext/xds/xds_resource_type_impl.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/gprpp/sync.h"
#include "src/core/lib/json/json.h" #include "src/core/lib/json/json.h"
#include "src/core/lib/json/json_object_loader.h" #include "src/core/lib/json/json_object_loader.h"
@ -476,10 +476,10 @@ class XdsClientTest : public ::testing::Test {
class ScopedExperimentalEnvVar { class ScopedExperimentalEnvVar {
public: public:
explicit ScopedExperimentalEnvVar(const char* env_var) : env_var_(env_var) { 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: private:
const char* env_var_; const char* env_var_;

@ -28,8 +28,8 @@
#include <grpcpp/security/tls_credentials_options.h> #include <grpcpp/security/tls_credentials_options.h>
#include <grpcpp/server_builder.h> #include <grpcpp/server_builder.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/env.h"
#include "src/cpp/client/secure_credentials.h" #include "src/cpp/client/secure_credentials.h"
#include "test/cpp/util/tls_test_utils.h" #include "test/cpp/util/tls_test_utils.h"
@ -228,7 +228,7 @@ TEST(CredentialsTest, StsCredentialsOptionsJson) {
TEST(CredentialsTest, StsCredentialsOptionsFromEnv) { TEST(CredentialsTest, StsCredentialsOptionsFromEnv) {
// Unset env and check expected failure. // Unset env and check expected failure.
grpc_core::UnsetEnv("STS_CREDENTIALS"); gpr_unsetenv("STS_CREDENTIALS");
grpc::experimental::StsCredentialsOptions options; grpc::experimental::StsCredentialsOptions options;
auto status = grpc::experimental::StsCredentialsOptionsFromEnv(&options); auto status = grpc::experimental::StsCredentialsOptionsFromEnv(&options);
EXPECT_EQ(grpc::StatusCode::NOT_FOUND, status.error_code()); EXPECT_EQ(grpc::StatusCode::NOT_FOUND, status.error_code());
@ -247,7 +247,7 @@ TEST(CredentialsTest, StsCredentialsOptionsFromEnv) {
ASSERT_EQ(sizeof(valid_json), ASSERT_EQ(sizeof(valid_json),
fwrite(valid_json, 1, sizeof(valid_json), creds_file)); fwrite(valid_json, 1, sizeof(valid_json), creds_file));
fclose(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); gpr_free(creds_file_name);
status = grpc::experimental::StsCredentialsOptionsFromEnv(&options); status = grpc::experimental::StsCredentialsOptionsFromEnv(&options);
EXPECT_TRUE(status.ok()); EXPECT_TRUE(status.ok());
@ -262,7 +262,7 @@ TEST(CredentialsTest, StsCredentialsOptionsFromEnv) {
EXPECT_EQ(options.actor_token_type, ""); EXPECT_EQ(options.actor_token_type, "");
// Cleanup. // Cleanup.
grpc_core::UnsetEnv("STS_CREDENTIALS"); gpr_unsetenv("STS_CREDENTIALS");
} }
TEST(CredentialsTest, TlsChannelCredentialsWithDefaultRootsAndDefaultVerifier) { TEST(CredentialsTest, TlsChannelCredentialsWithDefaultRootsAndDefaultVerifier) {

@ -38,7 +38,7 @@
#include <grpcpp/server_builder.h> #include <grpcpp/server_builder.h>
#include "src/core/lib/backoff/backoff.h" #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/core/lib/iomgr/port.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h" #include "test/core/util/port.h"
@ -472,7 +472,7 @@ TEST_P(CFStreamTest, ConcurrentRpc) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
grpc::testing::TestEnvironment env(&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(); const auto result = RUN_ALL_TESTS();
return result; return result;
} }

@ -34,7 +34,7 @@
#include <grpcpp/server_builder.h> #include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h> #include <grpcpp/server_context.h>
#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/iomgr/load_file.h"
#include "src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h" #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h"
#include "src/core/lib/security/security_connector/ssl_utils.h" #include "src/core/lib/security/security_connector/ssl_utils.h"
@ -186,7 +186,7 @@ class ChannelzServerTest : public ::testing::TestWithParam<CredentialsType> {
static void SetUpTestCase() { static void SetUpTestCase() {
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
} }
void SetUp() override { void SetUp() override {

@ -37,7 +37,7 @@
#include <grpcpp/server_context.h> #include <grpcpp/server_context.h>
#include <grpcpp/support/client_callback.h> #include <grpcpp/support/client_callback.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/iomgr/iomgr.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h" #include "test/core/util/port.h"
@ -1524,7 +1524,7 @@ TEST_P(ClientCallbackEnd2endTest,
std::vector<TestScenario> CreateTestScenarios(bool test_insecure) { std::vector<TestScenario> CreateTestScenarios(bool test_insecure) {
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
std::vector<TestScenario> scenarios; std::vector<TestScenario> scenarios;

@ -54,8 +54,8 @@
#include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/backoff/backoff.h" #include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/channel/channel_args.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/debug_location.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/tcp_client.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); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
} }

@ -42,7 +42,7 @@
#include <grpcpp/test/channel_test_peer.h> #include <grpcpp/test/channel_test_peer.h>
#include "src/core/ext/filters/client_channel/backup_poller.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/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/credentials/credentials.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
@ -2252,7 +2252,7 @@ std::vector<TestScenario> CreateTestScenarios(bool use_proxy,
kClientChannelBackupPollIntervalMs); kClientChannelBackupPollIntervalMs);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
if (test_secure) { if (test_secure) {

@ -43,7 +43,7 @@
#include <grpcpp/server_builder.h> #include <grpcpp/server_builder.h>
#include "src/core/lib/backoff/backoff.h" #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 "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h" #include "test/core/util/port.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"

@ -46,7 +46,7 @@
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" #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/address_utils/parse_address.h"
#include "src/core/lib/channel/channel_args.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/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/resolver/server_address.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); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
grpc_init(); grpc_init();
} }

@ -30,7 +30,7 @@
#include <grpcpp/server_builder.h> #include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h> #include <grpcpp/server_context.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/iomgr/iomgr.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h"
@ -233,7 +233,7 @@ class HybridEnd2endTest : public ::testing::TestWithParam<bool> {
static void SetUpTestCase() { static void SetUpTestCase() {
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
} }

@ -34,7 +34,7 @@
#include <grpcpp/server_builder.h> #include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h> #include <grpcpp/server_context.h>
#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/endpoint.h"
#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/pollset.h" #include "src/core/lib/iomgr/pollset.h"
@ -313,7 +313,7 @@ std::vector<TestScenario> CreateTestScenarios() {
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
credentials_types = GetCredentialsProvider()->GetSecureCredentialsTypeList(); credentials_types = GetCredentialsProvider()->GetSecureCredentialsTypeList();

@ -33,7 +33,7 @@
#include <grpcpp/server_builder.h> #include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h> #include <grpcpp/server_context.h>
#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gpr/env.h"
#include "src/core/lib/iomgr/port.h" #include "src/core/lib/iomgr/port.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h"

@ -43,7 +43,7 @@
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" #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/address_utils/parse_address.h"
#include "src/core/lib/channel/channel_args.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/host_port.h"
#include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr.h"
@ -158,7 +158,7 @@ class FakeResolverResponseGeneratorWrapper {
class RlsEnd2endTest : public ::testing::Test { class RlsEnd2endTest : public ::testing::Test {
protected: protected:
static void SetUpTestSuite() { 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); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
grpc_core::CoreConfiguration::RegisterBuilder( grpc_core::CoreConfiguration::RegisterBuilder(
grpc_core::RegisterFixedAddressLoadBalancingPolicy); grpc_core::RegisterFixedAddressLoadBalancingPolicy);
@ -167,7 +167,7 @@ class RlsEnd2endTest : public ::testing::Test {
static void TearDownTestSuite() { static void TearDownTestSuite() {
grpc_shutdown_blocking(); grpc_shutdown_blocking();
grpc_core::UnsetEnv("GRPC_EXPERIMENTAL_ENABLE_RLS_LB_POLICY"); gpr_unsetenv("GRPC_EXPERIMENTAL_ENABLE_RLS_LB_POLICY");
grpc_core::CoreConfiguration::Reset(); grpc_core::CoreConfiguration::Reset();
} }

@ -30,7 +30,7 @@
#include <grpcpp/server_builder.h> #include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h> #include <grpcpp/server_context.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 "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h" #include "test/core/util/port.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"

@ -33,7 +33,7 @@
#include <grpcpp/server_builder.h> #include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h> #include <grpcpp/server_context.h>
#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gpr/env.h"
#include "src/core/lib/surface/api_trace.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/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h"
@ -75,7 +75,7 @@ class CommonStressTest {
CommonStressTest() : kMaxMessageSize_(8192) { CommonStressTest() : kMaxMessageSize_(8192) {
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
} }
virtual ~CommonStressTest() {} virtual ~CommonStressTest() {}

@ -1732,7 +1732,7 @@ int main(int argc, char** argv) {
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
grpc_init(); grpc_init();
grpc::testing::ConnectionAttemptInjector::Init(); grpc::testing::ConnectionAttemptInjector::Init();

@ -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/lb_policy/xds/xds_channel_args.h"
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.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/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/core/lib/resolver/server_address.h"
#include "src/proto/grpc/testing/xds/v3/aggregate_cluster.grpc.pb.h" #include "src/proto/grpc/testing/xds/v3/aggregate_cluster.grpc.pb.h"
#include "test/cpp/end2end/connection_attempt_injector.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); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
grpc_init(); grpc_init();
grpc::testing::ConnectionAttemptInjector::Init(); grpc::testing::ConnectionAttemptInjector::Init();

@ -1357,7 +1357,7 @@ int main(int argc, char** argv) {
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
grpc_init(); grpc_init();
const auto result = RUN_ALL_TESTS(); const auto result = RUN_ALL_TESTS();

@ -707,7 +707,7 @@ int main(int argc, char** argv) {
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
grpc_init(); grpc_init();
const auto result = RUN_ALL_TESTS(); const auto result = RUN_ALL_TESTS();

@ -69,10 +69,10 @@
#include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.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/string.h"
#include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gpr/time_precise.h"
#include "src/core/lib/gpr/tmpfile.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/ref_counted_ptr.h"
#include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/gprpp/time.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); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
grpc::testing::FakeCertificateProvider::CertDataMapWrapper cert_data_map_1; grpc::testing::FakeCertificateProvider::CertDataMapWrapper cert_data_map_1;
grpc::testing::g_fake1_cert_data_map = &cert_data_map_1; grpc::testing::g_fake1_cert_data_map = &cert_data_map_1;

@ -39,8 +39,8 @@
#include "src/core/ext/filters/http/server/http_server_filter.h" #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_channel_args.h"
#include "src/core/ext/xds/xds_client_grpc.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/gpr/tmpfile.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/iomgr/load_file.h" #include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/surface/server.h" #include "src/core/lib/surface/server.h"
#include "src/cpp/client/secure_credentials.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 // Clear global xDS channel args, since they will go out of scope
// when this test object is destroyed. // when this test object is destroyed.
grpc_core::internal::SetXdsChannelArgsForTest(nullptr); grpc_core::internal::SetXdsChannelArgsForTest(nullptr);
grpc_core::UnsetEnv("GRPC_XDS_BOOTSTRAP"); gpr_unsetenv("GRPC_XDS_BOOTSTRAP");
grpc_core::UnsetEnv("GRPC_XDS_BOOTSTRAP_CONFIG"); gpr_unsetenv("GRPC_XDS_BOOTSTRAP_CONFIG");
if (bootstrap_file_ != nullptr) { if (bootstrap_file_ != nullptr) {
remove(bootstrap_file_); remove(bootstrap_file_);
gpr_free(bootstrap_file_); gpr_free(bootstrap_file_);
@ -751,12 +751,12 @@ void XdsEnd2endTest::InitClient(BootstrapBuilder builder,
if (GetParam().use_v2()) builder.SetV2(); if (GetParam().use_v2()) builder.SetV2();
bootstrap_ = builder.Build(); bootstrap_ = builder.Build();
if (GetParam().bootstrap_source() == XdsTestType::kBootstrapFromEnvVar) { 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) { } else if (GetParam().bootstrap_source() == XdsTestType::kBootstrapFromFile) {
FILE* out = gpr_tmpfile("xds_bootstrap_v3", &bootstrap_file_); FILE* out = gpr_tmpfile("xds_bootstrap_v3", &bootstrap_file_);
fputs(bootstrap_.c_str(), out); fputs(bootstrap_.c_str(), out);
fclose(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 (GetParam().bootstrap_source() != XdsTestType::kBootstrapFromChannelArg) {
// If getting bootstrap from channel arg, we'll pass these args in // If getting bootstrap from channel arg, we'll pass these args in

@ -33,7 +33,7 @@
#include <grpcpp/client_context.h> #include <grpcpp/client_context.h>
#include <grpcpp/xds_server_builder.h> #include <grpcpp/xds_server_builder.h>
#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/credentials/fake/fake_credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils.h" #include "src/core/lib/security/security_connector/ssl_utils.h"
#include "src/cpp/server/secure_server_credentials.h" #include "src/cpp/server/secure_server_credentials.h"
@ -466,10 +466,10 @@ class XdsEnd2endTest : public ::testing::TestWithParam<XdsTestType> {
class ScopedExperimentalEnvVar { class ScopedExperimentalEnvVar {
public: public:
explicit ScopedExperimentalEnvVar(const char* env_var) : env_var_(env_var) { 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: private:
const char* env_var_; const char* env_var_;

@ -563,7 +563,7 @@ int main(int argc, char** argv) {
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
grpc_init(); grpc_init();
const auto result = RUN_ALL_TESTS(); const auto result = RUN_ALL_TESTS();

@ -1245,16 +1245,16 @@ int main(int argc, char** argv) {
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
// TODO(roth): This is a hack to ensure that the outlier_detection LB policy // 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 // is always registered at gRPC init time. When the LB policy registry is
// moved to the new CoreConfiguration system, change this to use // moved to the new CoreConfiguration system, change this to use
// CoreConfiguration::BuildSpecialConfiguration() instead. // CoreConfiguration::BuildSpecialConfiguration() instead.
grpc_core::SetEnv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION", "true"); gpr_setenv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION", "true");
grpc_init(); grpc_init();
const auto result = RUN_ALL_TESTS(); const auto result = RUN_ALL_TESTS();
grpc_shutdown(); grpc_shutdown();
grpc_core::UnsetEnv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION"); gpr_unsetenv("GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION");
return result; return result;
} }

@ -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/lb_policy/xds/xds_channel_args.h"
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.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/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/aggregate_cluster.grpc.pb.h"
#include "src/proto/grpc/testing/xds/v3/cluster.grpc.pb.h" #include "src/proto/grpc/testing/xds/v3/cluster.grpc.pb.h"
#include "test/cpp/end2end/connection_attempt_injector.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); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
grpc_init(); grpc_init();
grpc::testing::ConnectionAttemptInjector::Init(); grpc::testing::ConnectionAttemptInjector::Init();

@ -22,7 +22,7 @@
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "src/core/ext/filters/client_channel/backup_poller.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.grpc.pb.h"
#include "src/proto/grpc/lookup/v1/rls.pb.h" #include "src/proto/grpc/lookup/v1/rls.pb.h"
#include "src/proto/grpc/lookup/v1/rls_config.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); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
grpc_init(); grpc_init();
const auto result = RUN_ALL_TESTS(); const auto result = RUN_ALL_TESTS();

@ -3183,7 +3183,7 @@ int main(int argc, char** argv) {
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1); GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
// Workaround Apple CFStream bug // Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0"); gpr_setenv("grpc_cfstream", "0");
#endif #endif
grpc_init(); grpc_init();
grpc_core::XdsHttpFilterRegistry::RegisterFilter( grpc_core::XdsHttpFilterRegistry::RegisterFilter(

@ -21,8 +21,8 @@
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/env.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
namespace grpc { namespace grpc {
@ -82,7 +82,7 @@ TEST(GcpEnvParsingTest, NoEnvironmentVariableSet) {
} }
TEST(GcpEnvParsingTest, ConfigFileDoesNotExist) { TEST(GcpEnvParsingTest, ConfigFileDoesNotExist) {
grpc_core::SetEnv("GRPC_OBSERVABILITY_CONFIG_FILE", gpr_setenv("GRPC_OBSERVABILITY_CONFIG_FILE",
"/tmp/gcp_observability_config_does_not_exist"); "/tmp/gcp_observability_config_does_not_exist");
auto config = GcpObservabilityConfig::ReadFromEnv(); auto config = GcpObservabilityConfig::ReadFromEnv();
@ -90,7 +90,7 @@ TEST(GcpEnvParsingTest, ConfigFileDoesNotExist) {
EXPECT_EQ(config.status(), EXPECT_EQ(config.status(),
absl::FailedPreconditionError("Failed to load file")); absl::FailedPreconditionError("Failed to load file"));
grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG_FILE"); gpr_unsetenv("GRPC_OBSERVABILITY_CONFIG_FILE");
} }
class EnvParsingTestType { class EnvParsingTestType {
@ -131,13 +131,13 @@ class EnvParsingTest : public ::testing::TestWithParam<EnvParsingTestType> {
~EnvParsingTest() override { ~EnvParsingTest() override {
if (GetParam().config_source() == EnvParsingTestType::ConfigSource::kFile) { if (GetParam().config_source() == EnvParsingTestType::ConfigSource::kFile) {
if (tmp_file_name != nullptr) { if (tmp_file_name != nullptr) {
grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG_FILE"); gpr_unsetenv("GRPC_OBSERVABILITY_CONFIG_FILE");
remove(tmp_file_name); remove(tmp_file_name);
gpr_free(tmp_file_name); gpr_free(tmp_file_name);
} }
} else if (GetParam().config_source() == } else if (GetParam().config_source() ==
EnvParsingTestType::ConfigSource::kEnvVar) { EnvParsingTestType::ConfigSource::kEnvVar) {
grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG"); gpr_unsetenv("GRPC_OBSERVABILITY_CONFIG");
} }
} }
@ -148,10 +148,10 @@ class EnvParsingTest : public ::testing::TestWithParam<EnvParsingTestType> {
gpr_tmpfile("gcp_observability_config", &tmp_file_name); gpr_tmpfile("gcp_observability_config", &tmp_file_name);
fputs(json, tmp_config_file); fputs(json, tmp_config_file);
fclose(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() == } else if (GetParam().config_source() ==
EnvParsingTestType::ConfigSource::kEnvVar) { EnvParsingTestType::ConfigSource::kEnvVar) {
grpc_core::SetEnv("GRPC_OBSERVABILITY_CONFIG", json); gpr_setenv("GRPC_OBSERVABILITY_CONFIG", json);
} }
} }

@ -44,7 +44,7 @@
#include <grpcpp/xds_server_builder.h> #include <grpcpp/xds_server_builder.h>
#include "src/core/lib/channel/status_util.h" #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/gprpp/host_port.h"
#include "src/core/lib/iomgr/gethostname.h" #include "src/core/lib/iomgr/gethostname.h"
#include "src/proto/grpc/testing/istio_echo.pb.h" #include "src/proto/grpc/testing/istio_echo.pb.h"

@ -40,7 +40,7 @@
#include <grpcpp/server_context.h> #include <grpcpp/server_context.h>
#include "src/core/lib/channel/status_util.h" #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/empty.pb.h"
#include "src/proto/grpc/testing/messages.pb.h" #include "src/proto/grpc/testing/messages.pb.h"
#include "src/proto/grpc/testing/test.grpc.pb.h" #include "src/proto/grpc/testing/test.grpc.pb.h"

@ -35,7 +35,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#endif #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/port.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
#include "test/cpp/util/subprocess.h" #include "test/cpp/util/subprocess.h"
@ -129,9 +129,9 @@ int main(int argc, char** argv) {
.empty()); .empty());
// Use bazel's TEST_SRCDIR environment variable to locate the "test data" // Use bazel's TEST_SRCDIR environment variable to locate the "test data"
// binaries. // binaries.
auto test_srcdir = grpc_core::GetEnv("TEST_SRCDIR"); char* test_srcdir = gpr_getenv("TEST_SRCDIR");
std::string const bin_dir = std::string const bin_dir =
test_srcdir.value() + test_srcdir +
absl::GetFlag(FLAGS_grpc_test_directory_relative_to_test_srcdir) + absl::GetFlag(FLAGS_grpc_test_directory_relative_to_test_srcdir) +
std::string("/test/cpp/naming"); std::string("/test/cpp/naming");
// Invoke bazel's executeable links to the .sh and .py scripts (don't use // 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 + "/utils/dns_server",
bin_dir + "/resolver_test_record_groups.yaml", bin_dir + "/resolver_test_record_groups.yaml",
bin_dir + "/utils/dns_resolver", bin_dir + "/utils/tcp_connect"); bin_dir + "/utils/dns_resolver", bin_dir + "/utils/tcp_connect");
gpr_free(test_srcdir);
} else { } else {
// Get the current binary's directory relative to repo root to invoke the // Get the current binary's directory relative to repo root to invoke the
// correct build config (asan/tsan/dbg, etc.). // correct build config (asan/tsan/dbg, etc.).

@ -37,7 +37,7 @@
#include <grpcpp/support/channel_arguments.h> #include <grpcpp/support/channel_arguments.h>
#include <grpcpp/support/slice.h> #include <grpcpp/support/slice.h>
#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gpr/env.h"
#include "src/cpp/util/core_stats.h" #include "src/cpp/util/core_stats.h"
#include "src/proto/grpc/testing/benchmark_service.grpc.pb.h" #include "src/proto/grpc/testing/benchmark_service.grpc.pb.h"
#include "src/proto/grpc/testing/payloads.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 /* Allow optionally overriding connect_deadline in order
* to deal with benchmark environments in which the server * to deal with benchmark environments in which the server
* can take a long time to become ready. */ * can take a long time to become ready. */
auto channel_connect_timeout_str = char* channel_connect_timeout_str =
grpc_core::GetEnv("QPS_WORKER_CHANNEL_CONNECT_TIMEOUT"); gpr_getenv("QPS_WORKER_CHANNEL_CONNECT_TIMEOUT");
if (channel_connect_timeout_str.has_value() && if (channel_connect_timeout_str != nullptr &&
!channel_connect_timeout_str->empty()) { strcmp(channel_connect_timeout_str, "") != 0) {
connect_deadline_seconds = atoi(channel_connect_timeout_str->c_str()); connect_deadline_seconds = atoi(channel_connect_timeout_str);
} }
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"Waiting for up to %d seconds for all channels to connect", "Waiting for up to %d seconds for all channels to connect",
connect_deadline_seconds); connect_deadline_seconds);
gpr_free(channel_connect_timeout_str);
gpr_timespec connect_deadline = gpr_time_add( gpr_timespec connect_deadline = gpr_time_add(
gpr_now(GPR_CLOCK_REALTIME), gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_seconds(connect_deadline_seconds, GPR_TIMESPAN)); gpr_time_from_seconds(connect_deadline_seconds, GPR_TIMESPAN));

@ -34,7 +34,7 @@
#include <grpcpp/client_context.h> #include <grpcpp/client_context.h>
#include <grpcpp/create_channel.h> #include <grpcpp/create_channel.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/host_port.h"
#include "src/proto/grpc/testing/worker_service.grpc.pb.h" #include "src/proto/grpc/testing/worker_service.grpc.pb.h"
#include "test/core/util/port.h" #include "test/core/util/port.h"
@ -61,11 +61,14 @@ static std::string get_host(const std::string& worker) {
static deque<string> get_workers(const string& env_name) { static deque<string> get_workers(const string& env_name) {
deque<string> out; deque<string> out;
auto env = grpc_core::GetEnv(env_name.c_str()).value_or(""); char* env = gpr_getenv(env_name.c_str());
const char* p = env.c_str(); if (!env) {
if (!env.empty()) { env = gpr_strdup("");
}
char* p = env;
if (strlen(env) != 0) {
for (;;) { for (;;) {
const char* comma = strchr(p, ','); char* comma = strchr(p, ',');
if (comma) { if (comma) {
out.emplace_back(p, comma); out.emplace_back(p, comma);
p = comma + 1; p = comma + 1;
@ -84,6 +87,7 @@ static deque<string> get_workers(const string& env_name) {
"%s=\"serverhost1:1234,clienthost1:1234,clienthost2:1234\"", "%s=\"serverhost1:1234,clienthost1:1234,clienthost2:1234\"",
env_name.c_str(), env_name.c_str()); env_name.c_str(), env_name.c_str());
} }
gpr_free(env);
return out; return out;
} }

@ -30,7 +30,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gpr/env.h"
#include "test/core/util/port.h" #include "test/core/util/port.h"
#include "test/cpp/util/subprocess.h" #include "test/cpp/util/subprocess.h"
@ -101,7 +101,7 @@ int main(int argc, char** argv) {
first = false; first = false;
} }
grpc_core::SetEnv("QPS_WORKERS", env.str().c_str()); gpr_setenv("QPS_WORKERS", env.str().c_str());
std::vector<std::string> args = {bin_dir + "/qps_json_driver"}; std::vector<std::string> args = {bin_dir + "/qps_json_driver"};
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
args.push_back(argv[i]); args.push_back(argv[i]);

@ -42,7 +42,7 @@
#include <grpcpp/server_builder.h> #include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h> #include <grpcpp/server_context.h>
#include "src/core/lib/gprpp/env.h" #include "src/core/lib/gpr/env.h"
#include "src/cpp/server/channelz/channelz_service.h" #include "src/cpp/server/channelz/channelz_service.h"
#include "src/proto/grpc/testing/test.grpc.pb.h" #include "src/proto/grpc/testing/test.grpc.pb.h"
#include "test/core/util/port.h" #include "test/core/util/port.h"

@ -36,7 +36,7 @@
#include <grpcpp/server_builder.h> #include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h> #include <grpcpp/server_context.h>
#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/iomgr/load_file.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "src/proto/grpc/testing/echo.pb.h" #include "src/proto/grpc/testing/echo.pb.h"
@ -1264,10 +1264,10 @@ TEST_F(GrpcToolTest, CallCommandWithBadMetadata) {
"grpc.testing.EchoTestService.Echo", "grpc.testing.EchoTestService.Echo",
"message: 'Hello'"}; "message: 'Hello'"};
absl::SetFlag(&FLAGS_protofiles, "src/proto/grpc/testing/echo.proto"); absl::SetFlag(&FLAGS_protofiles, "src/proto/grpc/testing/echo.proto");
auto test_srcdir = grpc_core::GetEnv("TEST_SRCDIR"); char* test_srcdir = gpr_getenv("TEST_SRCDIR");
if (test_srcdir.has_value()) { if (test_srcdir != nullptr) {
absl::SetFlag(&FLAGS_proto_path, 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_metadata, "");
absl::SetFlag(&FLAGS_protofiles, ""); absl::SetFlag(&FLAGS_protofiles, "");
gpr_free(test_srcdir);
} }
TEST_F(GrpcToolTest, ListCommand_OverrideSslHostName) { TEST_F(GrpcToolTest, ListCommand_OverrideSslHostName) {

@ -1991,6 +1991,10 @@ src/core/lib/gpr/cpu_iphone.cc \
src/core/lib/gpr/cpu_linux.cc \ src/core/lib/gpr/cpu_linux.cc \
src/core/lib/gpr/cpu_posix.cc \ src/core/lib/gpr/cpu_posix.cc \
src/core/lib/gpr/cpu_windows.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.cc \
src/core/lib/gpr/log_android.cc \ src/core/lib/gpr/log_android.cc \
src/core/lib/gpr/log_linux.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/cpp_impl_of.h \
src/core/lib/gprpp/debug_location.h \ src/core/lib/gprpp/debug_location.h \
src/core/lib/gprpp/dual_ref_counted.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.cc \
src/core/lib/gprpp/examine_stack.h \ src/core/lib/gprpp/examine_stack.h \
src/core/lib/gprpp/fork.cc \ src/core/lib/gprpp/fork.cc \

@ -1782,6 +1782,10 @@ src/core/lib/gpr/cpu_iphone.cc \
src/core/lib/gpr/cpu_linux.cc \ src/core/lib/gpr/cpu_linux.cc \
src/core/lib/gpr/cpu_posix.cc \ src/core/lib/gpr/cpu_posix.cc \
src/core/lib/gpr/cpu_windows.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.cc \
src/core/lib/gpr/log_android.cc \ src/core/lib/gpr/log_android.cc \
src/core/lib/gpr/log_linux.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/cpp_impl_of.h \
src/core/lib/gprpp/debug_location.h \ src/core/lib/gprpp/debug_location.h \
src/core/lib/gprpp/dual_ref_counted.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.cc \
src/core/lib/gprpp/examine_stack.h \ src/core/lib/gprpp/examine_stack.h \
src/core/lib/gprpp/fork.cc \ src/core/lib/gprpp/fork.cc \

Loading…
Cancel
Save