Wrap strerror into a thread-safe implementation

pull/25140/head
yang-g 4 years ago
parent b7df39f095
commit cf26f0133a
  1. 2
      BUILD
  2. 2
      BUILD.gn
  3. 1
      CMakeLists.txt
  4. 1
      Makefile
  5. 2
      build_autogenerated.yaml
  6. 1
      config.m4
  7. 1
      config.w32
  8. 2
      gRPC-C++.podspec
  9. 3
      gRPC-Core.podspec
  10. 2
      grpc.gemspec
  11. 1
      grpc.gyp
  12. 2
      package.xml
  13. 8
      src/core/lib/gpr/cpu_linux.cc
  14. 103
      src/core/lib/gpr/strerror.cc
  15. 35
      src/core/lib/gpr/strerror.h
  16. 5
      src/core/lib/gpr/tmpfile_posix.cc
  17. 5
      src/core/lib/gprpp/stat_posix.cc
  18. 5
      src/core/lib/gprpp/stat_windows.cc
  19. 9
      src/core/lib/iomgr/error.cc
  20. 7
      src/core/lib/iomgr/ev_epoll1_linux.cc
  21. 3
      src/core/lib/iomgr/internal_errqueue.cc
  22. 5
      src/core/lib/iomgr/socket_utils_common_posix.cc
  23. 10
      src/core/lib/iomgr/tcp_server_posix.cc
  24. 15
      src/core/lib/iomgr/udp_server.cc
  25. 4
      src/core/lib/iomgr/wakeup_fd_pipe.cc
  26. 1
      src/python/grpcio/grpc_core_dependencies.py
  27. 6
      test/core/iomgr/fd_posix_test.cc
  28. 3
      test/core/iomgr/tcp_server_posix_test.cc
  29. 41
      test/core/network_benchmarks/low_level_ping_pong.cc
  30. 4
      test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc
  31. 6
      test/core/util/subprocess_posix.cc
  32. 2
      tools/doxygen/Doxyfile.c++.internal
  33. 2
      tools/doxygen/Doxyfile.core.internal

