mirror of
https://gitee.com/wangbin579/cetus.git
synced 2024-12-04 04:48:04 +08:00
Merge pull request #125 from tsthght/enhance/optimize
Optimize more code hinted by coverity scan
This commit is contained in:
commit
cc5be3cf77
@ -1802,7 +1802,7 @@ void admin_select_single_table(network_mysqld_con* con)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void admin_sql_log_start(network_mysqld_con* con) {
|
void admin_sql_log_start(network_mysqld_con* con) {
|
||||||
if (!con || !con->srv || !con->srv->sql_mgr) {
|
if (!con->srv->sql_mgr) {
|
||||||
network_mysqld_con_send_error(con->client, C("Unexpected error"));
|
network_mysqld_con_send_error(con->client, C("Unexpected error"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1819,7 +1819,7 @@ void admin_sql_log_start(network_mysqld_con* con) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void admin_sql_log_stop(network_mysqld_con* con) {
|
void admin_sql_log_stop(network_mysqld_con* con) {
|
||||||
if (!con || !con->srv || !con->srv->sql_mgr) {
|
if (!con->srv->sql_mgr) {
|
||||||
network_mysqld_con_send_error(con->client, C("Unexpected error"));
|
network_mysqld_con_send_error(con->client, C("Unexpected error"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1832,7 +1832,7 @@ void admin_sql_log_stop(network_mysqld_con* con) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void admin_sql_log_status(network_mysqld_con* con) {
|
void admin_sql_log_status(network_mysqld_con* con) {
|
||||||
if (!con || !con->srv || !con->srv->sql_mgr) {
|
if (!con->srv->sql_mgr) {
|
||||||
network_mysqld_con_send_error(con->client, C("Unexpected error"));
|
network_mysqld_con_send_error(con->client, C("Unexpected error"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,10 @@ static void sql_log_check_rotate(struct sql_log_mgr *mgr) {
|
|||||||
mgr->sql_log_action = SQL_LOG_STOP;
|
mgr->sql_log_action = SQL_LOG_STOP;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fstat(fileno(mgr->sql_log_fp), &st);
|
gint rst = fstat(fileno(mgr->sql_log_fp), &st);
|
||||||
|
if (rst != 0) {
|
||||||
|
g_message("fstat() failed in sql_log_mainloop");
|
||||||
|
}
|
||||||
mgr->sql_log_cursize = st.st_size;
|
mgr->sql_log_cursize = st.st_size;
|
||||||
g_message("sql log thread started");
|
g_message("sql log thread started");
|
||||||
mgr->sql_log_action = SQL_LOG_START;
|
mgr->sql_log_action = SQL_LOG_START;
|
||||||
@ -342,13 +345,11 @@ sql_log_thread_start(struct sql_log_mgr *mgr) {
|
|||||||
if (mgr->sql_log_path == NULL) {
|
if (mgr->sql_log_path == NULL) {
|
||||||
mgr->sql_log_path = g_strdup(SQL_LOG_DEF_PATH);
|
mgr->sql_log_path = g_strdup(SQL_LOG_DEF_PATH);
|
||||||
}
|
}
|
||||||
int result = access(mgr->sql_log_path, F_OK);
|
gint result = mkdir(mgr->sql_log_path, 0770);
|
||||||
if (result != 0) {
|
if (!result) {
|
||||||
g_message("sql log path is not exist, try to mkdir");
|
g_message("sql log path maybe exist, try to mkdir failed");
|
||||||
result = mkdir(mgr->sql_log_path, 0660);
|
} else {
|
||||||
if (result != 0) {
|
g_message("sql log path is not exist, try to mkdir success");
|
||||||
g_message("mkdir(%s) failed", mgr->sql_log_path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (mgr->sql_log_fullname == NULL) {
|
if (mgr->sql_log_fullname == NULL) {
|
||||||
mgr->sql_log_fullname = g_strdup_printf("%s/%s-%d.%s", mgr->sql_log_path, mgr->sql_log_prefix, getpid(), SQL_LOG_DEF_SUFFIX);
|
mgr->sql_log_fullname = g_strdup_printf("%s/%s-%d.%s", mgr->sql_log_path, mgr->sql_log_prefix, getpid(), SQL_LOG_DEF_SUFFIX);
|
||||||
@ -486,7 +487,7 @@ log_sql_backend_sharding(network_mysqld_con *con, server_session_t *session)
|
|||||||
session->is_in_xa ==1 ? "true" : "false", com_dis_tras_state[xa_state],
|
session->is_in_xa ==1 ? "true" : "false", com_dis_tras_state[xa_state],
|
||||||
latency_ms, session->query_status == MYSQLD_PACKET_OK ? "OK" : "ERR",
|
latency_ms, session->query_status == MYSQLD_PACKET_OK ? "OK" : "ERR",
|
||||||
GET_COM_NAME(con->parse.command),//type
|
GET_COM_NAME(con->parse.command),//type
|
||||||
con->parse.command == 23 ? "" : (session->sql != NULL ? session->sql->str : ""));//sql
|
con->parse.command == COM_STMT_EXECUTE ? "" : (session->sql != NULL ? session->sql->str : ""));//sql
|
||||||
}
|
}
|
||||||
rfifo_write(mgr->fifo, message->str, message->len);
|
rfifo_write(mgr->fifo, message->str, message->len);
|
||||||
g_string_free(message, TRUE);
|
g_string_free(message, TRUE);
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#define GET_COM_NAME(com_type) \
|
#define GET_COM_NAME(com_type) \
|
||||||
((((gushort)com_type) >= 0 && ((gushort)com_type) <= 31) ? com_command_name[((gushort)com_type)].com_str : "UNKNOWN TYPE")
|
((((gushort)com_type) >= 0 && ((gushort)com_type) <= 31) ? com_command_name[((gushort)com_type)].com_str : "UNKNOWN TYPE")
|
||||||
#define GET_COM_STRING(query) GET_COM_NAME((query)->str[0]), ((query)->len > 1 ? ((query)->str + 1) : "")
|
#define GET_COM_STRING(query) ((query)->len > 1 ? ((query)->str + 1) : "")
|
||||||
|
|
||||||
typedef struct com_string {
|
typedef struct com_string {
|
||||||
char *com_str;
|
char *com_str;
|
||||||
|
Loading…
Reference in New Issue
Block a user