39
40
#define DRIZZLE_UNIX_SOCKET_PATH "/tmp/mysql.socket"
41
static std::string unix_socket_path(DRIZZLE_UNIX_SOCKET_PATH);
43
42
namespace po= boost::program_options;
43
namespace fs= boost::filesystem;
44
44
using namespace drizzled;
45
45
using namespace std;
50
50
Protocol::~Protocol()
52
fs::remove(unix_socket_path);
54
55
const char* Protocol::getHost(void) const
56
return DRIZZLE_UNIX_SOCKET_PATH;
57
return unix_socket_path.file_string().c_str();
59
60
in_port_t Protocol::getPort(void) const
66
67
const module::option_map &vm= context.getOptions();
70
unix_socket_path.clear();
71
unix_socket_path.append(vm["path"].as<string>());
74
context.add(new Protocol("mysql_unix_socket_protocol", true));
69
fs::path uds_path(vm["path"].as<fs::path>());
70
if (not fs::exists(uds_path))
72
context.add(new Protocol("mysql_unix_socket_protocol",
75
context.registerVariable(new sys_var_fs_path("path", uds_path));
79
cerr << uds_path << _(" exists already. Do you have another Drizzle or "
80
"MySQL running? Or perhaps the file is stale and "
81
"should be removed?") << std::endl;
91
100
memset(&servAddr, 0, sizeof(servAddr));
93
102
servAddr.sun_family= AF_UNIX;
94
strcpy(servAddr.sun_path, unix_socket_path.c_str());
103
strcpy(servAddr.sun_path, unix_socket_path.file_string().c_str());
96
105
// In case we restart and find something in our way we move it aside and
97
106
// then attempt to remove it.
99
std::string move_file(unix_socket_path);
100
move_file.append(".old");
101
std::rename(unix_socket_path.c_str(), move_file.c_str());
102
unlink(move_file.c_str());
108
fs::path move_file(unix_socket_path.file_string() + ".old");
109
fs::rename(unix_socket_path, move_file);
110
unlink(move_file.file_string().c_str());
108
116
(void) setsockopt(unix_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, sizeof(arg));
117
unlink(unix_socket_path.file_string().c_str());
110
119
addrlen= sizeof(servAddr);
111
120
if (::bind(unix_sock, reinterpret_cast<sockaddr *>(&servAddr), addrlen) < 0)
113
std::cerr << "Can't start server : Bind on unix socket\n";
114
std::cerr << "Do you already have another of drizzled or mysqld running on socket: " << unix_socket_path << "?\n";
115
std::cerr << "Can't start server : UNIX Socket";
122
std::cerr << "Can't start server : Bind on unix socket." << std::endl;
123
std::cerr << "Do you already have another of drizzled or mysqld running on socket: " << unix_socket_path << "?" << std::endl;
124
std::cerr << "Can't start server : UNIX Socket" << std::endl;
120
if (listen(unix_sock,(int) 1000) < 0)
129
if (listen(unix_sock, (int) 1000) < 0)
122
131
std::cerr << "listen() on Unix socket failed with error " << errno << "\n";
126
std::cerr << "Listening on " << unix_socket_path.c_str() << "\n";
135
std::cerr << "Listening on " << unix_socket_path << "\n";
128
137
(void) unlink(unix_socket_path.c_str());
136
145
static void init_options(drizzled::module::option_context &context)
139
po::value<string>()->default_value(unix_socket_path),
148
po::value<fs::path>()->default_value(DRIZZLE_UNIX_SOCKET_PATH),
140
149
N_("Path used for MySQL UNIX Socket Protocol."));
143
static drizzle_sys_var* sys_variables[]= {
147
152
} /* namespace mysql_unix_socket_protocol */
149
DRIZZLE_PLUGIN(mysql_unix_socket_protocol::init, mysql_unix_socket_protocol::sys_variables, mysql_unix_socket_protocol::init_options);
154
DRIZZLE_PLUGIN(mysql_unix_socket_protocol::init, NULL, mysql_unix_socket_protocol::init_options);