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

6
CMakeLists.txt generated

@ -1531,6 +1531,9 @@ add_library(gpr
src/core/lib/gpr/cpu_linux.cc
src/core/lib/gpr/cpu_posix.cc
src/core/lib/gpr/cpu_windows.cc
src/core/lib/gpr/env_linux.cc
src/core/lib/gpr/env_posix.cc
src/core/lib/gpr/env_windows.cc
src/core/lib/gpr/log.cc
src/core/lib/gpr/log_android.cc
src/core/lib/gpr/log_linux.cc
@ -1552,9 +1555,6 @@ add_library(gpr
src/core/lib/gpr/tmpfile_posix.cc
src/core/lib/gpr/tmpfile_windows.cc
src/core/lib/gpr/wrap_memcpy.cc
src/core/lib/gprpp/env_linux.cc
src/core/lib/gprpp/env_posix.cc
src/core/lib/gprpp/env_windows.cc
src/core/lib/gprpp/examine_stack.cc
src/core/lib/gprpp/fork.cc
src/core/lib/gprpp/global_config_env.cc

6
Makefile generated

@ -847,6 +847,9 @@ LIBGPR_SRC = \
src/core/lib/gpr/cpu_linux.cc \
src/core/lib/gpr/cpu_posix.cc \
src/core/lib/gpr/cpu_windows.cc \
src/core/lib/gpr/env_linux.cc \
src/core/lib/gpr/env_posix.cc \
src/core/lib/gpr/env_windows.cc \
src/core/lib/gpr/log.cc \
src/core/lib/gpr/log_android.cc \
src/core/lib/gpr/log_linux.cc \
@ -868,9 +871,6 @@ LIBGPR_SRC = \
src/core/lib/gpr/tmpfile_posix.cc \
src/core/lib/gpr/tmpfile_windows.cc \
src/core/lib/gpr/wrap_memcpy.cc \
src/core/lib/gprpp/env_linux.cc \
src/core/lib/gprpp/env_posix.cc \
src/core/lib/gprpp/env_windows.cc \
src/core/lib/gprpp/examine_stack.cc \
src/core/lib/gprpp/fork.cc \
src/core/lib/gprpp/global_config_env.cc \

@ -199,13 +199,13 @@ libs:
- include/grpc/support/time.h
headers:
- src/core/lib/gpr/alloc.h
- src/core/lib/gpr/env.h
- src/core/lib/gpr/string.h
- src/core/lib/gpr/time_precise.h
- src/core/lib/gpr/tls.h
- src/core/lib/gpr/tmpfile.h
- src/core/lib/gpr/useful.h
- src/core/lib/gprpp/construct_destruct.h
- src/core/lib/gprpp/env.h
- src/core/lib/gprpp/examine_stack.h
- src/core/lib/gprpp/fork.h
- src/core/lib/gprpp/global_config.h
@ -228,6 +228,9 @@ libs:
- src/core/lib/gpr/cpu_linux.cc
- src/core/lib/gpr/cpu_posix.cc
- src/core/lib/gpr/cpu_windows.cc
- src/core/lib/gpr/env_linux.cc
- src/core/lib/gpr/env_posix.cc
- src/core/lib/gpr/env_windows.cc
- src/core/lib/gpr/log.cc
- src/core/lib/gpr/log_android.cc
- src/core/lib/gpr/log_linux.cc
@ -249,9 +252,6 @@ libs:
- src/core/lib/gpr/tmpfile_posix.cc
- src/core/lib/gpr/tmpfile_windows.cc
- src/core/lib/gpr/wrap_memcpy.cc
- src/core/lib/gprpp/env_linux.cc
- src/core/lib/gprpp/env_posix.cc
- src/core/lib/gprpp/env_windows.cc
- src/core/lib/gprpp/examine_stack.cc
- src/core/lib/gprpp/fork.cc
- src/core/lib/gprpp/global_config_env.cc

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

6
config.w32 generated

@ -462,6 +462,9 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\gpr\\cpu_linux.cc " +
"src\\core\\lib\\gpr\\cpu_posix.cc " +
"src\\core\\lib\\gpr\\cpu_windows.cc " +
"src\\core\\lib\\gpr\\env_linux.cc " +
"src\\core\\lib\\gpr\\env_posix.cc " +
"src\\core\\lib\\gpr\\env_windows.cc " +
"src\\core\\lib\\gpr\\log.cc " +
"src\\core\\lib\\gpr\\log_android.cc " +
"src\\core\\lib\\gpr\\log_linux.cc " +
@ -484,9 +487,6 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\gpr\\tmpfile_posix.cc " +
"src\\core\\lib\\gpr\\tmpfile_windows.cc " +
"src\\core\\lib\\gpr\\wrap_memcpy.cc " +
"src\\core\\lib\\gprpp\\env_linux.cc " +
"src\\core\\lib\\gprpp\\env_posix.cc " +
"src\\core\\lib\\gprpp\\env_windows.cc " +
"src\\core\\lib\\gprpp\\examine_stack.cc " +
"src\\core\\lib\\gprpp\\fork.cc " +
"src\\core\\lib\\gprpp\\global_config_env.cc " +

4
gRPC-C++.podspec generated

@ -701,6 +701,7 @@ Pod::Spec.new do |s|
'src/core/lib/experiments/config.h',
'src/core/lib/experiments/experiments.h',
'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.h',
@ -715,7 +716,6 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/cpp_impl_of.h',
'src/core/lib/gprpp/debug_location.h',
'src/core/lib/gprpp/dual_ref_counted.h',
'src/core/lib/gprpp/env.h',
'src/core/lib/gprpp/examine_stack.h',
'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/global_config.h',
@ -1563,6 +1563,7 @@ Pod::Spec.new do |s|
'src/core/lib/experiments/config.h',
'src/core/lib/experiments/experiments.h',
'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.h',
@ -1577,7 +1578,6 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/cpp_impl_of.h',
'src/core/lib/gprpp/debug_location.h',
'src/core/lib/gprpp/dual_ref_counted.h',
'src/core/lib/gprpp/env.h',
'src/core/lib/gprpp/examine_stack.h',
'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/global_config.h',

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_posix.cc',
'src/core/lib/gpr/cpu_windows.cc',
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/env_linux.cc',
'src/core/lib/gpr/env_posix.cc',
'src/core/lib/gpr/env_windows.cc',
'src/core/lib/gpr/log.cc',
'src/core/lib/gpr/log_android.cc',
'src/core/lib/gpr/log_linux.cc',
@ -1131,10 +1135,6 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/cpp_impl_of.h',
'src/core/lib/gprpp/debug_location.h',
'src/core/lib/gprpp/dual_ref_counted.h',
'src/core/lib/gprpp/env.h',
'src/core/lib/gprpp/env_linux.cc',
'src/core/lib/gprpp/env_posix.cc',
'src/core/lib/gprpp/env_windows.cc',
'src/core/lib/gprpp/examine_stack.cc',
'src/core/lib/gprpp/examine_stack.h',
'src/core/lib/gprpp/fork.cc',
@ -2191,6 +2191,7 @@ Pod::Spec.new do |s|
'src/core/lib/experiments/config.h',
'src/core/lib/experiments/experiments.h',
'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/string.h',
@ -2205,7 +2206,6 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/cpp_impl_of.h',
'src/core/lib/gprpp/debug_location.h',
'src/core/lib/gprpp/dual_ref_counted.h',
'src/core/lib/gprpp/env.h',
'src/core/lib/gprpp/examine_stack.h',
'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/global_config.h',

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_posix.cc )
s.files += %w( src/core/lib/gpr/cpu_windows.cc )
s.files += %w( src/core/lib/gpr/env.h )
s.files += %w( src/core/lib/gpr/env_linux.cc )
s.files += %w( src/core/lib/gpr/env_posix.cc )
s.files += %w( src/core/lib/gpr/env_windows.cc )
s.files += %w( src/core/lib/gpr/log.cc )
s.files += %w( src/core/lib/gpr/log_android.cc )
s.files += %w( src/core/lib/gpr/log_linux.cc )
@ -1044,10 +1048,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gprpp/cpp_impl_of.h )
s.files += %w( src/core/lib/gprpp/debug_location.h )
s.files += %w( src/core/lib/gprpp/dual_ref_counted.h )
s.files += %w( src/core/lib/gprpp/env.h )
s.files += %w( src/core/lib/gprpp/env_linux.cc )
s.files += %w( src/core/lib/gprpp/env_posix.cc )
s.files += %w( src/core/lib/gprpp/env_windows.cc )
s.files += %w( src/core/lib/gprpp/examine_stack.cc )
s.files += %w( src/core/lib/gprpp/examine_stack.h )
s.files += %w( src/core/lib/gprpp/fork.cc )

