From be4f9125f0599195ae74a6bc3d0a6234e0b3a85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 15 Aug 2018 14:00:17 +0300 Subject: [PATCH] Fix mxb_strerror The function should not be an inline function with a static variable. This appears to cause problems on at least Debian Wheezy and is likely to cause odd behavior on other platforms. Also renamed the file to to better mirror how the file behaves. --- maxutils/maxbase/include/maxbase/string.h | 20 +++++++++++++++++++ maxutils/maxbase/src/CMakeLists.txt | 1 + maxutils/maxbase/src/logger.cc | 2 +- .../maxbase/error.h => src/string.cc} | 14 ++++++++----- server/core/log_manager.cc | 2 +- 5 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 maxutils/maxbase/include/maxbase/string.h rename maxutils/maxbase/{include/maxbase/error.h => src/string.cc} (78%) diff --git a/maxutils/maxbase/include/maxbase/string.h b/maxutils/maxbase/include/maxbase/string.h new file mode 100644 index 000000000..efa65cc4f --- /dev/null +++ b/maxutils/maxbase/include/maxbase/string.h @@ -0,0 +1,20 @@ +#pragma once +/* + * Copyright (c) 2016 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl11. + * + * Change Date: 2022-01-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ + +#include + +/** + * Thread-safe strerror + */ +const char* mxb_strerror(int error); diff --git a/maxutils/maxbase/src/CMakeLists.txt b/maxutils/maxbase/src/CMakeLists.txt index f85b7c2ce..be1f59835 100644 --- a/maxutils/maxbase/src/CMakeLists.txt +++ b/maxutils/maxbase/src/CMakeLists.txt @@ -3,6 +3,7 @@ add_library(maxbase STATIC eventcount.cc logger.cc stopwatch.cc + string.cc stacktrace.cc ) set_target_properties(maxbase PROPERTIES VERSION "1.0.0" LINK_FLAGS -Wl,-z,defs) diff --git a/maxutils/maxbase/src/logger.cc b/maxutils/maxbase/src/logger.cc index 4d74eea66..d784f0a80 100644 --- a/maxutils/maxbase/src/logger.cc +++ b/maxutils/maxbase/src/logger.cc @@ -22,7 +22,7 @@ #include #include -#include +#include // TODO: move into maxbase #define ss_dassert(a) diff --git a/maxutils/maxbase/include/maxbase/error.h b/maxutils/maxbase/src/string.cc similarity index 78% rename from maxutils/maxbase/include/maxbase/error.h rename to maxutils/maxbase/src/string.cc index 8172935e6..673582f95 100644 --- a/maxutils/maxbase/include/maxbase/error.h +++ b/maxutils/maxbase/src/string.cc @@ -1,4 +1,3 @@ -#pragma once /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -12,14 +11,19 @@ * Public License. */ -#include +#include #include -inline const char* mxb_strerror(int error) +namespace +{ + +thread_local char errbuf[512]; // Enough for all errors + +} + +const char* mxb_strerror(int error) { - // Enough for all errors - static thread_local char errbuf[512]; #ifdef HAVE_GLIBC return strerror_r(error, errbuf, sizeof(errbuf)); #else diff --git a/server/core/log_manager.cc b/server/core/log_manager.cc index ed4bcc7bd..6253b12ff 100644 --- a/server/core/log_manager.cc +++ b/server/core/log_manager.cc @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include