Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
win32 and ubsan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
weigon committed Jun 14, 2018
1 parent 8f0881d commit 38fcbaa
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/http/include/mysqlrouter/http_server_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HTTP_SERVER_EXPORT BaseRequestHandler {

virtual void handle_request(HttpRequest &req) = 0;

virtual ~BaseRequestHandler() = default;
virtual ~BaseRequestHandler();
};

class HTTP_SERVER_EXPORT HttpServerComponent {
Expand Down
7 changes: 5 additions & 2 deletions src/http/src/http_server_component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@

#include "mysqlrouter/http_server_component.h"
#include "http_server_plugin.h"
#include "mysql/harness/logging/logging.h"

IMPORT_LOG_FUNCTIONS()
// must be declared in .cc file as otherwise each plugin
// gets its own class-instance of BaseRequestHandler which leads
// to undefined behaviour (ubsan -> vptr)
BaseRequestHandler::~BaseRequestHandler() = default;

//
// HTTP Server's public API
//
Expand Down
30 changes: 14 additions & 16 deletions src/mock_server/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,6 @@ class MysqlServerMockFrontend {
program_name_ = arguments[0];
origin_dir_ = mysql_harness::Path(program_name_).dirname();

char *stage_dir_c = std::getenv("STAGE_DIR");
stage_dir_ = mysql_harness::Path(stage_dir_c ? stage_dir_c : "./stage");
#ifdef CMAKE_INTDIR
if (!origin_dir_.str().empty()) {
stage_dir_ = mysql_harness::Path(stage_dir_.join(origin_dir_.basename()));
}
else {
throw std::runtime_error("Origin dir not set");
}
#endif

prepare_command_options();
arg_handler_.process(std::vector<std::string>{arguments.begin() + 1, arguments.end()});

Expand Down Expand Up @@ -151,11 +140,21 @@ class MysqlServerMockFrontend {
config_.module_prefix = cwd;
}

// log to stderr
loader_config.set_default("logging_folder", "");
loader_config.set_default("plugin_folder", mysql_harness::Path(stage_dir_).join("lib").join("mysqlrouter").str());
loader_config.set_default("runtime_folder", mysql_harness::Path(stage_dir_).join("var").join("lib").str());
loader_config.set_default("config_folder", mysql_harness::Path(stage_dir_).join("etc").str());
loader_config.set_default("data_folder", mysql_harness::Path(stage_dir_).join("var").join("share").str());

// assume all path relative to the installed binary
auto base_path = mysql_harness::Path(origin_dir_).join("..");
loader_config.set_default("plugin_folder", mysql_harness::Path(base_path).join("lib")
#ifndef _WIN32
.join("mysqlrouter")
#endif
.str());

// those are unused, but must be set
loader_config.set_default("runtime_folder", mysql_harness::Path(base_path).join("var").join("lib").str());
loader_config.set_default("config_folder", mysql_harness::Path(base_path).join("etc").str());
loader_config.set_default("data_folder", mysql_harness::Path(base_path).join("var").join("share").str());

if (config_.http_port != 0) {
auto &rest_mock_server_config = loader_config.add("rest_mock_server", "");
Expand Down Expand Up @@ -234,7 +233,6 @@ class MysqlServerMockFrontend {

std::string program_name_;
mysql_harness::Path origin_dir_;
mysql_harness::Path stage_dir_;
};

int main(int argc, char* argv[]) {
Expand Down
14 changes: 10 additions & 4 deletions src/mock_server/src/mysql_server_mock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,19 @@ void MySQLServerMock::handle_connections(mysql_harness::PluginFuncEnv* env) {
if (FD_ISSET(listener_, &fds)) {
while (true) {
socket_t client_socket = accept(listener_, (struct sockaddr*)&client_addr, &addr_size);
if (client_socket < 0) {
if (client_socket == kInvalidSocket) {
auto last_errno = get_socket_errno();

// if we got interrupted at shutdown, just leave
if (!is_running(env)) break;

if (errno == EAGAIN) break;
if (errno == EWOULDBLOCK) break;
if (errno == EINTR) continue;
if (last_errno == EAGAIN) break;
if (last_errno == EWOULDBLOCK) break;
#ifdef _WIN32
if (last_errno == WSAEWOULDBLOCK) break;
if (last_errno == WSAEINTR) continue;
#endif
if (last_errno == EINTR) continue;

std::cerr << "accept() failed: " << get_socket_errno_str() << std::endl;
return;
Expand Down
1 change: 1 addition & 0 deletions tests/component/test_rest_mock_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class RestMockServerTest : public RouterComponentTest, public ::testing::Test {
TcpPortPool port_pool_;

void SetUp() override {
set_origin(g_origin_path);
RouterComponentTest::SetUp();
}

Expand Down

0 comments on commit 38fcbaa

Please sign in to comment.