6
grpc.gyp generated

@ -314,6 +314,9 @@
'src/core/lib/gpr/cpu_linux.cc',
'src/core/lib/gpr/cpu_posix.cc',
'src/core/lib/gpr/cpu_windows.cc',
'src/core/lib/gpr/env_linux.cc',
'src/core/lib/gpr/env_posix.cc',
'src/core/lib/gpr/env_windows.cc',
'src/core/lib/gpr/log.cc',
'src/core/lib/gpr/log_android.cc',
'src/core/lib/gpr/log_linux.cc',
@ -335,9 +338,6 @@
'src/core/lib/gpr/tmpfile_posix.cc',
'src/core/lib/gpr/tmpfile_windows.cc',
'src/core/lib/gpr/wrap_memcpy.cc',
'src/core/lib/gprpp/env_linux.cc',
'src/core/lib/gprpp/env_posix.cc',
'src/core/lib/gprpp/env_windows.cc',
'src/core/lib/gprpp/examine_stack.cc',
'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/global_config_env.cc',

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_posix.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_android.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/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/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.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/fork.cc" role="src" />

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

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

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

@ -18,20 +18,20 @@
#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/gprpp/env.h"
namespace grpc_core {
// TODO(donnadionne): check to see if federation is enabled, this will be
// removed once federation is fully integrated and enabled by default.
bool XdsFederationEnabled() {
auto value = GetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION");
if (!value.has_value()) return false;
char* value = gpr_getenv("GRPC_EXPERIMENTAL_XDS_FEDERATION");
bool parsed_value;
bool parse_succeeded = gpr_parse_bool_value(value->c_str(), &parsed_value);
bool parse_succeeded = gpr_parse_bool_value(value, &parsed_value);
gpr_free(value);
return parse_succeeded && parsed_value;
}

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

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

@ -16,38 +16,25 @@
*
*/
#ifndef GRPC_CORE_LIB_GPRPP_ENV_H
#define GRPC_CORE_LIB_GPRPP_ENV_H
#ifndef GRPC_CORE_LIB_GPR_ENV_H
#define GRPC_CORE_LIB_GPR_ENV_H
#include <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. */
absl::optional<std::string> GetEnv(const char* name);
/* Gets the environment variable value with the specified name.
Returns a newly allocated string. It is the responsibility of the caller to
gpr_free the return value if not NULL (which means that the environment
variable exists). */
char* gpr_getenv(const char* name);
/* Sets the environment with the specified name to the specified value. */
void SetEnv(const char* name, const char* value);
inline void SetEnv(const char* name, const std::string& value) {
SetEnv(name, value.c_str());
}
void gpr_setenv(const char* name, const char* value);
/* Deletes the variable name from the environment. */
void UnsetEnv(const char* name);
template <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
void gpr_unsetenv(const char* name);
#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 <string>
#include "absl/types/optional.h"
#ifdef GPR_LINUX_ENV
#if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
#include <dlfcn.h>
#endif
#include <features.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;
#if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
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
* to least secure) */
if (getenv_func == nullptr) {
for (auto name : {"secure_getenv", "__secure_getenv", "getenv"}) {
getenv_func = reinterpret_cast<getenv_type>(dlsym(RTLD_DEFAULT, name));
const char* names[] = {"secure_getenv", "__secure_getenv", "getenv"};
for (size_t i = 0; i < GPR_ARRAY_SIZE(names); i++) {
getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]);
if (getenv_func != nullptr) {
break;
}
@ -61,20 +59,17 @@ absl::optional<std::string> GetEnv(const char* name) {
#else
result = getenv(name);
#endif
if (result == nullptr) return absl::nullopt;
return result;
return result == nullptr ? result : gpr_strdup(result);
}
void SetEnv(const char* name, const char* value) {
void gpr_setenv(const char* name, const char* value) {
int res = setenv(name, value, 1);
if (res != 0) abort();
GPR_ASSERT(res == 0);
}
void UnsetEnv(const char* name) {
void gpr_unsetenv(const char* name) {
int res = unsetenv(name);
if (res != 0) abort();
GPR_ASSERT(res == 0);
}
} // namespace grpc_core
#endif /* GPR_LINUX_ENV */

@ -22,26 +22,25 @@
#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);
if (result == nullptr) return absl::nullopt;
return result;
return result == nullptr ? result : gpr_strdup(result);
}
void SetEnv(const char* name, const char* value) {
void gpr_setenv(const char* name, const char* value) {
int res = setenv(name, value, 1);
if (res != 0) abort();
GPR_ASSERT(res == 0);
}
void UnsetEnv(const char* name) {
void gpr_unsetenv(const char* name) {
int res = unsetenv(name);
if (res != 0) abort();
GPR_ASSERT(res == 0);
}
} // namespace grpc_core
#endif /* GPR_POSIX_ENV */

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

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

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

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

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

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

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

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

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

@ -471,6 +471,9 @@ CORE_SOURCE_FILES = [
'src/core/lib/gpr/cpu_linux.cc',
'src/core/lib/gpr/cpu_posix.cc',
'src/core/lib/gpr/cpu_windows.cc',
'src/core/lib/gpr/env_linux.cc',
'src/core/lib/gpr/env_posix.cc',
'src/core/lib/gpr/env_windows.cc',
'src/core/lib/gpr/log.cc',
'src/core/lib/gpr/log_android.cc',
'src/core/lib/gpr/log_linux.cc',
@ -493,9 +496,6 @@ CORE_SOURCE_FILES = [
'src/core/lib/gpr/tmpfile_posix.cc',
'src/core/lib/gpr/tmpfile_windows.cc',
'src/core/lib/gpr/wrap_memcpy.cc',
'src/core/lib/gprpp/env_linux.cc',
'src/core/lib/gprpp/env_posix.cc',
'src/core/lib/gprpp/env_windows.cc',
'src/core/lib/gprpp/examine_stack.cc',
'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/global_config_env.cc',

@ -20,7 +20,7 @@
#include "src/core/ext/filters/client_channel/http_proxy.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/transport/http_connect_handshaker.h"
#include "test/core/util/test_config.h"
@ -30,10 +30,10 @@ namespace {
class ScopedSetEnv {
public:
explicit ScopedSetEnv(const char* value) { SetEnv("no_proxy", value); }
explicit ScopedSetEnv(const char* value) { gpr_setenv("no_proxy", value); }
ScopedSetEnv(const ScopedSetEnv&) = delete;
ScopedSetEnv& operator=(const ScopedSetEnv&) = delete;
~ScopedSetEnv() { UnsetEnv("no_proxy"); }
~ScopedSetEnv() { gpr_unsetenv("no_proxy"); }
};
// Test that an empty no_proxy works as expected, i.e., proxy is used.

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

@ -19,7 +19,7 @@
#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 "test/core/util/test_config.h"

@ -27,7 +27,7 @@
#include <grpc/support/log.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 "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/http_proxy_fixture.h"
@ -75,7 +75,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
absl::StrFormat("http://%s@%s", proxy_auth_str,
grpc_end2end_http_proxy_get_proxy_name(ffd->proxy));
}
grpc_core::SetEnv("http_proxy", proxy_uri.c_str());
gpr_setenv("http_proxy", proxy_uri.c_str());
grpc_channel_credentials* creds = grpc_insecure_credentials_create();
f->client = grpc_channel_create(ffd->server_addr.c_str(), creds, client_args);
grpc_channel_credentials_release(creds);

@ -53,8 +53,8 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/event_engine/default_event_engine.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/endpoint.h"
@ -814,9 +814,9 @@ static grpc_channel_credentials* ReadChannelCreds(
DEFINE_PROTO_FUZZER(const api_fuzzer::Msg& msg) {
grpc_event_engine::experimental::ResetDefaultEventEngine();
grpc_test_only_set_slice_hash_seed(0);
if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) {
gpr_set_log_function(dont_log);
}
char* grpc_trace_fuzzer = gpr_getenv("GRPC_TRACE_FUZZER");
if (squelch && grpc_trace_fuzzer == nullptr) gpr_set_log_function(dont_log);
gpr_free(grpc_trace_fuzzer);
grpc_set_tcp_client_impl(&fuzz_tcp_client_vtable);
grpc_event_engine::experimental::SetDefaultEventEngineFactory(
[actions = msg.event_engine_actions()]() {

@ -22,7 +22,7 @@
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack_builder_impl.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/timer_manager.h"
#include "src/core/lib/resource_quota/resource_quota.h"
@ -585,9 +585,9 @@ DEFINE_PROTO_FUZZER(const filter_fuzzer::Msg& msg) {
}
grpc_test_only_set_slice_hash_seed(0);
if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) {
gpr_set_log_function(dont_log);
}
char* grpc_trace_fuzzer = gpr_getenv("GRPC_TRACE_FUZZER");
if (squelch && grpc_trace_fuzzer == nullptr) gpr_set_log_function(dont_log);
gpr_free(grpc_trace_fuzzer);
g_now = {1, 0, GPR_CLOCK_MONOTONIC};
grpc_core::TestOnlySetProcessEpoch(g_now);
gpr_now_impl = now_impl;

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

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

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

@ -30,7 +30,7 @@
#include <grpc/support/sync.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_util.h"
#include "src/core/lib/http/httpcli.h"

@ -35,9 +35,9 @@
#include <grpc/support/time.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/useful.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/executor.h"

@ -24,7 +24,7 @@
#include <grpc/support/log.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/check_gcp_environment.h"
#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h"
@ -60,9 +60,11 @@ static void read_target_service_accounts(
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (squelch && !grpc_core::GetEnv("GRPC_TRACE_FUZZER").has_value()) {
char* grpc_trace_fuzzer = gpr_getenv("GRPC_TRACE_FUZZER");
if (squelch && grpc_trace_fuzzer == nullptr) {
gpr_set_log_function(dont_log);
}
gpr_free(grpc_trace_fuzzer);
input_stream inp = {data, data + size};
grpc_init();
bool is_on_gcp = grpc_alts_is_running_on_gcp();

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

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

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

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

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

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

@ -30,7 +30,7 @@
#include "src/core/ext/xds/xds_bootstrap.h"
#include "src/core/ext/xds/xds_resource_type_impl.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/json/json.h"
#include "src/core/lib/json/json_object_loader.h"
@ -476,10 +476,10 @@ class XdsClientTest : public ::testing::Test {
class ScopedExperimentalEnvVar {
public:
explicit ScopedExperimentalEnvVar(const char* env_var) : env_var_(env_var) {
SetEnv(env_var_, "true");
gpr_setenv(env_var_, "true");
}
~ScopedExperimentalEnvVar() { UnsetEnv(env_var_); }
~ScopedExperimentalEnvVar() { gpr_unsetenv(env_var_); }
private:
const char* env_var_;

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

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

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

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

@ -54,8 +54,8 @@
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/tcp_client.h"
@ -242,7 +242,7 @@ class ClientLbEnd2endTest : public ::testing::Test {
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE
// Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0");
gpr_setenv("grpc_cfstream", "0");
#endif
}

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

@ -43,7 +43,7 @@
#include <grpcpp/server_builder.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 "test/core/util/port.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/lib/address_utils/parse_address.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/resolver/server_address.h"
@ -377,7 +377,7 @@ class GrpclbEnd2endTest : public ::testing::Test {
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE
// Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0");
gpr_setenv("grpc_cfstream", "0");
#endif
grpc_init();
}

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

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

@ -33,7 +33,7 @@
#include <grpcpp/server_builder.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/proto/grpc/testing/duplicate/echo_duplicate.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/lib/address_utils/parse_address.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/sockaddr.h"
@ -158,7 +158,7 @@ class FakeResolverResponseGeneratorWrapper {
class RlsEnd2endTest : public ::testing::Test {
protected:
static void SetUpTestSuite() {
grpc_core::SetEnv("GRPC_EXPERIMENTAL_ENABLE_RLS_LB_POLICY", "true");
gpr_setenv("GRPC_EXPERIMENTAL_ENABLE_RLS_LB_POLICY", "true");
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
grpc_core::CoreConfiguration::RegisterBuilder(
grpc_core::RegisterFixedAddressLoadBalancingPolicy);
@ -167,7 +167,7 @@ class RlsEnd2endTest : public ::testing::Test {
static void TearDownTestSuite() {
grpc_shutdown_blocking();
grpc_core::UnsetEnv("GRPC_EXPERIMENTAL_ENABLE_RLS_LB_POLICY");
gpr_unsetenv("GRPC_EXPERIMENTAL_ENABLE_RLS_LB_POLICY");
grpc_core::CoreConfiguration::Reset();
}

@ -30,7 +30,7 @@
#include <grpcpp/server_builder.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 "test/core/util/port.h"
#include "test/core/util/test_config.h"

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

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

@ -27,7 +27,7 @@
#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h"
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/resolver/server_address.h"
#include "src/proto/grpc/testing/xds/v3/aggregate_cluster.grpc.pb.h"
#include "test/cpp/end2end/connection_attempt_injector.h"
@ -784,7 +784,7 @@ int main(int argc, char** argv) {
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE
// Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0");
gpr_setenv("grpc_cfstream", "0");
#endif
grpc_init();
grpc::testing::ConnectionAttemptInjector::Init();

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

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

@ -69,10 +69,10 @@
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/time_precise.h"
#include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/gprpp/time.h"
@ -4047,7 +4047,7 @@ int main(int argc, char** argv) {
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE
// Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0");
gpr_setenv("grpc_cfstream", "0");
#endif
grpc::testing::FakeCertificateProvider::CertDataMapWrapper cert_data_map_1;
grpc::testing::g_fake1_cert_data_map = &cert_data_map_1;

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

@ -33,7 +33,7 @@
#include <grpcpp/client_context.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/security_connector/ssl_utils.h"
#include "src/cpp/server/secure_server_credentials.h"
@ -466,10 +466,10 @@ class XdsEnd2endTest : public ::testing::TestWithParam<XdsTestType> {
class ScopedExperimentalEnvVar {
public:
explicit ScopedExperimentalEnvVar(const char* env_var) : env_var_(env_var) {
grpc_core::SetEnv(env_var_, "true");
gpr_setenv(env_var_, "true");
}
~ScopedExperimentalEnvVar() { grpc_core::UnsetEnv(env_var_); }
~ScopedExperimentalEnvVar() { gpr_unsetenv(env_var_); }
private:
const char* env_var_;

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

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

@ -28,7 +28,7 @@
#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h"
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gpr/env.h"
#include "src/proto/grpc/testing/xds/v3/aggregate_cluster.grpc.pb.h"
#include "src/proto/grpc/testing/xds/v3/cluster.grpc.pb.h"
#include "test/cpp/end2end/connection_attempt_injector.h"
@ -1274,7 +1274,7 @@ int main(int argc, char** argv) {
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE
// Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0");
gpr_setenv("grpc_cfstream", "0");
#endif
grpc_init();
grpc::testing::ConnectionAttemptInjector::Init();

@ -22,7 +22,7 @@
#include "absl/strings/str_cat.h"
#include "src/core/ext/filters/client_channel/backup_poller.h"
#include "src/core/lib/gprpp/env.h"
#include "src/core/lib/gpr/env.h"
#include "src/proto/grpc/lookup/v1/rls.grpc.pb.h"
#include "src/proto/grpc/lookup/v1/rls.pb.h"
#include "src/proto/grpc/lookup/v1/rls_config.pb.h"
@ -354,7 +354,7 @@ int main(int argc, char** argv) {
GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
#if TARGET_OS_IPHONE
// Workaround Apple CFStream bug
grpc_core::SetEnv("grpc_cfstream", "0");
gpr_setenv("grpc_cfstream", "0");
#endif
grpc_init();
const auto result = RUN_ALL_TESTS();

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

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

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

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

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

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

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

@ -30,7 +30,7 @@
#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/cpp/util/subprocess.h"
@ -101,7 +101,7 @@ int main(int argc, char** argv) {
first = false;
}
grpc_core::SetEnv("QPS_WORKERS", env.str().c_str());
gpr_setenv("QPS_WORKERS", env.str().c_str());
std::vector<std::string> args = {bin_dir + "/qps_json_driver"};
for (int i = 1; i < argc; i++) {
args.push_back(argv[i]);

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

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

@ -1991,6 +1991,10 @@ src/core/lib/gpr/cpu_iphone.cc \
src/core/lib/gpr/cpu_linux.cc \
src/core/lib/gpr/cpu_posix.cc \
src/core/lib/gpr/cpu_windows.cc \
src/core/lib/gpr/env.h \
src/core/lib/gpr/env_linux.cc \
src/core/lib/gpr/env_posix.cc \
src/core/lib/gpr/env_windows.cc \
src/core/lib/gpr/log.cc \
src/core/lib/gpr/log_android.cc \
src/core/lib/gpr/log_linux.cc \
@ -2027,10 +2031,6 @@ src/core/lib/gprpp/construct_destruct.h \
src/core/lib/gprpp/cpp_impl_of.h \
src/core/lib/gprpp/debug_location.h \
src/core/lib/gprpp/dual_ref_counted.h \
src/core/lib/gprpp/env.h \
src/core/lib/gprpp/env_linux.cc \
src/core/lib/gprpp/env_posix.cc \
src/core/lib/gprpp/env_windows.cc \
src/core/lib/gprpp/examine_stack.cc \
src/core/lib/gprpp/examine_stack.h \
src/core/lib/gprpp/fork.cc \

@ -1782,6 +1782,10 @@ src/core/lib/gpr/cpu_iphone.cc \
src/core/lib/gpr/cpu_linux.cc \
src/core/lib/gpr/cpu_posix.cc \
src/core/lib/gpr/cpu_windows.cc \
src/core/lib/gpr/env.h \
src/core/lib/gpr/env_linux.cc \
src/core/lib/gpr/env_posix.cc \
src/core/lib/gpr/env_windows.cc \
src/core/lib/gpr/log.cc \
src/core/lib/gpr/log_android.cc \
src/core/lib/gpr/log_linux.cc \
@ -1819,10 +1823,6 @@ src/core/lib/gprpp/construct_destruct.h \
src/core/lib/gprpp/cpp_impl_of.h \
src/core/lib/gprpp/debug_location.h \
src/core/lib/gprpp/dual_ref_counted.h \
src/core/lib/gprpp/env.h \
src/core/lib/gprpp/env_linux.cc \
src/core/lib/gprpp/env_posix.cc \
src/core/lib/gprpp/env_windows.cc \
src/core/lib/gprpp/examine_stack.cc \
src/core/lib/gprpp/examine_stack.h \
src/core/lib/gprpp/fork.cc \

Loading…
Cancel
Save