From 2a2bbb81425799cefb076161c0d6196f7d68b2be Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Fri, 13 Jan 2023 16:01:50 -0500 Subject: [PATCH 1/7] fix sed args --- deps/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/Makefile b/deps/Makefile index 23ef204cd..412683d3c 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -74,7 +74,7 @@ endif ifeq ($(UNAME_S),Darwin) sed -i '' 's/CC=/CC?=/' libinjection/libinjection/src/Makefile else - sed -i 's/CC=/CC?=/' libinjection/libinjection/src/Makefile + sed -i -e 's/CC=/CC?=/' libinjection/libinjection/src/Makefile endif cd libinjection/libinjection && CC=${CC} CXX=${CXX} ${MAKE} libinjection: libinjection/libinjection/src/libinjection.a @@ -180,7 +180,7 @@ else cd clickhouse-cpp && ln -fs clickhouse-cpp-1.0.0 clickhouse-cpp cd clickhouse-cpp && rm -rf clickhouse-cpp-*/ || true cd clickhouse-cpp && tar -zxf v1.0.0.tar.gz && sync - cd clickhouse-cpp && sed -i 's/SET (CMAKE_CXX_STANDARD_REQUIRED ON)//' clickhouse-cpp/cmake/cpp17.cmake + cd clickhouse-cpp && sed -i -e 's/SET (CMAKE_CXX_STANDARD_REQUIRED ON)//' clickhouse-cpp/cmake/cpp17.cmake endif cd clickhouse-cpp/clickhouse-cpp && cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo . cd clickhouse-cpp/clickhouse-cpp && CC=${CC} CXX=${CXX} ${MAKE} From f8a81c8e0d0290e7d98eb1eeb2e772f6871e7831 Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Fri, 13 Jan 2023 16:42:40 -0500 Subject: [PATCH 2/7] reimplement timediff_timezone_offset --- lib/ProxySQL_Admin.cpp | 56 +++++++++++------------------------------- 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 54f8644a9..896d53cc7 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -3626,57 +3626,29 @@ SQLite3_result * ProxySQL_Admin::generate_show_table_status(const char *tablenam return result; } -/** - * @brief Helper function to format the received hours into a string - * in the format ('HH'|'0H'|'-0H'|'-HH'). Depending on the supplied - * number digit count and sign. - * @param num A number to be converted to described format. - * @return std::string holding the converted number. - */ -const std::string format_timezone_hours(const int num) { - std::string result {}; - - const std::string base_num = std::to_string(num); - - if (num < 10 && num >= 0) { - result = "0" + base_num; - } else if (num > -10 && num < 0) { - result = base_num.substr(0, 1) + "0" + base_num.substr(1); - } else if (num <= -10) { - result = base_num; - } - - return result; -} - /** * @brief Helper function that converts the current timezone * expressed in seconds into a string of the format: - * - 'hours' + ':00:00'. + * - '[-]HH:MM:00'. * Following the same pattern as the possible values returned by the SQL query * 'SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP())' in a MySQL server. * @return A string holding the specified representation of the * supplied timezone. */ std::string timediff_timezone_offset() { - // explecitly call 'tzset' to make sure '::timezone' is set - tzset(); - - // get the global variable - long int timezone = ::timezone; - - // first negate the received number - timezone = -timezone; - - // transform into hours - int timezone_offset_hours = timezone / 3600; - - // create an string with the resulting 'hours' + ':00:00' - std::string time_zone_offset { - format_timezone_hours(timezone_offset_hours) + ":00:00" - }; - - return time_zone_offset; + std::string time_zone_offset {}; + char result[8]; + time_t rawtime; + struct tm *info; + int offset; + + time(&rawtime); + info = localtime(&rawtime); + strftime(result, 8, "%z", info); + offset = (result[0] == '+') ? 1 : 0; + time_zone_offset = ((std::string)(result)).substr(offset, 3-offset) + ":" + ((std::string)(result)).substr(3, 2) + ":00"; + + return time_zone_offset; } void admin_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *pkt) { From f319cc455bd51277c3a160ab9dd686f6c03e87ff Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Fri, 13 Jan 2023 16:44:05 -0500 Subject: [PATCH 3/7] define ETIME for FreeBSD --- include/proxysql_utils.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/proxysql_utils.h b/include/proxysql_utils.h index 8a79127d0..6e5ade60d 100644 --- a/include/proxysql_utils.h +++ b/include/proxysql_utils.h @@ -8,6 +8,9 @@ #include #include +#ifdef __FreeBSD__ +#define ETIME ETIMEDOUT +#endif #ifdef CXX17 template struct conjunction : std::true_type { }; From 32436849840da567c0de393ca68ff38fa3332683 Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Fri, 13 Jan 2023 16:01:50 -0500 Subject: [PATCH 4/7] fix sed args --- deps/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/Makefile b/deps/Makefile index 23ef204cd..412683d3c 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -74,7 +74,7 @@ endif ifeq ($(UNAME_S),Darwin) sed -i '' 's/CC=/CC?=/' libinjection/libinjection/src/Makefile else - sed -i 's/CC=/CC?=/' libinjection/libinjection/src/Makefile + sed -i -e 's/CC=/CC?=/' libinjection/libinjection/src/Makefile endif cd libinjection/libinjection && CC=${CC} CXX=${CXX} ${MAKE} libinjection: libinjection/libinjection/src/libinjection.a @@ -180,7 +180,7 @@ else cd clickhouse-cpp && ln -fs clickhouse-cpp-1.0.0 clickhouse-cpp cd clickhouse-cpp && rm -rf clickhouse-cpp-*/ || true cd clickhouse-cpp && tar -zxf v1.0.0.tar.gz && sync - cd clickhouse-cpp && sed -i 's/SET (CMAKE_CXX_STANDARD_REQUIRED ON)//' clickhouse-cpp/cmake/cpp17.cmake + cd clickhouse-cpp && sed -i -e 's/SET (CMAKE_CXX_STANDARD_REQUIRED ON)//' clickhouse-cpp/cmake/cpp17.cmake endif cd clickhouse-cpp/clickhouse-cpp && cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo . cd clickhouse-cpp/clickhouse-cpp && CC=${CC} CXX=${CXX} ${MAKE} From fcfbc17407d9dbd786b4078879f2ed340f166bbf Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Fri, 13 Jan 2023 16:42:40 -0500 Subject: [PATCH 5/7] reimplement timediff_timezone_offset --- lib/ProxySQL_Admin.cpp | 56 +++++++++++------------------------------- 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 54f8644a9..896d53cc7 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -3626,57 +3626,29 @@ SQLite3_result * ProxySQL_Admin::generate_show_table_status(const char *tablenam return result; } -/** - * @brief Helper function to format the received hours into a string - * in the format ('HH'|'0H'|'-0H'|'-HH'). Depending on the supplied - * number digit count and sign. - * @param num A number to be converted to described format. - * @return std::string holding the converted number. - */ -const std::string format_timezone_hours(const int num) { - std::string result {}; - - const std::string base_num = std::to_string(num); - - if (num < 10 && num >= 0) { - result = "0" + base_num; - } else if (num > -10 && num < 0) { - result = base_num.substr(0, 1) + "0" + base_num.substr(1); - } else if (num <= -10) { - result = base_num; - } - - return result; -} - /** * @brief Helper function that converts the current timezone * expressed in seconds into a string of the format: - * - 'hours' + ':00:00'. + * - '[-]HH:MM:00'. * Following the same pattern as the possible values returned by the SQL query * 'SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP())' in a MySQL server. * @return A string holding the specified representation of the * supplied timezone. */ std::string timediff_timezone_offset() { - // explecitly call 'tzset' to make sure '::timezone' is set - tzset(); - - // get the global variable - long int timezone = ::timezone; - - // first negate the received number - timezone = -timezone; - - // transform into hours - int timezone_offset_hours = timezone / 3600; - - // create an string with the resulting 'hours' + ':00:00' - std::string time_zone_offset { - format_timezone_hours(timezone_offset_hours) + ":00:00" - }; - - return time_zone_offset; + std::string time_zone_offset {}; + char result[8]; + time_t rawtime; + struct tm *info; + int offset; + + time(&rawtime); + info = localtime(&rawtime); + strftime(result, 8, "%z", info); + offset = (result[0] == '+') ? 1 : 0; + time_zone_offset = ((std::string)(result)).substr(offset, 3-offset) + ":" + ((std::string)(result)).substr(3, 2) + ":00"; + + return time_zone_offset; } void admin_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *pkt) { From dacec21292dc7b47fe53218c9d886b73b8e109d6 Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Fri, 13 Jan 2023 16:44:05 -0500 Subject: [PATCH 6/7] define ETIME for FreeBSD --- include/proxysql_utils.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/proxysql_utils.h b/include/proxysql_utils.h index 8a79127d0..6e5ade60d 100644 --- a/include/proxysql_utils.h +++ b/include/proxysql_utils.h @@ -8,6 +8,9 @@ #include #include +#ifdef __FreeBSD__ +#define ETIME ETIMEDOUT +#endif #ifdef CXX17 template struct conjunction : std::true_type { }; From f095b7787778a57e86f85f7ac6594f14778d9e0c Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Wed, 18 Jan 2023 11:32:19 +0000 Subject: [PATCH 7/7] define ETIME ifndef and usage note --- include/proxysql_utils.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/proxysql_utils.h b/include/proxysql_utils.h index 6e5ade60d..2d75c4693 100644 --- a/include/proxysql_utils.h +++ b/include/proxysql_utils.h @@ -8,7 +8,10 @@ #include #include -#ifdef __FreeBSD__ +#ifndef ETIME +// ETIME is not defined on FreeBSD +// ETIME is used internaly to report API timer expired +// replace with ETIMEDOUT as closest alternative #define ETIME ETIMEDOUT #endif