From 0b1798412b2f817334b931fb8897a0bb1253208c Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 20 Jan 2021 16:33:27 +0100 Subject: [PATCH] Revert "Wrap strerror into a thread-safe implementation" --- BUILD | 2 - BUILD.gn | 2 - CMakeLists.txt | 1 - Makefile | 1 - build_autogenerated.yaml | 2 - config.m4 | 1 - config.w32 | 1 - gRPC-C++.podspec | 2 - gRPC-Core.podspec | 3 - grpc.gemspec | 2 - grpc.gyp | 1 - package.xml | 2 - src/core/lib/gpr/cpu_linux.cc | 8 +- src/core/lib/gpr/strerror.cc | 103 ------------------ src/core/lib/gpr/strerror.h | 35 ------ src/core/lib/gpr/tmpfile_posix.cc | 5 +- src/core/lib/gprpp/stat_posix.cc | 5 +- src/core/lib/gprpp/stat_windows.cc | 5 +- src/core/lib/iomgr/error.cc | 9 +- src/core/lib/iomgr/ev_epoll1_linux.cc | 7 +- src/core/lib/iomgr/internal_errqueue.cc | 3 +- .../lib/iomgr/socket_utils_common_posix.cc | 5 +- src/core/lib/iomgr/tcp_server_posix.cc | 10 +- src/core/lib/iomgr/udp_server.cc | 15 +-- src/core/lib/iomgr/wakeup_fd_pipe.cc | 4 +- src/python/grpcio/grpc_core_dependencies.py | 1 - test/core/iomgr/fd_posix_test.cc | 6 +- test/core/iomgr/tcp_server_posix_test.cc | 3 +- .../network_benchmarks/low_level_ping_pong.cc | 41 +++---- .../alts_concurrent_connectivity_test.cc | 4 +- test/core/util/subprocess_posix.cc | 6 +- tools/doxygen/Doxyfile.c++.internal | 2 - tools/doxygen/Doxyfile.core.internal | 2 - 33 files changed, 49 insertions(+), 250 deletions(-) delete mode 100644 src/core/lib/gpr/strerror.cc delete mode 100644 src/core/lib/gpr/strerror.h diff --git a/BUILD b/BUILD index 9702615098f..4836f557cd3 100644 --- a/BUILD +++ b/BUILD @@ -540,7 +540,6 @@ 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", @@ -577,7 +576,6 @@ 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", diff --git a/BUILD.gn b/BUILD.gn index 1eefe41a37a..472d2cac4c4 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -117,8 +117,6 @@ 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", diff --git a/CMakeLists.txt b/CMakeLists.txt index 64a4a9076e5..17a177d2369 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1307,7 +1307,6 @@ 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 diff --git a/Makefile b/Makefile index 92b71ef0b0a..d895d2a6256 100644 --- a/Makefile +++ b/Makefile @@ -920,7 +920,6 @@ 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 \ diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 45dd397425d..184326d9cea 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -283,7 +283,6 @@ 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 @@ -326,7 +325,6 @@ 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 diff --git a/config.m4 b/config.m4 index 41af622e0ea..601d4dc929b 100644 --- a/config.m4 +++ b/config.m4 @@ -354,7 +354,6 @@ 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 \ diff --git a/config.w32 b/config.w32 index 20ea0fd10d1..0497b183453 100644 --- a/config.w32 +++ b/config.w32 @@ -321,7 +321,6 @@ 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 " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 3b65e4d429b..00986eae727 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -486,7 +486,6 @@ 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', @@ -1105,7 +1104,6 @@ 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', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index d10a315a398..00736e45f0a 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -790,8 +790,6 @@ 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', @@ -1638,7 +1636,6 @@ 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', diff --git a/grpc.gemspec b/grpc.gemspec index 4db7ee3e805..1fe90b67e38 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -705,8 +705,6 @@ 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 ) diff --git a/grpc.gyp b/grpc.gyp index d8a2616c233..23e251b4efb 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -404,7 +404,6 @@ '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', diff --git a/package.xml b/package.xml index e7ec113e033..0dda7e37f4b 100644 --- a/package.xml +++ b/package.xml @@ -685,8 +685,6 @@ - - diff --git a/src/core/lib/gpr/cpu_linux.cc b/src/core/lib/gpr/cpu_linux.cc index 34656c438ae..2e16e3d992e 100644 --- a/src/core/lib/gpr/cpu_linux.cc +++ b/src/core/lib/gpr/cpu_linux.cc @@ -33,15 +33,12 @@ #include #include -#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", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno)); ncpus = 1; return; } @@ -71,8 +68,7 @@ unsigned gpr_cpu_current_cpu(void) { } int cpu = sched_getcpu(); if (cpu < 0) { - gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno)); return 0; } if (static_cast(cpu) >= gpr_cpu_num_cores()) { diff --git a/src/core/lib/gpr/strerror.cc b/src/core/lib/gpr/strerror.cc deleted file mode 100644 index 0cc8cd02342..00000000000 --- a/src/core/lib/gpr/strerror.cc +++ /dev/null @@ -1,103 +0,0 @@ -/* - * - * 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 - -#include "src/core/lib/gpr/strerror.h" - -#include -#include -#include -#include -#include -#include -#include - -// 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::value) { - // XSI `strerror_r`; `ret` is `int`: - if (ret) *buf = '\0'; - return buf; - } else { - // GNU `strerror_r`; `ret` is `char *`: - return reinterpret_cast(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* NewStrErrorTable() { - auto* table = new std::array; - for (int i = 0; i < static_cast(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(table->size())) { - return (*table)[errnum]; - } - return StrErrorInternal(errnum); -} - -} // namespace grpc_core diff --git a/src/core/lib/gpr/strerror.h b/src/core/lib/gpr/strerror.h deleted file mode 100644 index f1e85129599..00000000000 --- a/src/core/lib/gpr/strerror.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * 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 - -#include - -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 */ diff --git a/src/core/lib/gpr/tmpfile_posix.cc b/src/core/lib/gpr/tmpfile_posix.cc index b4b7f214de6..ffdad335d67 100644 --- a/src/core/lib/gpr/tmpfile_posix.cc +++ b/src/core/lib/gpr/tmpfile_posix.cc @@ -31,7 +31,6 @@ #include #include -#include "src/core/lib/gpr/strerror.h" #include "src/core/lib/gpr/string.h" FILE* gpr_tmpfile(const char* prefix, char** tmp_filename) { @@ -47,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, grpc_core::StrError(errno).c_str()); + filename_template, strerror(errno)); 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, grpc_core::StrError(errno).c_str()); + filename_template, fd, strerror(errno)); unlink(filename_template); close(fd); goto end; diff --git a/src/core/lib/gprpp/stat_posix.cc b/src/core/lib/gprpp/stat_posix.cc index a77faeae875..888361bf2aa 100644 --- a/src/core/lib/gprpp/stat_posix.cc +++ b/src/core/lib/gprpp/stat_posix.cc @@ -25,7 +25,6 @@ #include -#include "src/core/lib/gpr/strerror.h" #include "src/core/lib/gprpp/stat.h" namespace grpc_core { @@ -35,9 +34,9 @@ absl::Status GetFileModificationTime(const char* filename, time_t* timestamp) { GPR_ASSERT(timestamp != nullptr); struct stat buf; if (stat(filename, &buf) != 0) { - std::string error_msg = StrError(errno); + const char* error_msg = strerror(errno); gpr_log(GPR_ERROR, "stat failed for filename %s with error %s.", filename, - error_msg.c_str()); + error_msg); return absl::Status(absl::StatusCode::kInternal, error_msg); } // Last file/directory modification time. diff --git a/src/core/lib/gprpp/stat_windows.cc b/src/core/lib/gprpp/stat_windows.cc index 6e2ea434872..f1435e03305 100644 --- a/src/core/lib/gprpp/stat_windows.cc +++ b/src/core/lib/gprpp/stat_windows.cc @@ -24,7 +24,6 @@ #include -#include "src/core/lib/gpr/strerror.h" #include "src/core/lib/gprpp/stat.h" namespace grpc_core { @@ -34,9 +33,9 @@ absl::Status GetFileModificationTime(const char* filename, time_t* timestamp) { GPR_ASSERT(timestamp != nullptr); struct _stat buf; if (_stat(filename, &buf) != 0) { - std::string error_msg = StrError(errno); + const char* error_msg = strerror(errno); gpr_log(GPR_ERROR, "_stat failed for filename %s with error %s.", filename, - error_msg.c_str()); + error_msg); return absl::Status(absl::StatusCode::kInternal, error_msg); } // Last file/directory modification time. diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index 38115fe475a..091014593ee 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -32,7 +32,6 @@ #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" @@ -778,15 +777,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_cpp_string(err_string), nullptr, - 0), + grpc_slice_from_static_string(strerror(err)), + nullptr, 0), GRPC_ERROR_INT_ERRNO, err), - GRPC_ERROR_STR_OS_ERROR, grpc_slice_from_cpp_string(err_string)), + GRPC_ERROR_STR_OS_ERROR, + grpc_slice_from_static_string(strerror(err))), GRPC_ERROR_STR_SYSCALL, grpc_slice_from_copied_string(call_name)); } diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index c59bf9e6bb4..8a1013da21f 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -49,7 +49,6 @@ #include #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" @@ -372,8 +371,7 @@ static grpc_fd* fd_create(int fd, const char* name, bool track_err) { ev.data.ptr = reinterpret_cast(reinterpret_cast(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", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "epoll_ctl failed: %s", strerror(errno)); } return new_fd; @@ -394,8 +392,7 @@ 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", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "epoll_ctl failed: %s", strerror(errno)); } } fd->write_closure->SetShutdown(GRPC_ERROR_REF(why)); diff --git a/src/core/lib/iomgr/internal_errqueue.cc b/src/core/lib/iomgr/internal_errqueue.cc index bd5b97b35a6..b68c66b7575 100644 --- a/src/core/lib/iomgr/internal_errqueue.cc +++ b/src/core/lib/iomgr/internal_errqueue.cc @@ -21,7 +21,6 @@ #include "src/core/lib/iomgr/port.h" #include -#include "src/core/lib/gpr/strerror.h" #include "src/core/lib/iomgr/internal_errqueue.h" #ifdef GRPC_POSIX_SOCKET_TCP @@ -42,7 +41,7 @@ void grpc_errqueue_init() { #ifdef GRPC_LINUX_ERRQUEUE struct utsname buffer; if (uname(&buffer) != 0) { - gpr_log(GPR_ERROR, "uname: %s", StrError(errno).c_str()); + gpr_log(GPR_ERROR, "uname: %s", strerror(errno)); return; } char* release = buffer.release; diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc index 0b94d8a3d4b..fa7f893f72c 100644 --- a/src/core/lib/iomgr/socket_utils_common_posix.cc +++ b/src/core/lib/iomgr/socket_utils_common_posix.cc @@ -48,7 +48,6 @@ #include #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" @@ -364,12 +363,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", - grpc_core::StrError(errno).c_str()); + strerror(errno)); return GRPC_ERROR_NONE; } if (0 != getsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &newval, &len)) { gpr_log(GPR_ERROR, "getsockopt(TCP_USER_TIMEOUT) %s", - grpc_core::StrError(errno).c_str()); + strerror(errno)); return GRPC_ERROR_NONE; } if (newval != timeout) { diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc index d47bd359b69..d6e13e81d15 100644 --- a/src/core/lib/iomgr/tcp_server_posix.cc +++ b/src/core/lib/iomgr/tcp_server_posix.cc @@ -48,7 +48,6 @@ #include #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" @@ -214,8 +213,7 @@ 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", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Failed accept4: %s", strerror(errno)); } else { /* if we have shutdown listeners, accept4 could fail, and we needn't notify users */ @@ -232,8 +230,7 @@ static void on_read(void* arg, grpc_error* err) { addr.len = static_cast(sizeof(struct sockaddr_storage)); if (getsockname(fd, reinterpret_cast(addr.addr), &(addr.len)) < 0) { - gpr_log(GPR_ERROR, "Failed getsockname: %s", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Failed getsockname: %s", strerror(errno)); close(fd); goto error; } @@ -583,8 +580,7 @@ class ExternalConnectionHandler : public grpc_core::TcpServerFdHandler { if (getpeername(fd, reinterpret_cast(addr.addr), &(addr.len)) < 0) { - gpr_log(GPR_ERROR, "Failed getpeername: %s", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Failed getpeername: %s", strerror(errno)); close(fd); return; } diff --git a/src/core/lib/iomgr/udp_server.cc b/src/core/lib/iomgr/udp_server.cc index d318fb2a129..c2eacc5053d 100644 --- a/src/core/lib/iomgr/udp_server.cc +++ b/src/core/lib/iomgr/udp_server.cc @@ -57,7 +57,6 @@ #include #include #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" @@ -368,13 +367,11 @@ 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, - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Unable to set nonblocking %d: %s", fd, strerror(errno)); goto error; } if (grpc_set_socket_cloexec(fd, 1) != GRPC_ERROR_NONE) { - gpr_log(GPR_ERROR, "Unable to set cloexec %d: %s", fd, - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Unable to set cloexec %d: %s", fd, strerror(errno)); goto error; } @@ -416,8 +413,7 @@ 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(), - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "bind addr=%s: %s", addr_str.c_str(), strerror(errno)); goto error; } @@ -426,7 +422,7 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd, if (getsockname(fd, reinterpret_cast(sockname_temp.addr), &sockname_temp.len) < 0) { gpr_log(GPR_ERROR, "Unable to get the address socket %d is bound to: %s", - fd, grpc_core::StrError(errno).c_str()); + fd, strerror(errno)); goto error; } @@ -674,8 +670,7 @@ 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", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Unable to create socket: %s", strerror(errno)); } if (dsmode == GRPC_DSMODE_IPV4 && grpc_sockaddr_is_v4mapped(addr, &addr4_copy)) { diff --git a/src/core/lib/iomgr/wakeup_fd_pipe.cc b/src/core/lib/iomgr/wakeup_fd_pipe.cc index 475e6eba1f1..797cd44cd1a 100644 --- a/src/core/lib/iomgr/wakeup_fd_pipe.cc +++ b/src/core/lib/iomgr/wakeup_fd_pipe.cc @@ -31,15 +31,13 @@ #include -#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, - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "pipe creation failed (%d): %s", errno, strerror(errno)); return GRPC_OS_ERROR(errno, "pipe"); } grpc_error* err; diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 3baf7dd56ca..008482e043b 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -330,7 +330,6 @@ 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', diff --git a/test/core/iomgr/fd_posix_test.cc b/test/core/iomgr/fd_posix_test.cc index f9841c14ce6..e0b29abb454 100644 --- a/test/core/iomgr/fd_posix_test.cc +++ b/test/core/iomgr/fd_posix_test.cc @@ -41,7 +41,6 @@ #include #include -#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" @@ -161,8 +160,7 @@ 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", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Unhandled read error %s", strerror(errno)); abort(); } } @@ -328,7 +326,7 @@ static void client_session_write(void* arg, /*client */ } gpr_mu_unlock(g_mu); } else { - gpr_log(GPR_ERROR, "unknown errno %s", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "unknown errno %s", strerror(errno)); abort(); } } diff --git a/test/core/iomgr/tcp_server_posix_test.cc b/test/core/iomgr/tcp_server_posix_test.cc index 7d570d03461..1441c0d54e5 100644 --- a/test/core/iomgr/tcp_server_posix_test.cc +++ b/test/core/iomgr/tcp_server_posix_test.cc @@ -40,7 +40,6 @@ #include #include -#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" @@ -458,7 +457,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", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "getifaddrs: %s", strerror(errno)); return EXIT_FAILURE; } dst_addrs->naddrs = 0; diff --git a/test/core/network_benchmarks/low_level_ping_pong.cc b/test/core/network_benchmarks/low_level_ping_pong.cc index 0e0155543bb..a983b1876d6 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.cc +++ b/test/core/network_benchmarks/low_level_ping_pong.cc @@ -38,7 +38,6 @@ #include #include -#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" @@ -81,8 +80,7 @@ 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", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Read failed: %s", strerror(errno)); return -1; } } else { @@ -115,8 +113,7 @@ 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", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Poll failed: %s", strerror(errno)); return -1; } } @@ -127,7 +124,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", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Read failed: %s", strerror(errno)); return -1; } bytes_read += static_cast(err2); @@ -156,8 +153,7 @@ 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", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "epoll_wait failed: %s", strerror(errno)); return -1; } if (err == 0 && spin) continue; @@ -203,8 +199,7 @@ static int blocking_write_bytes(struct thread_args* args, char* buf) { if (errno == EINTR) { continue; } else { - gpr_log(GPR_ERROR, "Read failed: %s", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Read failed: %s", strerror(errno)); return -1; } } else { @@ -242,7 +237,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", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "epoll_create: %s", strerror(errno)); return -1; } @@ -251,7 +246,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", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "epoll_ctl: %s", strerror(errno)); } return 0; } @@ -335,8 +330,7 @@ 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", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Unable to create socket: %s", strerror(errno)); goto error; } @@ -354,17 +348,17 @@ static int create_listening_socket(struct sockaddr* port, socklen_t len) { } if (bind(fd, port, len) < 0) { - gpr_log(GPR_ERROR, "bind: %s", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "bind: %s", strerror(errno)); goto error; } if (listen(fd, 1) < 0) { - gpr_log(GPR_ERROR, "listen: %s", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "listen: %s", strerror(errno)); goto error; } if (getsockname(fd, port, &len) < 0) { - gpr_log(GPR_ERROR, "getsockname: %s", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "getsockname: %s", strerror(errno)); goto error; } @@ -381,8 +375,7 @@ 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", - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Unable to create socket: %s", strerror(errno)); goto error; } @@ -400,7 +393,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", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "connect error: %s", strerror(errno)); goto error; } return fd; @@ -415,7 +408,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", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "Accept failed: %s", strerror(errno)); return -1; } return fd; @@ -474,7 +467,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", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "socketpair: %s", strerror(errno)); return -1; } @@ -489,12 +482,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", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "pipe: %s", strerror(errno)); return -1; } if (pipe(sfds) < 0) { - gpr_log(GPR_ERROR, "pipe: %s", grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "pipe: %s", strerror(errno)); return -1; } diff --git a/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc b/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc index 2477105c817..bc2eca1a61b 100644 --- a/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc +++ b/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc @@ -45,7 +45,6 @@ #include #include -#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" @@ -460,8 +459,7 @@ class FakeTcpServer { gpr_log(GPR_ERROR, "Fake TCP server encountered unexpected error:%d |%s| " "sending %d bytes on fd:%d", - errno, grpc_core::StrError(errno).c_str(), bytes_to_send, - fd_); + errno, strerror(errno), bytes_to_send, fd_); GPR_ASSERT(0); } else if (bytes_sent > 0) { total_bytes_sent_ += bytes_sent; diff --git a/test/core/util/subprocess_posix.cc b/test/core/util/subprocess_posix.cc index a6b2c29823a..ab288d777fc 100644 --- a/test/core/util/subprocess_posix.cc +++ b/test/core/util/subprocess_posix.cc @@ -34,7 +34,6 @@ #include #include -#include "src/core/lib/gpr/strerror.h" #include "test/core/util/subprocess.h" struct gpr_subprocess { @@ -59,8 +58,7 @@ 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], - grpc_core::StrError(errno).c_str()); + gpr_log(GPR_ERROR, "execv '%s' failed: %s", exec_args[0], strerror(errno)); _exit(1); return nullptr; } else { @@ -86,7 +84,7 @@ retry: goto retry; } gpr_log(GPR_ERROR, "waitpid failed for pid %d: %s", p->pid, - grpc_core::StrError(errno).c_str()); + strerror(errno)); return -1; } p->joined = true; diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 575aedde096..8f5132b30ce 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1636,8 +1636,6 @@ 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 \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 891a3c12d84..c6b920dfc3c 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1475,8 +1475,6 @@ 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 \