mirror of
https://gitee.com/wangbin579/cetus.git
synced 2024-12-02 03:47:41 +08:00
Optimize code hinted by cppcheck
This commit is contained in:
parent
78826aa070
commit
1370d956ae
@ -1232,7 +1232,6 @@ void admin_delete_backend(network_mysqld_con* con, char *key, char *val)
|
||||
}
|
||||
|
||||
chassis_private *g = con->srv->priv;
|
||||
int affected_rows = 0;
|
||||
int backend_ndx = -1;
|
||||
if (strcasecmp(key, "backend_ndx")==0) {
|
||||
backend_ndx = atoi(val);
|
||||
@ -1406,10 +1405,10 @@ void admin_set_config(network_mysqld_con* con, char* key, char* value)
|
||||
return;
|
||||
}
|
||||
|
||||
char msg[128] = {0};
|
||||
GList *options = admin_get_all_options(con->srv);
|
||||
chassis_option_t* opt = chassis_options_get(options, key);
|
||||
if (!opt) {
|
||||
char msg[128] = {0};
|
||||
snprintf(msg, sizeof(msg), "no such variable: %s", key);
|
||||
network_mysqld_con_send_error(con->client, L(msg));
|
||||
g_list_free(options);
|
||||
|
@ -359,10 +359,9 @@ network_read_sql_resp(int G_GNUC_UNUSED fd, short events, void *user_data)
|
||||
int unread_len = ch.admin_sql_resp_len;
|
||||
GString *raw_packet = g_string_sized_new(unread_len);
|
||||
unsigned char *p = raw_packet->str;
|
||||
int len;
|
||||
|
||||
do {
|
||||
len = recv(fd, p, unread_len, 0);
|
||||
int len = recv(fd, p, unread_len, 0);
|
||||
if (len > 0) {
|
||||
g_debug("%s: resp_len:%d, len:%d, fd:%d",
|
||||
G_STRLOC, unread_len, len, fd);
|
||||
|
@ -11,7 +11,6 @@
|
||||
int
|
||||
cetus_write_channel(int s, cetus_channel_t *ch, size_t size)
|
||||
{
|
||||
int err;
|
||||
ssize_t n;
|
||||
struct iovec iov[1];
|
||||
struct msghdr msg;
|
||||
@ -62,7 +61,7 @@ cetus_write_channel(int s, cetus_channel_t *ch, size_t size)
|
||||
|
||||
g_debug("%s: sendmsg fd:%d, n:%d, size:%d", G_STRLOC, s, (int) n, (int) size);
|
||||
if (n == -1) {
|
||||
err = errno;
|
||||
int err = errno;
|
||||
if (err == EAGAIN) {
|
||||
return NETWORK_SOCKET_WAIT_FOR_EVENT;
|
||||
}
|
||||
@ -78,8 +77,6 @@ cetus_write_channel(int s, cetus_channel_t *ch, size_t size)
|
||||
int
|
||||
cetus_read_channel(int s, cetus_channel_t *ch, size_t size)
|
||||
{
|
||||
int fd;
|
||||
int err;
|
||||
ssize_t n;
|
||||
struct iovec iov[1];
|
||||
struct msghdr msg;
|
||||
@ -106,7 +103,7 @@ cetus_read_channel(int s, cetus_channel_t *ch, size_t size)
|
||||
g_debug("%s: recvmsg fd:%d, n:%d", G_STRLOC, s, (int) n);
|
||||
|
||||
if (n == -1) {
|
||||
err = errno;
|
||||
int err = errno;
|
||||
if (err == EAGAIN) {
|
||||
g_message("%s:recvmsg() EAGAIN, errno:%d", G_STRLOC, errno);
|
||||
return NETWORK_SOCKET_WAIT_FOR_EVENT;
|
||||
|
@ -389,8 +389,8 @@ gint
|
||||
check_hostname(network_backend_t *backend)
|
||||
{
|
||||
gint ret = 0;
|
||||
gchar *p = NULL;
|
||||
if (!backend) return ret;
|
||||
|
||||
gchar old_addr[INET_ADDRSTRLEN] = {""};
|
||||
inet_ntop(AF_INET, &(backend->addr->addr.ipv4.sin_addr), old_addr, sizeof(old_addr));
|
||||
if (0 != network_address_set_address(backend->addr, backend->address->str)) {
|
||||
|
@ -107,10 +107,7 @@ cetus_exec_new_binary(cetus_cycle_t *cycle, char **argv)
|
||||
void
|
||||
cetus_master_process_cycle(cetus_cycle_t *cycle)
|
||||
{
|
||||
u_char *p;
|
||||
int i, try_cnt;
|
||||
unsigned int n;
|
||||
struct itimerval itv;
|
||||
int try_cnt;
|
||||
unsigned int live;
|
||||
|
||||
cetus_start_worker_processes(cycle, cycle->worker_processes,
|
||||
@ -474,8 +471,6 @@ cetus_reap_children(cetus_cycle_t *cycle)
|
||||
static void
|
||||
cetus_master_process_exit(cetus_cycle_t *cycle)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
g_message("%s: exit", G_STRLOC);
|
||||
|
||||
exit(0);
|
||||
@ -596,8 +591,6 @@ cetus_worker_process_init(cetus_cycle_t *cycle, int worker)
|
||||
{
|
||||
sigset_t set;
|
||||
int n;
|
||||
unsigned int i;
|
||||
struct rlimit rlmt;
|
||||
|
||||
sigemptyset(&set);
|
||||
|
||||
@ -653,8 +646,6 @@ cetus_worker_process_init(cetus_cycle_t *cycle, int worker)
|
||||
static void
|
||||
cetus_worker_process_exit(cetus_cycle_t *cycle)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
cetus_monitor_stop_thread(cycle->priv->monitor);
|
||||
|
||||
g_message("%s: exit", G_STRLOC);
|
||||
@ -742,7 +733,7 @@ process_admin_sql(cetus_cycle_t *cycle, cetus_channel_t *ch)
|
||||
|
||||
func = plugin->con_exectute_sql;
|
||||
retval = (*func) (cycle, con);
|
||||
g_debug("%s: call admin", G_STRLOC);
|
||||
g_debug("%s: call admin:%d", G_STRLOC, retval);
|
||||
send_admin_resp(cycle, con);
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,6 @@ pid_t
|
||||
cetus_spawn_process(cetus_cycle_t *cycle, cetus_spawn_proc_pt proc, void *data,
|
||||
char *name, int respawn)
|
||||
{
|
||||
u_long on;
|
||||
pid_t pid;
|
||||
int s;
|
||||
|
||||
@ -313,13 +312,9 @@ cetus_init_signals()
|
||||
static void
|
||||
cetus_signal_handler(int signo, siginfo_t *siginfo, void *ucontext)
|
||||
{
|
||||
char *action;
|
||||
int ignore;
|
||||
int err;
|
||||
cetus_signal_t *sig;
|
||||
|
||||
ignore = 0;
|
||||
|
||||
err = errno;
|
||||
|
||||
for (sig = signals; sig->signo != 0; sig++) {
|
||||
@ -328,8 +323,6 @@ cetus_signal_handler(int signo, siginfo_t *siginfo, void *ucontext)
|
||||
}
|
||||
}
|
||||
|
||||
action = "";
|
||||
|
||||
switch (cetus_process) {
|
||||
|
||||
case CETUS_PROCESS_MASTER:
|
||||
@ -338,29 +331,23 @@ cetus_signal_handler(int signo, siginfo_t *siginfo, void *ucontext)
|
||||
|
||||
case cetus_signal_value(CETUS_SHUTDOWN_SIGNAL):
|
||||
cetus_quit = 1;
|
||||
action = ", shutting down";
|
||||
break;
|
||||
|
||||
case cetus_signal_value(CETUS_TERMINATE_SIGNAL):
|
||||
case SIGINT:
|
||||
cetus_terminate = 1;
|
||||
action = ", exiting";
|
||||
break;
|
||||
|
||||
case cetus_signal_value(CETUS_NOACCEPT_SIGNAL):
|
||||
cetus_noaccept = 1;
|
||||
action = ", stop accepting connections";
|
||||
break;
|
||||
|
||||
case cetus_signal_value(CETUS_CHANGEBIN_SIGNAL):
|
||||
if (getppid() == cetus_parent || cetus_new_binary > 0) {
|
||||
action = ", ignoring";
|
||||
ignore = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
cetus_change_binary = 1;
|
||||
action = ", changing binary";
|
||||
break;
|
||||
|
||||
case SIGALRM:
|
||||
@ -385,18 +372,15 @@ cetus_signal_handler(int signo, siginfo_t *siginfo, void *ucontext)
|
||||
break;
|
||||
case cetus_signal_value(CETUS_SHUTDOWN_SIGNAL):
|
||||
cetus_quit = 1;
|
||||
action = ", shutting down";
|
||||
break;
|
||||
|
||||
case cetus_signal_value(CETUS_TERMINATE_SIGNAL):
|
||||
case SIGINT:
|
||||
cetus_terminate = 1;
|
||||
action = ", exiting";
|
||||
break;
|
||||
|
||||
case cetus_signal_value(CETUS_CHANGEBIN_SIGNAL):
|
||||
case SIGIO:
|
||||
action = ", ignoring";
|
||||
break;
|
||||
}
|
||||
|
||||
@ -415,7 +399,6 @@ static void
|
||||
cetus_process_get_status(void)
|
||||
{
|
||||
int status;
|
||||
char *process;
|
||||
pid_t pid;
|
||||
int err;
|
||||
int i;
|
||||
@ -450,13 +433,10 @@ cetus_process_get_status(void)
|
||||
|
||||
|
||||
one = 1;
|
||||
process = "unknown process";
|
||||
|
||||
for (i = 0; i < cetus_last_process; i++) {
|
||||
if (cetus_processes[i].pid == pid) {
|
||||
cetus_processes[i].status = status;
|
||||
cetus_processes[i].exited = 1;
|
||||
process = cetus_processes[i].name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -467,22 +447,3 @@ cetus_process_get_status(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
cetus_os_signal_process(cetus_cycle_t *cycle, char *name, pid_t pid)
|
||||
{
|
||||
cetus_signal_t *sig;
|
||||
|
||||
for (sig = signals; sig->signo != 0; sig++) {
|
||||
if (strcmp(name, sig->name) == 0) {
|
||||
if (kill(pid, sig->signo) != -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_critical("%s: kill(%d, %d) failed", G_STRLOC, pid, sig->signo);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -29,42 +29,6 @@
|
||||
#include "glib-ext.h"
|
||||
#include "cetus-util.h"
|
||||
|
||||
void
|
||||
cetus_string_dequote(char *z)
|
||||
{
|
||||
int quote;
|
||||
int i, j;
|
||||
if (z == 0)
|
||||
return;
|
||||
quote = z[0];
|
||||
switch (quote) {
|
||||
case '\'':
|
||||
break;
|
||||
case '"':
|
||||
break;
|
||||
case '`':
|
||||
break; /* For MySQL compatibility */
|
||||
default:
|
||||
return;
|
||||
}
|
||||
for (i = 1, j = 0; z[i]; i++) {
|
||||
if (z[i] == quote) {
|
||||
if (z[i + 1] == quote) { /* quote escape */
|
||||
z[j++] = quote;
|
||||
i++;
|
||||
} else {
|
||||
z[j++] = 0;
|
||||
break;
|
||||
}
|
||||
} else if (z[i] == '\\') { /* slash escape */
|
||||
i++;
|
||||
z[j++] = z[i];
|
||||
} else {
|
||||
z[j++] = z[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
try_get_int_value(const gchar *option_value, gint *return_value)
|
||||
{
|
||||
|
@ -38,8 +38,6 @@ typedef int32_t BitArray;
|
||||
#define ClearBit(A,k) (A[(k/32)] &= ~(1 << (k%32)))
|
||||
#define TestBit(A,k) (A[(k/32)] & (1 << (k%32)))
|
||||
|
||||
void cetus_string_dequote(char *z);
|
||||
|
||||
#define KB 1024
|
||||
#define MB 1024 * KB
|
||||
#define GB 1024 * MB
|
||||
|
@ -273,20 +273,6 @@ chassis_is_shutdown()
|
||||
return signal_shutdown == 1 || cetus_terminate == 1;
|
||||
}
|
||||
|
||||
static void
|
||||
sighup_handler(int G_GNUC_UNUSED fd, short G_GNUC_UNUSED event_type, void *_data)
|
||||
{
|
||||
chassis *chas = _data;
|
||||
|
||||
/* this should go into the old logfile */
|
||||
g_message("received a SIGHUP, closing log file");
|
||||
|
||||
chassis_log_set_logrotate(chas->log);
|
||||
|
||||
/* ... and this into the new one */
|
||||
g_message("re-opened log file after SIGHUP");
|
||||
}
|
||||
|
||||
/**
|
||||
* forward libevent messages to the glib error log
|
||||
*/
|
||||
@ -313,7 +299,6 @@ int
|
||||
chassis_mainloop(void *_chas)
|
||||
{
|
||||
chassis *chas = _chas;
|
||||
guint i;
|
||||
|
||||
/* redirect logging from libevent to glib */
|
||||
event_set_log_callback(event_log_use_glib);
|
||||
|
@ -2449,29 +2449,6 @@ check_dist_tran_resultset(network_queue *recv_queue, network_mysqld_con *con)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
log_packet_error_info(network_socket *client, network_socket *server, char *orig_sql,
|
||||
GString *packet_str, uint64_t uniq_id)
|
||||
{
|
||||
network_mysqld_err_packet_t *err_packet;
|
||||
network_packet packet;
|
||||
|
||||
packet.data = packet_str;
|
||||
packet.offset = NET_HEADER_SIZE;
|
||||
|
||||
err_packet = network_mysqld_err_packet_new();
|
||||
|
||||
if (network_mysqld_proto_get_err_packet(&packet, err_packet)) {
|
||||
g_message("%s:dst:%s, sql:%s", G_STRLOC, server->dst->name->str, orig_sql);
|
||||
network_mysqld_err_packet_free(err_packet);
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_message("%s:dst:%s,sql:%s,errmsg:%s", G_STRLOC, server->dst->name->str, orig_sql, err_packet->errmsg->str);
|
||||
|
||||
network_mysqld_err_packet_free(err_packet);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
merge_for_modify(sql_context_t *context, network_queue *send_queue, GPtrArray *recv_queues,
|
||||
@ -2810,7 +2787,7 @@ merge_for_admin(network_queue *send_queue, GPtrArray *recv_queues,
|
||||
network_mysqld_con *con, cetus_result_t *res_merge, result_merge_t *merged_result)
|
||||
{
|
||||
int p;
|
||||
char *orig_sql = con->orig_sql->str;
|
||||
|
||||
for (p = 0; p < recv_queues->len; p++) {
|
||||
network_queue *recv_q = g_ptr_array_index(recv_queues, p);
|
||||
GString *pkt = g_queue_peek_head(recv_q->chunks);
|
||||
|
Loading…
Reference in New Issue
Block a user