Use MT-Safe strerror_r instead of strerror
strerror() is MT-Unsafe, because it uses a static buffer under the hood. We should use strerror_r() instead, which takes a user-provided buffer. The problem is there are two implementations of strerror_r(): XSI and GNU. The first one returns an error code and always writes the message to the beginning of the buffer while the second one returns a pointer to a location within the buffer where the message starts. Let's introduce a macro HAVE_STRERROR_R_GNU set if the GNU version is available and define tt_strerror() which writes the message to the static buffer, like tt_cstr() or tt_sprintf(). Note, we have to export tt_strerror(), because it is used by Lua via FFI. We also need to make it available in the module API header, because the say_syserror() macro uses strerror() directly. In order to avoid adding tt_strerror() to the module API, we introduce an internal helper function _say_strerror(), which calls tt_strerror(). NO_DOC=bug fix NO_TEST=code is covered by existing tests (cherry picked from commit 44f46dc8)
Showing
- CMakeLists.txt 7 additions, 0 deletionsCMakeLists.txt
- changelogs/unreleased/strerror-mt-safe.md 4 additions, 0 deletionschangelogs/unreleased/strerror-mt-safe.md
- extra/exports 2 additions, 0 deletionsextra/exports
- src/box/lua/info.c 2 additions, 1 deletionsrc/box/lua/info.c
- src/lib/core/CMakeLists.txt 1 addition, 0 deletionssrc/lib/core/CMakeLists.txt
- src/lib/core/backtrace.c 2 additions, 1 deletionsrc/lib/core/backtrace.c
- src/lib/core/crash.c 6 additions, 4 deletionssrc/lib/core/crash.c
- src/lib/core/evio.c 3 additions, 2 deletionssrc/lib/core/evio.c
- src/lib/core/exception.cc 5 additions, 4 deletionssrc/lib/core/exception.cc
- src/lib/core/say.c 7 additions, 0 deletionssrc/lib/core/say.c
- src/lib/core/say.h 14 additions, 3 deletionssrc/lib/core/say.h
- src/lib/core/tt_strerror.c 25 additions, 0 deletionssrc/lib/core/tt_strerror.c
- src/lib/core/tt_strerror.h 23 additions, 0 deletionssrc/lib/core/tt_strerror.h
- src/lua/errno.lua 2 additions, 2 deletionssrc/lua/errno.lua
- src/main.cc 3 additions, 1 deletionsrc/main.cc
- src/module_header.h 0 additions, 1 deletionsrc/module_header.h
- src/trivia/config.h.cmake 6 additions, 1 deletionsrc/trivia/config.h.cmake
- test/unit/say.c 3 additions, 1 deletiontest/unit/say.c
Loading
Please register or sign in to comment