@ -540,6 +540,7 @@ grpc_cc_library(
"src/core/lib/gpr/log_posix.cc",
"src/core/lib/gpr/log_windows.cc",
"src/core/lib/gpr/murmur_hash.cc",
"src/core/lib/gpr/strerror.cc",
"src/core/lib/gpr/string.cc",
"src/core/lib/gpr/string_posix.cc",
"src/core/lib/gpr/string_util_windows.cc",
@ -576,6 +577,7 @@ grpc_cc_library(
"src/core/lib/gpr/env.h",
"src/core/lib/gpr/murmur_hash.h",
"src/core/lib/gpr/spinlock.h",
"src/core/lib/gpr/strerror.h",
"src/core/lib/gpr/string.h",
"src/core/lib/gpr/string_windows.h",
"src/core/lib/gpr/time_precise.h",

@ -117,6 +117,8 @@ config("grpc_config") {
"src/core/lib/gpr/murmur_hash.cc",
"src/core/lib/gpr/murmur_hash.h",
"src/core/lib/gpr/spinlock.h",
"src/core/lib/gpr/strerror.cc",
"src/core/lib/gpr/strerror.h",
"src/core/lib/gpr/string.cc",
"src/core/lib/gpr/string.h",
"src/core/lib/gpr/string_posix.cc",

@ -1306,6 +1306,7 @@ add_library(gpr
src/core/lib/gpr/log_posix.cc
src/core/lib/gpr/log_windows.cc
src/core/lib/gpr/murmur_hash.cc
src/core/lib/gpr/strerror.cc
src/core/lib/gpr/string.cc
src/core/lib/gpr/string_posix.cc
src/core/lib/gpr/string_util_windows.cc

@ -920,6 +920,7 @@ LIBGPR_SRC = \
src/core/lib/gpr/log_posix.cc \
src/core/lib/gpr/log_windows.cc \
src/core/lib/gpr/murmur_hash.cc \
src/core/lib/gpr/strerror.cc \
src/core/lib/gpr/string.cc \
src/core/lib/gpr/string_posix.cc \
src/core/lib/gpr/string_util_windows.cc \

@ -283,6 +283,7 @@ libs:
- src/core/lib/gpr/env.h
- src/core/lib/gpr/murmur_hash.h
- src/core/lib/gpr/spinlock.h
- src/core/lib/gpr/strerror.h
- src/core/lib/gpr/string.h
- src/core/lib/gpr/string_windows.h
- src/core/lib/gpr/time_precise.h
@ -325,6 +326,7 @@ libs:
- src/core/lib/gpr/log_posix.cc
- src/core/lib/gpr/log_windows.cc
- src/core/lib/gpr/murmur_hash.cc
- src/core/lib/gpr/strerror.cc
- src/core/lib/gpr/string.cc
- src/core/lib/gpr/string_posix.cc
- src/core/lib/gpr/string_util_windows.cc

@ -354,6 +354,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/gpr/log_posix.cc \
src/core/lib/gpr/log_windows.cc \
src/core/lib/gpr/murmur_hash.cc \
src/core/lib/gpr/strerror.cc \
src/core/lib/gpr/string.cc \
src/core/lib/gpr/string_posix.cc \
src/core/lib/gpr/string_util_windows.cc \

@ -321,6 +321,7 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\gpr\\log_posix.cc " +
"src\\core\\lib\\gpr\\log_windows.cc " +
"src\\core\\lib\\gpr\\murmur_hash.cc " +
"src\\core\\lib\\gpr\\strerror.cc " +
"src\\core\\lib\\gpr\\string.cc " +
"src\\core\\lib\\gpr\\string_posix.cc " +
"src\\core\\lib\\gpr\\string_util_windows.cc " +

@ -486,6 +486,7 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/strerror.h',
'src/core/lib/gpr/string.h',
'src/core/lib/gpr/string_windows.h',
'src/core/lib/gpr/time_precise.h',
@ -1104,6 +1105,7 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/strerror.h',
'src/core/lib/gpr/string.h',
'src/core/lib/gpr/string_windows.h',
'src/core/lib/gpr/time_precise.h',

@ -790,6 +790,8 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/murmur_hash.cc',
'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/strerror.cc',
'src/core/lib/gpr/strerror.h',
'src/core/lib/gpr/string.cc',
'src/core/lib/gpr/string.h',
'src/core/lib/gpr/string_posix.cc',
@ -1635,6 +1637,7 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h',
'src/core/lib/gpr/strerror.h',
'src/core/lib/gpr/string.h',
'src/core/lib/gpr/string_windows.h',
'src/core/lib/gpr/time_precise.h',

@ -705,6 +705,8 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gpr/murmur_hash.cc )
s.files += %w( src/core/lib/gpr/murmur_hash.h )
s.files += %w( src/core/lib/gpr/spinlock.h )
s.files += %w( src/core/lib/gpr/strerror.cc )
s.files += %w( src/core/lib/gpr/strerror.h )
s.files += %w( src/core/lib/gpr/string.cc )
s.files += %w( src/core/lib/gpr/string.h )
s.files += %w( src/core/lib/gpr/string_posix.cc )

@ -404,6 +404,7 @@
'src/core/lib/gpr/log_posix.cc',
'src/core/lib/gpr/log_windows.cc',
'src/core/lib/gpr/murmur_hash.cc',
'src/core/lib/gpr/strerror.cc',
'src/core/lib/gpr/string.cc',
'src/core/lib/gpr/string_posix.cc',
'src/core/lib/gpr/string_util_windows.cc',

@ -685,6 +685,8 @@
<file baseinstalldir="/" name="src/core/lib/gpr/murmur_hash.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/murmur_hash.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/spinlock.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/strerror.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/strerror.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/string.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/string.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/string_posix.cc" role="src" />

@ -33,12 +33,15 @@
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include "src/core/lib/gpr/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()) {

@ -0,0 +1,103 @@
/*
*
* Copyright 2020 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/gpr/strerror.h"
#include <array>
#include <cerrno>
#include <cstddef>
#include <cstdio>
#include <cstring>
#include <string>
#include <type_traits>
// The implementation below is mostly copied from abseil because it is internal
// there.
namespace grpc_core {
namespace {
// `ErrnoSaver` captures the value of `errno` upon construction and restores it
// upon deletion. It is used in low-level code and must be super fast. Do not
// add instrumentation, even in debug modes.
class ErrnoSaver {
public:
ErrnoSaver() : saved_errno_(errno) {}
~ErrnoSaver() { errno = saved_errno_; }
int operator()() const { return saved_errno_; }
private:
const int saved_errno_;
};
const char* StrErrorAdaptor(int errnum, char* buf, size_t buflen) {
#if defined(GPR_WINDOWS)
int rc = strerror_s(buf, buflen, errnum);
buf[buflen - 1] = '\0'; // guarantee NUL termination
if (rc == 0 && strncmp(buf, "Unknown error", buflen) == 0) *buf = '\0';
return buf;
#else
// The type of `ret` is platform-specific; both of these branches must compile
// either way but only one will execute on any given platform:
auto ret = strerror_r(errnum, buf, buflen);
if (std::is_same<decltype(ret), int>::value) {
// XSI `strerror_r`; `ret` is `int`:
if (ret) *buf = '\0';
return buf;
} else {
// GNU `strerror_r`; `ret` is `char *`:
return reinterpret_cast<const char*>(ret);
}
#endif
}
std::string StrErrorInternal(int errnum) {
char buf[100];
const char* str = StrErrorAdaptor(errnum, buf, sizeof buf);
if (*str == '\0') {
snprintf(buf, sizeof buf, "Unknown error %d", errnum);
str = buf;
}
return str;
}
// kSysNerr is the number of errors from a recent glibc. `StrError()` falls back
// to `StrErrorAdaptor()` if the value is larger than this.
constexpr int kSysNerr = 135;
std::array<std::string, kSysNerr>* NewStrErrorTable() {
auto* table = new std::array<std::string, kSysNerr>;
for (int i = 0; i < static_cast<int>(table->size()); ++i) {
(*table)[i] = StrErrorInternal(i);
}
return table;
}
} // namespace
std::string StrError(int errnum) {
ErrnoSaver errno_saver;
static const auto* table = NewStrErrorTable();
if (errnum >= 0 && errnum < static_cast<int>(table->size())) {
return (*table)[errnum];
}
return StrErrorInternal(errnum);
}
} // namespace grpc_core

@ -0,0 +1,35 @@
/*
*
* Copyright 2020 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_GPR_STRERROR_H
#define GRPC_CORE_LIB_GPR_STRERROR_H
#include <grpc/support/port_platform.h>
#include <string>
namespace grpc_core {
// `strerror` is not thread-safe. This wrapper is a portable thread-safe
// implementation. It does not modify `errno`.
// The implementation is copied from abseil's internal.
std::string StrError(int errnum);
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPR_STRERROR_H */

@ -31,6 +31,7 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/gpr/string.h"
FILE* gpr_tmpfile(const char* prefix, char** tmp_filename) {
@ -46,13 +47,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;

@ -25,6 +25,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/gprpp/stat.h"
namespace grpc_core {
@ -34,9 +35,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.

@ -24,6 +24,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/gprpp/stat.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.

@ -32,6 +32,7 @@
#endif
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/error_internal.h"
#include "src/core/lib/profiling/timers.h"
@ -777,15 +778,15 @@ const char* grpc_error_string(grpc_error* err) {
grpc_error* grpc_os_error(const char* file, int line, int err,
const char* call_name) {
std::string err_string = grpc_core::StrError(err);
return grpc_error_set_str(
grpc_error_set_str(
grpc_error_set_int(
grpc_error_create(file, line,
grpc_slice_from_static_string(strerror(err)),
nullptr, 0),
grpc_slice_from_cpp_string(err_string), nullptr,
0),
GRPC_ERROR_INT_ERRNO, err),
GRPC_ERROR_STR_OS_ERROR,
grpc_slice_from_static_string(strerror(err))),
GRPC_ERROR_STR_OS_ERROR, grpc_slice_from_cpp_string(err_string)),
GRPC_ERROR_STR_SYSCALL, grpc_slice_from_copied_string(call_name));
}

@ -49,6 +49,7 @@
#include <grpc/support/cpu.h>
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/tls.h"
#include "src/core/lib/gpr/useful.h"
@ -371,7 +372,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;
@ -392,7 +394,8 @@ static void fd_shutdown_internal(grpc_fd* fd, grpc_error* why,
epoll_event dummy_event;
if (epoll_ctl(g_epoll_set.epfd, EPOLL_CTL_DEL, fd->fd, &dummy_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(GRPC_ERROR_REF(why));

@ -21,6 +21,7 @@
#include "src/core/lib/iomgr/port.h"
#include <grpc/impl/codegen/log.h>
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/iomgr/internal_errqueue.h"
#ifdef GRPC_POSIX_SOCKET_TCP
@ -41,7 +42,7 @@ void grpc_errqueue_init() {
#ifdef GRPC_LINUX_ERRQUEUE
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;
}
char* release = buffer.release;

@ -48,6 +48,7 @@
#include <grpc/support/sync.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
@ -363,12 +364,12 @@ grpc_error* 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 GRPC_ERROR_NONE;
}
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 GRPC_ERROR_NONE;
}
if (newval != timeout) {

@ -48,6 +48,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/exec_ctx.h"
@ -213,7 +214,8 @@ static void on_read(void* arg, grpc_error* err) {
default:
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 */
@ -230,7 +232,8 @@ static void on_read(void* arg, grpc_error* 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;
}
@ -580,7 +583,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;
}

@ -57,6 +57,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/error.h"
@ -367,11 +368,13 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd,
}
if (grpc_set_socket_nonblocking(fd, 1) != GRPC_ERROR_NONE) {
gpr_log(GPR_ERROR, "Unable to set nonblocking %d: %s", fd, strerror(errno));
gpr_log(GPR_ERROR, "Unable to set nonblocking %d: %s", fd,
grpc_core::StrError(errno).c_str());
goto error;
}
if (grpc_set_socket_cloexec(fd, 1) != GRPC_ERROR_NONE) {
gpr_log(GPR_ERROR, "Unable to set cloexec %d: %s", fd, strerror(errno));
gpr_log(GPR_ERROR, "Unable to set cloexec %d: %s", fd,
grpc_core::StrError(errno).c_str());
goto error;
}
@ -413,7 +416,8 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd,
if (bind_socket(socket_factory, fd, addr) < 0) {
std::string addr_str = grpc_sockaddr_to_string(addr, false);
gpr_log(GPR_ERROR, "bind addr=%s: %s", addr_str.c_str(), strerror(errno));
gpr_log(GPR_ERROR, "bind addr=%s: %s", addr_str.c_str(),
grpc_core::StrError(errno).c_str());
goto error;
}
@ -422,7 +426,7 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd,
if (getsockname(fd, reinterpret_cast<grpc_sockaddr*>(sockname_temp.addr),
&sockname_temp.len) < 0) {
gpr_log(GPR_ERROR, "Unable to get the address socket %d is bound to: %s",
fd, strerror(errno));
fd, grpc_core::StrError(errno).c_str());
goto error;
}
@ -670,7 +674,8 @@ int grpc_udp_server_add_port(grpc_udp_server* s, grpc_resolved_address* addr,
GRPC_ERROR_UNREF(grpc_create_dualstack_socket_using_factory(
s->socket_factory, addr, SOCK_DGRAM, IPPROTO_UDP, &dsmode, &fd));
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());
}
if (dsmode == GRPC_DSMODE_IPV4 &&
grpc_sockaddr_is_v4mapped(addr, &addr4_copy)) {

@ -31,13 +31,15 @@
#include <grpc/support/log.h>
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/iomgr/socket_utils_posix.h"
static grpc_error* 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* err;

@ -330,6 +330,7 @@ CORE_SOURCE_FILES = [
'src/core/lib/gpr/log_posix.cc',
'src/core/lib/gpr/log_windows.cc',
'src/core/lib/gpr/murmur_hash.cc',
'src/core/lib/gpr/strerror.cc',
'src/core/lib/gpr/string.cc',
'src/core/lib/gpr/string_posix.cc',
'src/core/lib/gpr/string_util_windows.cc',

@ -41,6 +41,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/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"
@ -160,7 +161,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();
}
}
@ -326,7 +328,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();
}
}

@ -40,6 +40,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/resolve_address.h"
@ -457,7 +458,7 @@ int main(int argc, char** argv) {
test_no_op_with_port_and_start();
if (getifaddrs(&ifa) != 0 || ifa == nullptr) {
gpr_log(GPR_ERROR, "getifaddrs: %s", strerror(errno));
gpr_log(GPR_ERROR, "getifaddrs: %s", grpc_core::StrError(errno).c_str());
return EXIT_FAILURE;
}
dst_addrs->naddrs = 0;

@ -38,6 +38,7 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/error.h"
@ -80,7 +81,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 {
@ -113,7 +115,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;
}
}
@ -124,7 +127,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);
@ -153,7 +156,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;
@ -199,7 +203,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 {
@ -237,7 +242,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;
}
@ -246,7 +251,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;
}
@ -330,7 +335,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;
}
@ -348,17 +354,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;
}
@ -375,7 +381,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;
}
@ -393,7 +400,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;
@ -408,7 +415,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;
@ -467,7 +474,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;
}
@ -482,12 +489,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;
}

