[tsan] Threadsafe strerror implementation (#31167)

* fix

* spread

* fix

* Automated change: Fix sanity tests

* fix

* remove unnecessary .c_strs

* lashes

* fix

* Automated change: Fix sanity tests

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/31187/head^2
Craig Tiller 2 years ago committed by GitHub
parent d84846646d
commit db5fe72da9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      BUILD
  2. 2
      CMakeLists.txt
  3. 1
      Makefile
  4. 3
      build_autogenerated.yaml
  5. 1
      config.m4
  6. 1
      config.w32
  7. 2
      gRPC-C++.podspec
  8. 3
      gRPC-Core.podspec
  9. 2
      grpc.gemspec
  10. 1
      grpc.gyp
  11. 2
      package.xml
  12. 10
      src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc
  13. 4
      src/core/lib/event_engine/posix_engine/ev_poll_posix.cc
  14. 6
      src/core/lib/event_engine/posix_engine/internal_errqueue.cc
  15. 69
      src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc
  16. 14
      src/core/lib/event_engine/posix_engine/wakeup_fd_eventfd.cc
  17. 10
      src/core/lib/event_engine/posix_engine/wakeup_fd_pipe.cc
  18. 8
      src/core/lib/gpr/cpu_linux.cc
  19. 5
      src/core/lib/gpr/tmpfile_posix.cc
  20. 9
      src/core/lib/gprpp/stat_posix.cc
  21. 5
      src/core/lib/gprpp/stat_windows.cc
  22. 41
      src/core/lib/gprpp/strerror.cc
  23. 29
      src/core/lib/gprpp/strerror.h
  24. 21
      src/core/lib/iomgr/error.cc
  25. 7
      src/core/lib/iomgr/ev_epoll1_linux.cc
  26. 4
      src/core/lib/iomgr/internal_errqueue.cc
  27. 5
      src/core/lib/iomgr/socket_utils_common_posix.cc
  28. 1
      src/core/lib/iomgr/socket_utils_posix.cc
  29. 3
      src/core/lib/iomgr/tcp_posix.cc
  30. 10
      src/core/lib/iomgr/tcp_server_posix.cc
  31. 1
      src/core/lib/iomgr/wakeup_fd_eventfd.cc
  32. 4
      src/core/lib/iomgr/wakeup_fd_pipe.cc
  33. 1
      src/python/grpcio/grpc_core_dependencies.py
  34. 11
      test/core/event_engine/posix/event_poller_posix_test.cc
  35. 44
      test/core/event_engine/test_suite/oracle_event_engine_posix.cc
  36. 6
      test/core/iomgr/fd_posix_test.cc
  37. 3
      test/core/iomgr/tcp_server_posix_test.cc
  38. 43
      test/core/network_benchmarks/low_level_ping_pong.cc
  39. 8
      test/core/util/subprocess_posix.cc
  40. 2
      tools/doxygen/Doxyfile.c++.internal
  41. 2
      tools/doxygen/Doxyfile.core.internal

22
BUILD

@ -1126,6 +1126,7 @@ grpc_cc_library(
"examine_stack",
"gpr_atm",
"no_destruct",
"strerror",
"tchar",
"useful",
],
@ -2190,6 +2191,7 @@ grpc_cc_library(
"slice",
"slice_refcount",
"status_helper",
"strerror",
"useful",
],
)
@ -2625,6 +2627,7 @@ grpc_cc_library(
"gpr",
"iomgr_port",
"posix_event_engine_wakeup_fd_posix",
"strerror",
],
)
@ -2645,6 +2648,7 @@ grpc_cc_library(
"gpr",
"iomgr_port",
"posix_event_engine_wakeup_fd_posix",
"strerror",
],
)
@ -2697,6 +2701,7 @@ grpc_cc_library(
"posix_event_engine_lockfree_event",
"posix_event_engine_wakeup_fd_posix",
"posix_event_engine_wakeup_fd_posix_default",
"strerror",
],
)
@ -2729,6 +2734,7 @@ grpc_cc_library(
"posix_event_engine_event_poller",
"posix_event_engine_wakeup_fd_posix",
"posix_event_engine_wakeup_fd_posix_default",
"strerror",
"time",
],
)
@ -2761,6 +2767,7 @@ grpc_cc_library(
deps = [
"gpr",
"iomgr_port",
"strerror",
],
)
@ -2797,7 +2804,6 @@ grpc_cc_library(
"absl/container:flat_hash_map",
"absl/functional:any_invocable",
"absl/hash",
"absl/memory",
"absl/meta:type_traits",
"absl/status",
"absl/status:statusor",
@ -2872,6 +2878,7 @@ grpc_cc_library(
"resource_quota",
"socket_mutator",
"status_helper",
"strerror",
"useful",
],
)
@ -3483,6 +3490,7 @@ grpc_cc_library(
"slice_refcount",
"sockaddr_utils",
"status_helper",
"strerror",
"thread_quota",
"time",
"transport_fwd",
@ -6242,6 +6250,18 @@ grpc_cc_library(
],
)
grpc_cc_library(
name = "strerror",
srcs = [
"src/core/lib/gprpp/strerror.cc",
],
hdrs = [
"src/core/lib/gprpp/strerror.h",
],
external_deps = ["absl/strings:str_format"],
deps = ["gpr_platform"],
)
grpc_cc_library(
name = "grpc_tls_credentials",
srcs = [

2
CMakeLists.txt generated

@ -1573,6 +1573,7 @@ add_library(gpr
src/core/lib/gprpp/mpscq.cc
src/core/lib/gprpp/stat_posix.cc
src/core/lib/gprpp/stat_windows.cc
src/core/lib/gprpp/strerror.cc
src/core/lib/gprpp/tchar.cc
src/core/lib/gprpp/thd_posix.cc
src/core/lib/gprpp/thd_windows.cc
@ -14618,7 +14619,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
target_link_libraries(posix_endpoint_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
absl::cleanup
grpc_test_util
)

1
Makefile generated

@ -877,6 +877,7 @@ LIBGPR_SRC = \
src/core/lib/gprpp/mpscq.cc \
src/core/lib/gprpp/stat_posix.cc \
src/core/lib/gprpp/stat_windows.cc \
src/core/lib/gprpp/strerror.cc \
src/core/lib/gprpp/tchar.cc \
src/core/lib/gprpp/thd_posix.cc \
src/core/lib/gprpp/thd_windows.cc \

@ -216,6 +216,7 @@ libs:
- src/core/lib/gprpp/mpscq.h
- src/core/lib/gprpp/no_destruct.h
- src/core/lib/gprpp/stat.h
- src/core/lib/gprpp/strerror.h
- src/core/lib/gprpp/sync.h
- src/core/lib/gprpp/tchar.h
- src/core/lib/gprpp/thd.h
@ -258,6 +259,7 @@ libs:
- src/core/lib/gprpp/mpscq.cc
- src/core/lib/gprpp/stat_posix.cc
- src/core/lib/gprpp/stat_windows.cc
- src/core/lib/gprpp/strerror.cc
- src/core/lib/gprpp/tchar.cc
- src/core/lib/gprpp/thd_posix.cc
- src/core/lib/gprpp/thd_windows.cc
@ -8314,7 +8316,6 @@ targets:
- test/core/event_engine/test_suite/event_engine_test_utils.cc
- test/core/event_engine/test_suite/oracle_event_engine_posix.cc
deps:
- absl/cleanup:cleanup
- grpc_test_util
platforms:
- linux

1
config.m4 generated

@ -530,6 +530,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/gprpp/stat_posix.cc \
src/core/lib/gprpp/stat_windows.cc \
src/core/lib/gprpp/status_helper.cc \
src/core/lib/gprpp/strerror.cc \
src/core/lib/gprpp/tchar.cc \
src/core/lib/gprpp/thd_posix.cc \
src/core/lib/gprpp/thd_windows.cc \

1
config.w32 generated

@ -496,6 +496,7 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\gprpp\\stat_posix.cc " +
"src\\core\\lib\\gprpp\\stat_windows.cc " +
"src\\core\\lib\\gprpp\\status_helper.cc " +
"src\\core\\lib\\gprpp\\strerror.cc " +
"src\\core\\lib\\gprpp\\tchar.cc " +
"src\\core\\lib\\gprpp\\thd_posix.cc " +
"src\\core\\lib\\gprpp\\thd_windows.cc " +

2
gRPC-C++.podspec generated

@ -741,6 +741,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/sorted_pack.h',
'src/core/lib/gprpp/stat.h',
'src/core/lib/gprpp/status_helper.h',
'src/core/lib/gprpp/strerror.h',
'src/core/lib/gprpp/sync.h',
'src/core/lib/gprpp/table.h',
'src/core/lib/gprpp/tchar.h',
@ -1607,6 +1608,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/sorted_pack.h',
'src/core/lib/gprpp/stat.h',
'src/core/lib/gprpp/status_helper.h',
'src/core/lib/gprpp/strerror.h',
'src/core/lib/gprpp/sync.h',
'src/core/lib/gprpp/table.h',
'src/core/lib/gprpp/tchar.h',

3
gRPC-Core.podspec generated

@ -1168,6 +1168,8 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/stat_windows.cc',
'src/core/lib/gprpp/status_helper.cc',
'src/core/lib/gprpp/status_helper.h',
'src/core/lib/gprpp/strerror.cc',
'src/core/lib/gprpp/strerror.h',
'src/core/lib/gprpp/sync.h',
'src/core/lib/gprpp/table.h',
'src/core/lib/gprpp/tchar.cc',
@ -2237,6 +2239,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/sorted_pack.h',
'src/core/lib/gprpp/stat.h',
'src/core/lib/gprpp/status_helper.h',
'src/core/lib/gprpp/strerror.h',
'src/core/lib/gprpp/sync.h',
'src/core/lib/gprpp/table.h',
'src/core/lib/gprpp/tchar.h',

2
grpc.gemspec generated

@ -1079,6 +1079,8 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gprpp/stat_windows.cc )
s.files += %w( src/core/lib/gprpp/status_helper.cc )
s.files += %w( src/core/lib/gprpp/status_helper.h )
s.files += %w( src/core/lib/gprpp/strerror.cc )
s.files += %w( src/core/lib/gprpp/strerror.h )
s.files += %w( src/core/lib/gprpp/sync.h )
s.files += %w( src/core/lib/gprpp/table.h )
s.files += %w( src/core/lib/gprpp/tchar.cc )

1
grpc.gyp generated

@ -345,6 +345,7 @@
'src/core/lib/gprpp/mpscq.cc',
'src/core/lib/gprpp/stat_posix.cc',
'src/core/lib/gprpp/stat_windows.cc',
'src/core/lib/gprpp/strerror.cc',
'src/core/lib/gprpp/tchar.cc',
'src/core/lib/gprpp/thd_posix.cc',
'src/core/lib/gprpp/thd_windows.cc',

2
package.xml generated

@ -1061,6 +1061,8 @@
<file baseinstalldir="/" name="src/core/lib/gprpp/stat_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/status_helper.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/status_helper.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/strerror.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/strerror.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/sync.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/table.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/tchar.cc" role="src" />

@ -36,7 +36,6 @@
#ifdef GRPC_LINUX_EPOLL
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <unistd.h>
@ -49,6 +48,7 @@
#include "src/core/lib/event_engine/posix_engine/wakeup_fd_posix.h"
#include "src/core/lib/event_engine/posix_engine/wakeup_fd_posix_default.h"
#include "src/core/lib/gprpp/fork.h"
#include "src/core/lib/gprpp/strerror.h"
using ::grpc_event_engine::posix_engine::LockfreeEvent;
using ::grpc_event_engine::posix_engine::WakeupFd;
@ -337,7 +337,8 @@ void Epoll1EventHandle::HandleShutdownInternal(absl::Status why,
epoll_event phony_event;
if (epoll_ctl(poller_->g_epoll_set_.epfd, EPOLL_CTL_DEL, fd_,
&phony_event) != 0) {
gpr_log(GPR_ERROR, "epoll_ctl failed: %s", strerror(errno));
gpr_log(GPR_ERROR, "epoll_ctl failed: %s",
grpc_core::StrError(errno).c_str());
}
}
write_closure_->SetShutdown(why);
@ -408,7 +409,8 @@ EventHandle* Epoll1Poller::CreateHandle(int fd, absl::string_view /*name*/,
ev.data.ptr = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(new_handle) |
(track_err ? 1 : 0));
if (epoll_ctl(g_epoll_set_.epfd, EPOLL_CTL_ADD, fd, &ev) != 0) {
gpr_log(GPR_ERROR, "epoll_ctl failed: %s", strerror(errno));
gpr_log(GPR_ERROR, "epoll_ctl failed: %s",
grpc_core::StrError(errno).c_str());
}
return new_handle;
@ -469,7 +471,7 @@ int Epoll1Poller::DoEpollWait(EventEngine::Duration timeout) {
if (r < 0) {
gpr_log(GPR_ERROR,
"(event_engine) Epoll1Poller:%p encountered epoll_wait error: %s",
this, strerror(errno));
this, grpc_core::StrError(errno).c_str());
GPR_ASSERT(false);
}
g_epoll_set_.num_events = r;

@ -46,7 +46,6 @@
#include <errno.h>
#include <limits.h>
#include <poll.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
@ -60,6 +59,7 @@
#include "src/core/lib/event_engine/time_util.h"
#include "src/core/lib/gprpp/fork.h"
#include "src/core/lib/gprpp/global_config.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/gprpp/time.h"
GPR_GLOBAL_CONFIG_DECLARE_STRING(grpc_poll_strategy);
@ -719,7 +719,7 @@ Poller::WorkResult PollPoller::Work(
// Abort fail here.
gpr_log(GPR_ERROR,
"(event_engine) PollPoller:%p encountered poll error: %s", this,
strerror(errno));
grpc_core::StrError(errno).c_str());
GPR_ASSERT(false);
}

@ -16,6 +16,8 @@
#include "src/core/lib/event_engine/posix_engine/internal_errqueue.h"
#include <string>
#include <grpc/support/log.h>
#include "src/core/lib/iomgr/port.h"
@ -30,6 +32,8 @@
#include <cstddef>
#include "src/core/lib/gprpp/strerror.h"
namespace grpc_event_engine {
namespace posix_engine {
@ -48,7 +52,7 @@ bool KernelSupportsErrqueue() {
// least 4.0.0
struct utsname buffer;
if (uname(&buffer) != 0) {
gpr_log(GPR_ERROR, "uname: %s", strerror(errno));
gpr_log(GPR_ERROR, "uname: %s", grpc_core::StrError(errno).c_str());
return false;
}
char* release = buffer.release;

@ -55,6 +55,7 @@
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/status_helper.h"
#include "src/core/lib/gprpp/strerror.h"
#ifdef GRPC_HAVE_UNIX_SOCKET
#include <sys/un.h>
@ -92,7 +93,7 @@ absl::Status ErrorForFd(
if (fd >= 0) return absl::OkStatus();
const char* addr_str = reinterpret_cast<const char*>(addr.address());
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("socket: ", strerror(errno),
absl::StrCat("socket: ", grpc_core::StrError(errno),
std::string(addr_str, addr.size())));
}
@ -359,7 +360,7 @@ absl::StatusOr<int> PosixSocketWrapper::SetSocketRcvLowat(int bytes) {
if (setsockopt(fd_, SOL_SOCKET, SO_RCVLOWAT, &bytes, sizeof(bytes)) != 0) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("setsockopt(SO_RCVLOWAT): ", strerror(errno)));
absl::StrCat("setsockopt(SO_RCVLOWAT): ", grpc_core::StrError(errno)));
}
return bytes;
}
@ -372,13 +373,13 @@ absl::Status PosixSocketWrapper::SetSocketZeroCopy() {
if (err != 0) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("setsockopt(SO_ZEROCOPY): ", strerror(errno)));
absl::StrCat("setsockopt(SO_ZEROCOPY): ", grpc_core::StrError(errno)));
}
return absl::OkStatus();
#else
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("setsockopt(SO_ZEROCOPY): ", strerror(ENOSYS)));
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("setsockopt(SO_ZEROCOPY): ",
grpc_core::StrError(ENOSYS).c_str()));
#endif
}
@ -387,7 +388,7 @@ absl::Status PosixSocketWrapper::SetSocketNonBlocking(int non_blocking) {
int oldflags = fcntl(fd_, F_GETFL, 0);
if (oldflags < 0) {
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("fcntl: ", strerror(errno)));
absl::StrCat("fcntl: ", grpc_core::StrError(errno)));
}
if (non_blocking) {
@ -398,7 +399,7 @@ absl::Status PosixSocketWrapper::SetSocketNonBlocking(int non_blocking) {
if (fcntl(fd_, F_SETFL, oldflags) != 0) {
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("fcntl: ", strerror(errno)));
absl::StrCat("fcntl: ", grpc_core::StrError(errno)));
}
return absl::OkStatus();
@ -412,12 +413,12 @@ absl::Status PosixSocketWrapper::SetSocketNoSigpipeIfPossible() {
if (0 != setsockopt(fd_, SOL_SOCKET, SO_NOSIGPIPE, &val, sizeof(val))) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("setsockopt(SO_NOSIGPIPE): ", strerror(errno)));
absl::StrCat("setsockopt(SO_NOSIGPIPE): ", grpc_core::StrError(errno)));
}
if (0 != getsockopt(fd_, SOL_SOCKET, SO_NOSIGPIPE, &newval, &intlen)) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("getsockopt(SO_NOSIGPIPE): ", strerror(errno)));
absl::StrCat("getsockopt(SO_NOSIGPIPE): ", grpc_core::StrError(errno)));
}
if ((newval != 0) != (val != 0)) {
return absl::Status(absl::StatusCode::kInternal,
@ -434,7 +435,7 @@ absl::Status PosixSocketWrapper::SetSocketIpPktInfoIfPossible() {
sizeof(get_local_ip))) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("setsockopt(IP_PKTINFO): ", strerror(errno)));
absl::StrCat("setsockopt(IP_PKTINFO): ", grpc_core::StrError(errno)));
}
#endif
return absl::OkStatus();
@ -445,9 +446,9 @@ absl::Status PosixSocketWrapper::SetSocketIpv6RecvPktInfoIfPossible() {
int get_local_ip = 1;
if (0 != setsockopt(fd_, IPPROTO_IPV6, IPV6_RECVPKTINFO, &get_local_ip,
sizeof(get_local_ip))) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("setsockopt(IPV6_RECVPKTINFO): ", strerror(errno)));
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("setsockopt(IPV6_RECVPKTINFO): ",
grpc_core::StrError(errno)));
}
#endif
return absl::OkStatus();
@ -457,18 +458,18 @@ absl::Status PosixSocketWrapper::SetSocketSndBuf(int buffer_size_bytes) {
return 0 == setsockopt(fd_, SOL_SOCKET, SO_SNDBUF, &buffer_size_bytes,
sizeof(buffer_size_bytes))
? absl::OkStatus()
: absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("setsockopt(SO_SNDBUF): ", strerror(errno)));
: absl::Status(absl::StatusCode::kInternal,
absl::StrCat("setsockopt(SO_SNDBUF): ",
grpc_core::StrError(errno)));
}
absl::Status PosixSocketWrapper::SetSocketRcvBuf(int buffer_size_bytes) {
return 0 == setsockopt(fd_, SOL_SOCKET, SO_RCVBUF, &buffer_size_bytes,
sizeof(buffer_size_bytes))
? absl::OkStatus()
: absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("setsockopt(SO_RCVBUF): ", strerror(errno)));
: absl::Status(absl::StatusCode::kInternal,
absl::StrCat("setsockopt(SO_RCVBUF): ",
grpc_core::StrError(errno)));
}
// Set a socket to close on exec
@ -476,7 +477,7 @@ absl::Status PosixSocketWrapper::SetSocketCloexec(int close_on_exec) {
int oldflags = fcntl(fd_, F_GETFD, 0);
if (oldflags < 0) {
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("fcntl: ", strerror(errno)));
absl::StrCat("fcntl: ", grpc_core::StrError(errno)));
}
if (close_on_exec) {
@ -487,7 +488,7 @@ absl::Status PosixSocketWrapper::SetSocketCloexec(int close_on_exec) {
if (fcntl(fd_, F_SETFD, oldflags) != 0) {
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("fcntl: ", strerror(errno)));
absl::StrCat("fcntl: ", grpc_core::StrError(errno)));
}
return absl::OkStatus();
@ -501,12 +502,12 @@ absl::Status PosixSocketWrapper::SetSocketReuseAddr(int reuse) {
if (0 != setsockopt(fd_, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val))) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("setsockopt(SO_REUSEADDR): ", strerror(errno)));
absl::StrCat("setsockopt(SO_REUSEADDR): ", grpc_core::StrError(errno)));
}
if (0 != getsockopt(fd_, SOL_SOCKET, SO_REUSEADDR, &newval, &intlen)) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("getsockopt(SO_REUSEADDR): ", strerror(errno)));
absl::StrCat("getsockopt(SO_REUSEADDR): ", grpc_core::StrError(errno)));
}
if ((newval != 0) != val) {
return absl::Status(absl::StatusCode::kInternal,
@ -528,12 +529,12 @@ absl::Status PosixSocketWrapper::SetSocketReusePort(int reuse) {
if (0 != setsockopt(fd_, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val))) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("setsockopt(SO_REUSEPORT): ", strerror(errno)));
absl::StrCat("setsockopt(SO_REUSEPORT): ", grpc_core::StrError(errno)));
}
if (0 != getsockopt(fd_, SOL_SOCKET, SO_REUSEPORT, &newval, &intlen)) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("getsockopt(SO_REUSEPORT): ", strerror(errno)));
absl::StrCat("getsockopt(SO_REUSEPORT): ", grpc_core::StrError(errno)));
}
if ((newval != 0) != val) {
return absl::Status(absl::StatusCode::kInternal,
@ -571,12 +572,12 @@ absl::Status PosixSocketWrapper::SetSocketLowLatency(int low_latency) {
if (0 != setsockopt(fd_, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val))) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("setsockopt(TCP_NODELAY): ", strerror(errno)));
absl::StrCat("setsockopt(TCP_NODELAY): ", grpc_core::StrError(errno)));
}
if (0 != getsockopt(fd_, IPPROTO_TCP, TCP_NODELAY, &newval, &intlen)) {
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("getsockopt(TCP_NODELAY): ", strerror(errno)));
absl::StrCat("getsockopt(TCP_NODELAY): ", grpc_core::StrError(errno)));
}
if ((newval != 0) != val) {
return absl::Status(absl::StatusCode::kInternal,
@ -659,11 +660,13 @@ void PosixSocketWrapper::TrySetSocketTcpUserTimeout(
if (g_socket_supports_tcp_user_timeout.load() > 0) {
if (0 != setsockopt(fd_, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout,
sizeof(timeout))) {
gpr_log(GPR_ERROR, "setsockopt(TCP_USER_TIMEOUT) %s", strerror(errno));
gpr_log(GPR_ERROR, "setsockopt(TCP_USER_TIMEOUT) %s",
grpc_core::StrError(errno).c_str());
return;
}
if (0 != getsockopt(fd_, IPPROTO_TCP, TCP_USER_TIMEOUT, &newval, &len)) {
gpr_log(GPR_ERROR, "getsockopt(TCP_USER_TIMEOUT) %s", strerror(errno));
gpr_log(GPR_ERROR, "getsockopt(TCP_USER_TIMEOUT) %s",
grpc_core::StrError(errno).c_str());
return;
}
if (newval != timeout) {
@ -728,7 +731,8 @@ PosixSocketWrapper::LocalAddress() {
EventEngine::ResolvedAddress addr;
socklen_t len = EventEngine::ResolvedAddress::MAX_SIZE_BYTES;
if (getsockname(fd_, const_cast<sockaddr*>(addr.address()), &len) < 0) {
return absl::InternalError(absl::StrCat("getsockname:", strerror(errno)));
return absl::InternalError(
absl::StrCat("getsockname:", grpc_core::StrError(errno)));
}
return addr;
}
@ -737,7 +741,8 @@ absl::StatusOr<EventEngine::ResolvedAddress> PosixSocketWrapper::PeerAddress() {
EventEngine::ResolvedAddress addr;
socklen_t len = EventEngine::ResolvedAddress::MAX_SIZE_BYTES;
if (getpeername(fd_, const_cast<sockaddr*>(addr.address()), &len) < 0) {
return absl::InternalError(absl::StrCat("getpeername:", strerror(errno)));
return absl::InternalError(
absl::StrCat("getpeername:", grpc_core::StrError(errno)));
}
return addr;
}

@ -26,7 +26,6 @@
#ifdef GRPC_LINUX_EVENTFD
#include <errno.h>
#include <string.h>
#include <sys/eventfd.h>
#include <unistd.h>
@ -34,6 +33,7 @@
#endif
#include "src/core/lib/event_engine/posix_engine/wakeup_fd_eventfd.h"
#include "src/core/lib/gprpp/strerror.h"
namespace grpc_event_engine {
namespace posix_engine {
@ -45,7 +45,7 @@ absl::Status EventFdWakeupFd::Init() {
int write_fd = -1;
if (read_fd < 0) {
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("eventfd: ", strerror(errno)));
absl::StrCat("eventfd: ", grpc_core::StrError(errno)));
}
SetWakeupFds(read_fd, write_fd);
return absl::OkStatus();
@ -58,8 +58,9 @@ absl::Status EventFdWakeupFd::ConsumeWakeup() {
err = eventfd_read(ReadFd(), &value);
} while (err < 0 && errno == EINTR);
if (err < 0 && errno != EAGAIN) {
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("eventfd_read: ", strerror(errno)));
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("eventfd_read: ", grpc_core::StrError(errno)));
}
return absl::OkStatus();
}
@ -70,8 +71,9 @@ absl::Status EventFdWakeupFd::Wakeup() {
err = eventfd_write(ReadFd(), 1);
} while (err < 0 && errno == EINTR);
if (err < 0) {
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("eventfd_write: ", strerror(errno)));
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("eventfd_write: ", grpc_core::StrError(errno)));
}
return absl::OkStatus();
}

