Skip to content

Commit

Permalink
Merge pull request #4081 from sysown/v2.x-freebsd-fixes
Browse files Browse the repository at this point in the history
FreeBSD fixes - convert current timezone
  • Loading branch information
renecannao committed Jan 27, 2023
2 parents 5ac59bf + 4048a1e commit 6778ec0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ DEBUG=${ALL_DEBUG}
#export OPTZ
#export EXTRALINK
export MAKE
export CURVER?=2.5.0
export CURVER?=2.4.7
ifneq (,$(wildcard /etc/os-release))
DISTRO := $(shell gawk -F= '/^NAME/{print $$2}' /etc/os-release)
else
Expand Down
4 changes: 2 additions & 2 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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}

Expand Down Expand Up @@ -178,7 +178,7 @@ else
echo ">>> Clickhouse CXX11"
cd clickhouse-cpp && ln -fs clickhouse-cpp-1.0.0 clickhouse-cpp
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}
Expand Down
6 changes: 6 additions & 0 deletions include/proxysql_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#include <vector>
#include <sys/time.h>

#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

#ifdef CXX17
template<class...> struct conjunction : std::true_type { };
Expand Down
56 changes: 14 additions & 42 deletions lib/ProxySQL_Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3627,57 +3627,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) {
Expand Down

0 comments on commit 6778ec0

Please sign in to comment.