@ -45,6 +45,7 @@
#include <grpcpp/impl/codegen/service_type.h>
#include <grpcpp/server_builder.h>
#include "src/core/lib/gpr/strerror.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/thd.h"
@ -459,7 +460,8 @@ class FakeTcpServer {
gpr_log(GPR_ERROR,
"Fake TCP server encountered unexpected error:%d |%s| "
"sending %d bytes on fd:%d",
errno, strerror(errno), bytes_to_send, fd_);
errno, grpc_core::StrError(errno).c_str(), bytes_to_send,
fd_);
GPR_ASSERT(0);
} else if (bytes_sent > 0) {
total_bytes_sent_ += bytes_sent;

@ -34,6 +34,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gpr/strerror.h"
#include "test/core/util/subprocess.h"
struct gpr_subprocess {
@ -58,7 +59,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);
return nullptr;
} else {
@ -84,7 +86,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;

@ -1638,6 +1638,8 @@ src/core/lib/gpr/log_windows.cc \
src/core/lib/gpr/murmur_hash.cc \
src/core/lib/gpr/murmur_hash.h \
src/core/lib/gpr/spinlock.h \
src/core/lib/gpr/strerror.cc \
src/core/lib/gpr/strerror.h \
src/core/lib/gpr/string.cc \
src/core/lib/gpr/string.h \
src/core/lib/gpr/string_posix.cc \

@ -1477,6 +1477,8 @@ src/core/lib/gpr/log_windows.cc \
src/core/lib/gpr/murmur_hash.cc \
src/core/lib/gpr/murmur_hash.h \
src/core/lib/gpr/spinlock.h \
src/core/lib/gpr/strerror.cc \
src/core/lib/gpr/strerror.h \
src/core/lib/gpr/string.cc \
src/core/lib/gpr/string.h \
src/core/lib/gpr/string_posix.cc \

Loading…
Cancel
Save