@ -27,13 +27,13 @@
#ifdef GRPC_POSIX_WAKEUP_FD
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include "src/core/lib/event_engine/posix_engine/wakeup_fd_posix.h"
#endif
#include "src/core/lib/event_engine/posix_engine/wakeup_fd_pipe.h"
#include "src/core/lib/gprpp/strerror.h"
namespace grpc_event_engine {
namespace posix_engine {
@ -46,14 +46,14 @@ absl::Status SetSocketNonBlocking(int fd) {
int oldflags = fcntl(fd, F_GETFL, 0);
if (oldflags < 0) {
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("fcntl: ", strerror(errno)));
absl::StrCat("fcntl: ", grpc_core::StrError(errno)));
}
oldflags |= O_NONBLOCK;
if (fcntl(fd, F_SETFL, oldflags) != 0) {
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("fcntl: ", strerror(errno)));
absl::StrCat("fcntl: ", grpc_core::StrError(errno)));
}
return absl::OkStatus();
@ -65,7 +65,7 @@ absl::Status PipeWakeupFd::Init() {
int r = pipe(pipefd);
if (0 != r) {
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("pipe: ", strerror(errno)));
absl::StrCat("pipe: ", grpc_core::StrError(errno)));
}
auto status = SetSocketNonBlocking(pipefd[0]);
if (!status.ok()) return status;
@ -90,7 +90,7 @@ absl::Status PipeWakeupFd::ConsumeWakeup() {
continue;
default:
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("read: ", strerror(errno)));
absl::StrCat("read: ", grpc_core::StrError(errno)));
}
}
}

