Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding cli params for pid and cwd #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions proxysql_binlog_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void daemonize_wait_daemon() {
}


bool daemonize_phase2() {
bool daemonize_phase2(std::string cwd) {
int rc;
/* Close FDs */
if (daemon_close_all(-1) < 0) {
Expand All @@ -133,9 +133,9 @@ bool daemonize_phase2() {
return false;
}

rc=chdir("/tmp");
rc=chdir(cwd.c_str());
if (rc) {
daemon_log(LOG_ERR, "Could not chdir into datadir: %s . Error: %s", "/tmp", strerror(errno));
daemon_log(LOG_ERR, "Could not chdir into datadir: %s . Error: %s", cwd.c_str(), strerror(errno));
exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -223,13 +223,13 @@ bool daemonize_phase3() {
return true;
}

void daemonize_phase1(char *argv0) {
void daemonize_phase1(char *argv0, std::string pid_file, std::string cwd) {
int rc;
daemon_pid_file_ident="/tmp/proxysql_mysqlbinlog.pid";
const char *daemon_pid_file_ident=pid_file.c_str();
daemon_log_ident=daemon_ident_from_argv0(argv0);
rc=chdir("/tmp");
rc=chdir(cwd.c_str());
if (rc) {
daemon_log(LOG_ERR, "Could not chdir into datadir: %s . Error: %s", "/tmp", strerror(errno));
daemon_log(LOG_ERR, "Could not chdir into datadir: %s . Error: %s", cwd.c_str(), strerror(errno));
exit(EXIT_FAILURE);
}
daemon_pid_file_proc=proxysql_binlog_pid_file;
Expand Down Expand Up @@ -287,7 +287,7 @@ class Client_Data {
ip = (char *)malloc(strlen(a)+16);
sprintf(ip,"%s:%d",a,p);
}

bool writeout() {
bool ret = true;
if (len==0) {
Expand Down Expand Up @@ -378,7 +378,7 @@ void read_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) {
}

void accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) {
typedef union {
typedef union {
struct sockaddr_in in;
struct sockaddr_in6 in6;
} custom_sockaddr;
Expand Down Expand Up @@ -432,7 +432,7 @@ void accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) {
//proxy_info("Adding client with FD %d\n", client->fd);
Clients.push_back(client);
} else {
proxy_info("Error accepting client with FD %d\n", client->fd);
proxy_info("Error accepting client with FD %d\n", client->fd);
delete custom_data;
free(client);
}
Expand Down Expand Up @@ -485,7 +485,7 @@ void async_cb(struct ev_loop *loop, struct ev_async *watcher, int revents) {
}
server_uuids.clear();
trx_ids.clear();

pthread_mutex_unlock(&pos_mutex);
return;
}
Expand Down Expand Up @@ -606,7 +606,7 @@ std::string gtid_executed_to_string(slave::Position &curpos) {


void usage(const char* name) {
std::cout << "Usage: " << name << " -h <mysql host> -u <mysql user> -p <mysql password> -P <mysql port> -l <listen port> -L <log file>" << std::endl;
std::cout << "Usage: " << name << " -h <mysql host> -u <mysql user> -p <mysql password> -P <mysql port> -l <listen port> -L <log file> -i <Pid file> -c <current working dir>" << std::endl;
}


Expand All @@ -620,14 +620,16 @@ int main(int argc, char** argv) {
std::string user;
std::string password;
std::string errorstr;
std::string pid_file="/tmp/proxysql_mysqlbinlog.pid";
std::string cwd="/tmp";
unsigned int port = 3306;


bool error = false;


int c;
while (-1 != (c = ::getopt(argc, argv, "fh:u:p:P:l:L:"))) {
while (-1 != (c = ::getopt(argc, argv, "fh:u:p:P:l:L:i:c:"))) {
switch (c) {
case 'f': foreground=true; break;
case 'h': host = optarg; break;
Expand All @@ -639,6 +641,8 @@ int main(int argc, char** argv) {
case 'P': port = std::stoi(optarg); break;
case 'l': listen_port = std::stoi(optarg); break;
case 'L' : errorstr = optarg; break;
case 'i': pid_file = optarg; break;
case 'c': cwd = optarg; break;
default:
usage(argv[0]);
return 1;
Expand All @@ -663,7 +667,7 @@ int main(int argc, char** argv) {


if (foreground==false) {
daemonize_phase1((char *)argv[0]);
daemonize_phase1((char *)argv[0], pid_file, cwd);
if ((pid = daemon_fork()) < 0) {
/* Exit on error */
daemon_retval_done();
Expand All @@ -674,7 +678,7 @@ int main(int argc, char** argv) {
daemonize_wait_daemon();

} else {
if (daemonize_phase2()==false) {
if (daemonize_phase2(cwd)==false) {
goto finish;
}

Expand Down