@ -33,12 +33,15 @@
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include "src/core/lib/gprpp/strerror.h"
static int ncpus = 0;
static void init_num_cpus() {
#ifndef GPR_MUSL_LIBC_COMPAT
if (sched_getcpu() < 0) {
gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno));
gpr_log(GPR_ERROR, "Error determining current CPU: %s\n",
grpc_core::StrError(errno).c_str());
ncpus = 1;
return;
}
@ -68,7 +71,8 @@ unsigned gpr_cpu_current_cpu(void) {
}
int cpu = sched_getcpu();
if (cpu < 0) {
gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno));
gpr_log(GPR_ERROR, "Error determining current CPU: %s\n",
grpc_core::StrError(errno).c_str());
return 0;
}
if (static_cast<unsigned>(cpu) >= gpr_cpu_num_cores()) {

@ -31,6 +31,7 @@
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/strerror.h"
FILE* gpr_tmpfile(const char* prefix, char** tmp_filename) {
FILE* result = nullptr;
@ -45,13 +46,13 @@ FILE* gpr_tmpfile(const char* prefix, char** tmp_filename) {
fd = mkstemp(filename_template);
if (fd == -1) {
gpr_log(GPR_ERROR, "mkstemp failed for filename_template %s with error %s.",
filename_template, strerror(errno));
filename_template, grpc_core::StrError(errno).c_str());
goto end;
}
result = fdopen(fd, "w+");
if (result == nullptr) {
gpr_log(GPR_ERROR, "Could not open file %s from fd %d (error = %s).",
filename_template, fd, strerror(errno));
filename_template, fd, grpc_core::StrError(errno).c_str());
unlink(filename_template);
close(fd);
goto end;

@ -16,9 +16,9 @@
#include <grpc/support/port_platform.h>
// IWYU pragma: no_include <bits/struct_stat.h>
#include <string>
#include <string.h>
// IWYU pragma: no_include <bits/struct_stat.h>
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
@ -31,6 +31,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/stat.h"
#include "src/core/lib/gprpp/strerror.h"
namespace grpc_core {
@ -39,9 +40,9 @@ absl::Status GetFileModificationTime(const char* filename, time_t* timestamp) {
GPR_ASSERT(timestamp != nullptr);
struct stat buf;
if (stat(filename, &buf) != 0) {
const char* error_msg = strerror(errno);
std::string error_msg = StrError(errno);
gpr_log(GPR_ERROR, "stat failed for filename %s with error %s.", filename,
error_msg);
error_msg.c_str());
return absl::Status(absl::StatusCode::kInternal, error_msg);
}
// Last file/directory modification time.

@ -25,6 +25,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/stat.h"
#include "src/core/lib/gprpp/strerror.h"
namespace grpc_core {
@ -33,9 +34,9 @@ absl::Status GetFileModificationTime(const char* filename, time_t* timestamp) {
GPR_ASSERT(timestamp != nullptr);
struct _stat buf;
if (_stat(filename, &buf) != 0) {
const char* error_msg = strerror(errno);
std::string error_msg = StrError(errno);
gpr_log(GPR_ERROR, "_stat failed for filename %s with error %s.", filename,
error_msg);
error_msg.c_str());
return absl::Status(absl::StatusCode::kInternal, error_msg);
}
// Last file/directory modification time.

@ -0,0 +1,41 @@
// Copyright 2022 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <grpc/support/port_platform.h>
#include "src/core/lib/gprpp/strerror.h"
#include <string.h>
#include "absl/strings/str_format.h"
namespace grpc_core {
#ifdef GPR_WINDOWS
std::string StrError(int err) { return strerror(err); }
#else
std::string StrError(int err) {
struct Finish {
static std::string Run(char* buf, int err, int r) {
if (r == 0) return buf;
return absl::StrFormat("strerror_r(%d) failed: %d", err, r);
}
static std::string Run(char*, int, const char* r) { return r; }
};
char buf[256];
return Finish::Run(buf, err, strerror_r(err, buf, sizeof(buf)));
}
#endif // !GPR_WINDOWS
} // namespace grpc_core

@ -0,0 +1,29 @@
// Copyright 2022 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_CORE_LIB_GPRPP_STRERROR_H
#define GRPC_CORE_LIB_GPRPP_STRERROR_H
#include <grpc/support/port_platform.h>
#include <string>
namespace grpc_core {
// Returns a string describing the posix error code.
std::string StrError(int err);
} // namespace grpc_core
#endif // GRPC_CORE_LIB_GPRPP_STRERROR_H

@ -35,6 +35,7 @@
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/slice/slice_internal.h"
grpc_core::DebugOnlyTraceFlag grpc_trace_error_refcount(false,
@ -67,27 +68,9 @@ std::string grpc_error_std_string(absl::Status error) {
return grpc_core::StatusToString(error);
}
namespace {
#ifdef GPR_WINDOWS
std::string StrError(int err) { return strerror(err); }
#else
std::string StrError(int err) {
struct Finish {
static std::string Run(char* buf, int err, int r) {
if (r == 0) return buf;
return absl::StrFormat("strerror_r(%d) failed: %d", err, r);
}
static std::string Run(char*, int, const char* r) { return r; }
};
char buf[256];
return Finish::Run(buf, err, strerror_r(err, buf, sizeof(buf)));
}
#endif // !GPR_WINDOWS
} // namespace
absl::Status grpc_os_error(const grpc_core::DebugLocation& location, int err,
const char* call_name) {
auto err_string = StrError(err);
auto err_string = grpc_core::StrError(err);
absl::Status s =
StatusCreate(absl::StatusCode::kUnknown, err_string, location, {});
grpc_core::StatusSetInt(&s, grpc_core::StatusIntProperty::kErrorNo, err);

@ -50,6 +50,7 @@
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/iomgr/block_annotate.h"
#include "src/core/lib/iomgr/ev_epoll1_linux.h"
#include "src/core/lib/iomgr/ev_posix.h"
@ -368,7 +369,8 @@ static grpc_fd* fd_create(int fd, const char* name, bool track_err) {
ev.data.ptr = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(new_fd) |
(track_err ? 1 : 0));
if (epoll_ctl(g_epoll_set.epfd, EPOLL_CTL_ADD, fd, &ev) != 0) {
gpr_log(GPR_ERROR, "epoll_ctl failed: %s", strerror(errno));
gpr_log(GPR_ERROR, "epoll_ctl failed: %s",
grpc_core::StrError(errno).c_str());
}
return new_fd;
@ -389,7 +391,8 @@ static void fd_shutdown_internal(grpc_fd* fd, grpc_error_handle why,
epoll_event phony_event;
if (epoll_ctl(g_epoll_set.epfd, EPOLL_CTL_DEL, fd->fd, &phony_event) !=
0) {
gpr_log(GPR_ERROR, "epoll_ctl failed: %s", strerror(errno));
gpr_log(GPR_ERROR, "epoll_ctl failed: %s",
grpc_core::StrError(errno).c_str());
}
}
fd->write_closure->SetShutdown(why);

@ -27,6 +27,8 @@
#include <string.h>
#include <sys/utsname.h>
#include "src/core/lib/gprpp/strerror.h"
namespace grpc_core {
bool KernelSupportsErrqueue() {
@ -36,7 +38,7 @@ bool KernelSupportsErrqueue() {
// least 4.0.0
struct utsname buffer;
if (uname(&buffer) != 0) {
gpr_log(GPR_ERROR, "uname: %s", strerror(errno));
gpr_log(GPR_ERROR, "uname: %s", StrError(errno).c_str());
return false;
}
char* release = buffer.release;

@ -50,6 +50,7 @@
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/iomgr/sockaddr.h"
/* set a socket to use zerocopy */
@ -347,12 +348,12 @@ grpc_error_handle grpc_set_socket_tcp_user_timeout(
if (0 != setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout,
sizeof(timeout))) {
gpr_log(GPR_ERROR, "setsockopt(TCP_USER_TIMEOUT) %s",
strerror(errno));
grpc_core::StrError(errno).c_str());
return absl::OkStatus();
}
if (0 != getsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &newval, &len)) {
gpr_log(GPR_ERROR, "getsockopt(TCP_USER_TIMEOUT) %s",
strerror(errno));
grpc_core::StrError(errno).c_str());
return absl::OkStatus();
}
if (newval != timeout) {

@ -37,6 +37,7 @@
#ifdef GRPC_POSIX_SOCKET_TCP
#include "src/core/lib/event_engine/channel_args_endpoint_config.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/iomgr/socket_utils_posix.h"
using ::grpc_event_engine::experimental::EndpointConfig;

@ -54,6 +54,7 @@
#include "src/core/lib/experiments/experiments.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/iomgr/buffer_list.h"
#include "src/core/lib/iomgr/ev_posix.h"
@ -862,7 +863,7 @@ static void update_rcvlowat(grpc_tcp* tcp)
sizeof(remaining)) != 0) {
gpr_log(GPR_ERROR, "%s",
absl::StrCat("Cannot set SO_RCVLOWAT on fd=", tcp->fd,
" err=", strerror(errno))
" err=", grpc_core::StrError(errno).c_str())
.c_str());
return;
}

@ -52,6 +52,7 @@
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/sockaddr.h"
@ -202,7 +203,8 @@ static void on_read(void* arg, grpc_error_handle err) {
} else {
gpr_mu_lock(&sp->server->mu);
if (!sp->server->shutdown_listeners) {
gpr_log(GPR_ERROR, "Failed accept4: %s", strerror(errno));
gpr_log(GPR_ERROR, "Failed accept4: %s",
grpc_core::StrError(errno).c_str());
} else {
/* if we have shutdown listeners, accept4 could fail, and we
needn't notify users */
@ -232,7 +234,8 @@ static void on_read(void* arg, grpc_error_handle err) {
addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_storage));
if (getsockname(fd, reinterpret_cast<struct sockaddr*>(addr.addr),
&(addr.len)) < 0) {
gpr_log(GPR_ERROR, "Failed getsockname: %s", strerror(errno));
gpr_log(GPR_ERROR, "Failed getsockname: %s",
grpc_core::StrError(errno).c_str());
close(fd);
goto error;
}
@ -595,7 +598,8 @@ class ExternalConnectionHandler : public grpc_core::TcpServerFdHandler {
if (getpeername(fd, reinterpret_cast<struct sockaddr*>(addr.addr),
&(addr.len)) < 0) {
gpr_log(GPR_ERROR, "Failed getpeername: %s", strerror(errno));
gpr_log(GPR_ERROR, "Failed getpeername: %s",
grpc_core::StrError(errno).c_str());
close(fd);
return;
}

@ -28,6 +28,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
static grpc_error_handle eventfd_create(grpc_wakeup_fd* fd_info) {

@ -28,6 +28,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/iomgr/socket_utils_posix.h"
#include "src/core/lib/iomgr/wakeup_fd_pipe.h"
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
@ -36,7 +37,8 @@ static grpc_error_handle pipe_init(grpc_wakeup_fd* fd_info) {
int pipefd[2];
int r = pipe(pipefd);
if (0 != r) {
gpr_log(GPR_ERROR, "pipe creation failed (%d): %s", errno, strerror(errno));
gpr_log(GPR_ERROR, "pipe creation failed (%d): %s", errno,
grpc_core::StrError(errno).c_str());
return GRPC_OS_ERROR(errno, "pipe");
}
grpc_error_handle err;

@ -505,6 +505,7 @@ CORE_SOURCE_FILES = [
'src/core/lib/gprpp/stat_posix.cc',
'src/core/lib/gprpp/stat_windows.cc',
'src/core/lib/gprpp/status_helper.cc',
'src/core/lib/gprpp/strerror.cc',
'src/core/lib/gprpp/tchar.cc',
'src/core/lib/gprpp/thd_posix.cc',
'src/core/lib/gprpp/thd_windows.cc',

@ -60,6 +60,7 @@
#include "src/core/lib/gprpp/dual_ref_counted.h"
#include "src/core/lib/gprpp/global_config.h"
#include "src/core/lib/gprpp/notification.h"
#include "src/core/lib/gprpp/strerror.h"
#include "test/core/event_engine/posix/posix_engine_test_utils.h"
#include "test/core/util/port.h"
@ -94,7 +95,8 @@ absl::Status SetSocketSendBuf(int fd, int buffer_size_bytes) {
return 0 == setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &buffer_size_bytes,
sizeof(buffer_size_bytes))
? absl::OkStatus()
: absl::Status(absl::StatusCode::kInternal, strerror(errno));
: absl::Status(absl::StatusCode::kInternal,
grpc_core::StrError(errno).c_str());
}
// Create a test socket with the right properties for testing.
@ -234,7 +236,7 @@ void ListenCb(server* sv, absl::Status status) {
return;
} else if (fd < 0) {
gpr_log(GPR_ERROR, "Failed to acceot a connection, returned error: %s",
std::strerror(errno));
grpc_core::StrError(errno).c_str());
}
EXPECT_GE(fd, 0);
EXPECT_LT(fd, FD_SETSIZE);
@ -621,8 +623,9 @@ class WakeupFdHandle : public grpc_core::DualRefCounted<WakeupFdHandle> {
case EINTR:
continue;
default:
return absl::Status(absl::StatusCode::kInternal,
absl::StrCat("read: ", strerror(errno)));
return absl::Status(
absl::StatusCode::kInternal,
absl::StrCat("read: ", grpc_core::StrError(errno)));
}
}
}

@ -34,6 +34,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/iomgr/resolved_address.h"
namespace grpc_event_engine {
@ -72,7 +73,7 @@ absl::Status PollFds(struct pollfd* pfds, int nfds, absl::Duration timeout) {
}
}
if (rv < 0) {
return absl::UnknownError(std::strerror(errno));
return absl::UnknownError(grpc_core::StrError(errno));
}
if (rv == 0) {
return absl::CancelledError("Deadline exceeded");
@ -262,10 +263,11 @@ void PosixOracleEndpoint::ProcessReadOperations() {
int saved_errno;
std::string read_data =
ReadBytes(socket_fd_, saved_errno, read_op.GetNumBytesToRead());
read_op(read_data, read_data.empty() ? absl::CancelledError(absl::StrCat(
"Read failed with error = ",
std::strerror(saved_errno)))
: absl::OkStatus());
read_op(read_data, read_data.empty()
? absl::CancelledError(
absl::StrCat("Read failed with error = ",
grpc_core::StrError(saved_errno)))
: absl::OkStatus());
}
gpr_log(GPR_INFO, "Shutting down read ops thread ...");
}
@ -282,10 +284,10 @@ void PosixOracleEndpoint::ProcessWriteOperations() {
}
int saved_errno;
int ret = WriteBytes(socket_fd_, saved_errno, write_op.GetBytesToWrite());
write_op(
ret < 0 ? absl::CancelledError(absl::StrCat(
"Write failed with error = ", std::strerror(saved_errno)))
: absl::OkStatus());
write_op(ret < 0 ? absl::CancelledError(
absl::StrCat("Write failed with error = ",
grpc_core::StrError(saved_errno)))
: absl::OkStatus());
}
gpr_log(GPR_INFO, "Shutting down write ops thread ...");
}
@ -298,7 +300,8 @@ PosixOracleListener::PosixOracleListener(
on_shutdown_(std::move(on_shutdown)),
memory_allocator_factory_(std::move(memory_allocator_factory)) {
if (pipe(pipefd_) == -1) {
gpr_log(GPR_ERROR, "Error creating pipe: %s", std::strerror(errno));
gpr_log(GPR_ERROR, "Error creating pipe: %s",
grpc_core::StrError(errno).c_str());
abort();
}
}
@ -368,7 +371,7 @@ void PosixOracleListener::HandleIncomingConnections() {
gpr_log(GPR_ERROR,
"Error accepting new connection: %s. Ignoring connection "
"attempt ...",
std::strerror(errno));
grpc_core::StrError(errno).c_str());
continue;
}
on_accept_(PosixOracleEndpoint::Create(client_sock_fd),
@ -395,29 +398,29 @@ absl::StatusOr<int> PosixOracleListener::Bind(
// Creating a new socket file descriptor.
if ((new_socket = socket(AF_INET6, SOCK_STREAM, 0)) <= 0) {
return absl::UnknownError(
absl::StrCat("Error creating socket: ", std::strerror(errno)));
absl::StrCat("Error creating socket: ", grpc_core::StrError(errno)));
}
// MacOS biulds fail if SO_REUSEADDR and SO_REUSEPORT are set in the same
// setsockopt syscall. So they are set separately one after the other.
if (setsockopt(new_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
return absl::UnknownError(
absl::StrCat("Error setsockopt(SO_REUSEADDR): ", std::strerror(errno)));
return absl::UnknownError(absl::StrCat("Error setsockopt(SO_REUSEADDR): ",
grpc_core::StrError(errno)));
}
if (setsockopt(new_socket, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt))) {
return absl::UnknownError(
absl::StrCat("Error setsockopt(SO_REUSEPORT): ", std::strerror(errno)));
return absl::UnknownError(absl::StrCat("Error setsockopt(SO_REUSEPORT): ",
grpc_core::StrError(errno)));
}
// Forcefully bind the new socket.
if (bind(new_socket, reinterpret_cast<const struct sockaddr*>(addr.address()),
address.len) < 0) {
return absl::UnknownError(
absl::StrCat("Error bind: ", std::strerror(errno)));
absl::StrCat("Error bind: ", grpc_core::StrError(errno)));
}
// Set the new socket to listen for one active connection at a time.
if (listen(new_socket, 1) < 0) {
return absl::UnknownError(
absl::StrCat("Error listen: ", std::strerror(errno)));
absl::StrCat("Error listen: ", grpc_core::StrError(errno)));
}
listener_fds_.push_back(new_socket);
return 0;
@ -440,8 +443,9 @@ EventEngine::ConnectionHandle PosixOracleEventEngine::Connect(
return {};
}
if ((client_sock_fd = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
on_connect(absl::CancelledError(absl::StrCat(
"Connect failed: socket creation error: ", std::strerror(errno))));
on_connect(absl::CancelledError(
absl::StrCat("Connect failed: socket creation error: ",
grpc_core::StrError(errno).c_str())));
return {};
}
int err;

@ -42,6 +42,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/socket_utils_posix.h"
@ -161,7 +162,8 @@ static void session_read_cb(void* arg, /*session */
before notify_on_read is called. */
grpc_fd_notify_on_read(se->em_fd, &se->session_read_closure);
} else {
gpr_log(GPR_ERROR, "Unhandled read error %s", strerror(errno));
gpr_log(GPR_ERROR, "Unhandled read error %s",
grpc_core::StrError(errno).c_str());
abort();
}
}
@ -327,7 +329,7 @@ static void client_session_write(void* arg, /*client */
}
gpr_mu_unlock(g_mu);
} else {
gpr_log(GPR_ERROR, "unknown errno %s", strerror(errno));
gpr_log(GPR_ERROR, "unknown errno %s", grpc_core::StrError(errno).c_str());
abort();
}
}

@ -45,6 +45,7 @@
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/event_engine/channel_args_endpoint_config.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/resolve_address.h"
@ -499,7 +500,7 @@ TEST(TcpServerPosixTest, MainTest) {
test_no_op_with_port_and_start();
if (getifaddrs(&ifa) != 0 || ifa == nullptr) {
FAIL() << "getifaddrs: " << strerror(errno);
FAIL() << "getifaddrs: " << grpc_core::StrError(errno);
}
dst_addrs->naddrs = 0;
for (ifa_it = ifa; ifa_it != nullptr && dst_addrs->naddrs < MAX_ADDRS;

@ -37,11 +37,14 @@
#endif
#include <sys/socket.h>
#include <string>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/socket_utils_posix.h"
@ -83,7 +86,8 @@ static int read_bytes(int fd, char* buf, size_t read_size, int spin) {
if (errno == EAGAIN && spin == 1) {
continue;
}
gpr_log(GPR_ERROR, "Read failed: %s", strerror(errno));
gpr_log(GPR_ERROR, "Read failed: %s",
grpc_core::StrError(errno).c_str());
return -1;
}
} else {
@ -116,7 +120,8 @@ static int poll_read_bytes(int fd, char* buf, size_t read_size, int spin) {
if (errno == EINTR) {
continue;
} else {
gpr_log(GPR_ERROR, "Poll failed: %s", strerror(errno));
gpr_log(GPR_ERROR, "Poll failed: %s",
grpc_core::StrError(errno).c_str());
return -1;
}
}
@ -127,7 +132,7 @@ static int poll_read_bytes(int fd, char* buf, size_t read_size, int spin) {
err2 = read(fd, buf + bytes_read, read_size - bytes_read);
} while (err2 < 0 && errno == EINTR);
if (err2 < 0 && errno != EAGAIN) {
gpr_log(GPR_ERROR, "Read failed: %s", strerror(errno));
gpr_log(GPR_ERROR, "Read failed: %s", grpc_core::StrError(errno).c_str());
return -1;
}
bytes_read += static_cast<size_t>(err2);
@ -156,7 +161,8 @@ static int epoll_read_bytes(struct thread_args* args, char* buf, int spin) {
err = epoll_wait(args->epoll_fd, &ev, 1, spin ? 0 : -1);
if (err < 0) {
if (errno == EINTR) continue;
gpr_log(GPR_ERROR, "epoll_wait failed: %s", strerror(errno));
gpr_log(GPR_ERROR, "epoll_wait failed: %s",
grpc_core::StrError(errno).c_str());
return -1;
}
if (err == 0 && spin) continue;
@ -202,7 +208,8 @@ static int blocking_write_bytes(struct thread_args* args, char* buf) {
if (errno == EINTR) {
continue;
} else {
gpr_log(GPR_ERROR, "Read failed: %s", strerror(errno));
gpr_log(GPR_ERROR, "Read failed: %s",
grpc_core::StrError(errno).c_str());
return -1;
}
} else {
@ -240,7 +247,7 @@ static int epoll_setup(thread_args* args) {
set_socket_nonblocking(args);
epoll_fd = epoll_create(1);
if (epoll_fd < 0) {
gpr_log(GPR_ERROR, "epoll_create: %s", strerror(errno));
gpr_log(GPR_ERROR, "epoll_create: %s", grpc_core::StrError(errno).c_str());
return -1;
}
@ -249,7 +256,7 @@ static int epoll_setup(thread_args* args) {
ev.events = EPOLLIN | EPOLLET;
ev.data.fd = args->fds.read_fd;
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, args->fds.read_fd, &ev) < 0) {
gpr_log(GPR_ERROR, "epoll_ctl: %s", strerror(errno));
gpr_log(GPR_ERROR, "epoll_ctl: %s", grpc_core::StrError(errno).c_str());
}
return 0;
}
@ -333,7 +340,8 @@ error:
static int create_listening_socket(struct sockaddr* port, socklen_t len) {
int fd = socket(port->sa_family, SOCK_STREAM, 0);
if (fd < 0) {
gpr_log(GPR_ERROR, "Unable to create socket: %s", strerror(errno));
gpr_log(GPR_ERROR, "Unable to create socket: %s",
grpc_core::StrError(errno).c_str());
goto error;
}
@ -351,17 +359,17 @@ static int create_listening_socket(struct sockaddr* port, socklen_t len) {
}
if (bind(fd, port, len) < 0) {
gpr_log(GPR_ERROR, "bind: %s", strerror(errno));
gpr_log(GPR_ERROR, "bind: %s", grpc_core::StrError(errno).c_str());
goto error;
}
if (listen(fd, 1) < 0) {
gpr_log(GPR_ERROR, "listen: %s", strerror(errno));
gpr_log(GPR_ERROR, "listen: %s", grpc_core::StrError(errno).c_str());
goto error;
}
if (getsockname(fd, port, &len) < 0) {
gpr_log(GPR_ERROR, "getsockname: %s", strerror(errno));
gpr_log(GPR_ERROR, "getsockname: %s", grpc_core::StrError(errno).c_str());
goto error;
}
@ -378,7 +386,8 @@ static int connect_client(struct sockaddr* addr, socklen_t len) {
int fd = socket(addr->sa_family, SOCK_STREAM, 0);
int err;
if (fd < 0) {
gpr_log(GPR_ERROR, "Unable to create socket: %s", strerror(errno));
gpr_log(GPR_ERROR, "Unable to create socket: %s",
grpc_core::StrError(errno).c_str());
goto error;
}
@ -396,7 +405,7 @@ static int connect_client(struct sockaddr* addr, socklen_t len) {
} while (err < 0 && errno == EINTR);
if (err < 0) {
gpr_log(GPR_ERROR, "connect error: %s", strerror(errno));
gpr_log(GPR_ERROR, "connect error: %s", grpc_core::StrError(errno).c_str());
goto error;
}
return fd;
@ -411,7 +420,7 @@ error:
static int accept_server(int listen_fd) {
int fd = accept(listen_fd, nullptr, nullptr);
if (fd < 0) {
gpr_log(GPR_ERROR, "Accept failed: %s", strerror(errno));
gpr_log(GPR_ERROR, "Accept failed: %s", grpc_core::StrError(errno).c_str());
return -1;
}
return fd;
@ -470,7 +479,7 @@ error:
static int create_sockets_socketpair(fd_pair* client_fds, fd_pair* server_fds) {
int fds[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
gpr_log(GPR_ERROR, "socketpair: %s", strerror(errno));
gpr_log(GPR_ERROR, "socketpair: %s", grpc_core::StrError(errno).c_str());
return -1;
}
@ -485,12 +494,12 @@ static int create_sockets_pipe(fd_pair* client_fds, fd_pair* server_fds) {
int cfds[2];
int sfds[2];
if (pipe(cfds) < 0) {
gpr_log(GPR_ERROR, "pipe: %s", strerror(errno));
gpr_log(GPR_ERROR, "pipe: %s", grpc_core::StrError(errno).c_str());
return -1;
}
if (pipe(sfds) < 0) {
gpr_log(GPR_ERROR, "pipe: %s", strerror(errno));
gpr_log(GPR_ERROR, "pipe: %s", grpc_core::StrError(errno).c_str());
return -1;
}

@ -18,6 +18,8 @@
#include <grpc/support/port_platform.h>
#include <string>
#ifdef GPR_POSIX_SUBPROCESS
#include <errno.h>
@ -30,6 +32,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/strerror.h"
#include "test/core/util/subprocess.h"
struct gpr_subprocess {
@ -54,7 +57,8 @@ gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) {
exec_args[argc] = nullptr;
execv(exec_args[0], exec_args);
/* if we reach here, an error has occurred */
gpr_log(GPR_ERROR, "execv '%s' failed: %s", exec_args[0], strerror(errno));
gpr_log(GPR_ERROR, "execv '%s' failed: %s", exec_args[0],
grpc_core::StrError(errno).c_str());
_exit(1);
} else {
r = grpc_core::Zalloc<gpr_subprocess>();
@ -79,7 +83,7 @@ retry:
goto retry;
}
gpr_log(GPR_ERROR, "waitpid failed for pid %d: %s", p->pid,
strerror(errno));
grpc_core::StrError(errno).c_str());
return -1;
}
p->joined = true;

@ -2064,6 +2064,8 @@ src/core/lib/gprpp/stat_posix.cc \
src/core/lib/gprpp/stat_windows.cc \
src/core/lib/gprpp/status_helper.cc \
src/core/lib/gprpp/status_helper.h \
src/core/lib/gprpp/strerror.cc \
src/core/lib/gprpp/strerror.h \
src/core/lib/gprpp/sync.h \
src/core/lib/gprpp/table.h \
src/core/lib/gprpp/tchar.cc \

@ -1854,6 +1854,8 @@ src/core/lib/gprpp/stat_posix.cc \
src/core/lib/gprpp/stat_windows.cc \
src/core/lib/gprpp/status_helper.cc \
src/core/lib/gprpp/status_helper.h \
src/core/lib/gprpp/strerror.cc \
src/core/lib/gprpp/strerror.h \
src/core/lib/gprpp/sync.h \
src/core/lib/gprpp/table.h \
src/core/lib/gprpp/tchar.cc \

Loading…
Cancel
Save