diff --git a/Common/log_types.h b/Common/log_types.h index bfc8c5675..e30c12778 100755 --- a/Common/log_types.h +++ b/Common/log_types.h @@ -3,6 +3,8 @@ #include "ulog_api.h" +#define LOG_HOST_SZ 256 + typedef enum { LOG_OFF = 0, LOG_ON @@ -24,7 +26,7 @@ typedef enum { typedef struct _log_remote_host { log_rfc_t rfc; - char host[256]; + char host[LOG_HOST_SZ]; u16 port; } log_remote_host_t; diff --git a/Platform/common/ulog/ulog_in.h b/Platform/common/ulog/ulog_in.h index b15b0ac95..f63dbf766 100755 --- a/Platform/common/ulog/ulog_in.h +++ b/Platform/common/ulog/ulog_in.h @@ -13,6 +13,8 @@ #define CONF_LOG_CONSOLE_FUNC "conf_log_console" #define CONF_LOG_PTY_FUNC "conf_log_pty" +#define CONF_LOG_REMOTE_ADD_HOST "conf_log_add_remote" +#define CONF_LOG_REMOTE_DEL_HOST "conf_log_del_remote" typedef struct _level_str { u32 level; diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index 9c45e65b4..e3547cff2 100755 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -172,8 +172,8 @@ LOG_CONFIG_REMOTE_ADD_HOST, \ CONFIG_FROM_WEB, \ FALSE, \ - log_remote_config_chk, \ - log_remote_add_config_proc, \ + log_remote_host_config_chk, \ + log_remote_add_host_config_proc, \ NULL, \ NULL \ },\ @@ -181,8 +181,8 @@ LOG_CONFIG_REMOTE_DEL_HOST, \ CONFIG_FROM_WEB, \ FALSE, \ - log_remote_config_chk, \ - log_remote_del_config_proc, \ + log_remote_host_config_chk, \ + log_remote_del_host_config_proc, \ NULL, \ NULL \ }\ diff --git a/Platform/user/configm/config-server/include/log_config.h b/Platform/user/configm/config-server/include/log_config.h index 56284d622..81830c995 100755 --- a/Platform/user/configm/config-server/include/log_config.h +++ b/Platform/user/configm/config-server/include/log_config.h @@ -19,13 +19,13 @@ ret_code log_monitor_config_chk(uint source, uint *config_type, ret_code log_monitor_config_proc(uint source, uint config_type, pointer input, int input_len, pointer output, int *output_len); -ret_code log_remote_config_chk(uint source, uint *config_type, +ret_code log_remote_host_config_chk(uint source, uint *config_type, pointer input, int *input_len, pointer output, int *output_len); -ret_code log_remote_add_config_proc(uint source, uint config_type, +ret_code log_remote_add_host_config_proc(uint source, uint config_type, pointer input, int input_len, pointer output, int *output_len); -ret_code log_remote_del_config_proc(uint source, uint config_type, +ret_code log_remote_del_host_config_proc(uint source, uint config_type, pointer input, int input_len, pointer output, int *output_len); diff --git a/Platform/user/configm/config-server/log_config/log_config_cm.c b/Platform/user/configm/config-server/log_config/log_config_cm.c index 05dcb9160..2b5154e62 100755 --- a/Platform/user/configm/config-server/log_config/log_config_cm.c +++ b/Platform/user/configm/config-server/log_config/log_config_cm.c @@ -4,7 +4,8 @@ ret_code log_rpc_exec(char* service_name, char* method_name, pointer input, int input_len, int last_lenth) { if ((input == NULL) - && input_len < last_lenth /*sizeof(log_console_t) */) { + && input_len < last_lenth /*sizeof(log_console_t) */) { + ULOG_ERR(g_log_h, "log rpc input actual length:%d, need length:%d", input_len, last_lenth); return RET_INPUTERR; } diff --git a/Platform/user/configm/config-server/log_config/log_config_cm.h b/Platform/user/configm/config-server/log_config/log_config_cm.h index 9cc341095..dbd1dfcb6 100755 --- a/Platform/user/configm/config-server/log_config/log_config_cm.h +++ b/Platform/user/configm/config-server/log_config/log_config_cm.h @@ -8,7 +8,13 @@ #include "rpc_types.h" #include "rpc_common.h" -#define TERMINAL_CHK(type, input, input_len, str_conf) { \ +#define TERMINAL_GEN_JSON(s, o) { \ + s2j_struct_get_basic_element(s, o, int, level); \ + s2j_struct_get_basic_element(s, o, int, on); \ + S2J_STRUCT_GET_STRING_ELEMENT_N(s, o, module, MAX_MODULE_NAME_SZ); \ +} + +#define COMMON_CHK(type, input, input_len, str_conf, cb) { \ ULOG_DEBUG(g_log_h, "Checking %s configuration:%s", str_conf, input); \ if (input == NULL) { \ ULOG_ERR(g_log_h, "input can't null"); \ @@ -23,21 +29,23 @@ \ ULOG_DEBUG(g_log_h, "json input: %s", cJSON_Print(json_obj)); \ \ - s2j_create_struct_obj(log_terminal, type /*log_console_t*/); \ - if(log_terminal == NULL) { \ + s2j_create_struct_obj(st, type /*log_console_t*/); \ + if(st == NULL) { \ cJSON_Delete(json_obj); \ ULOG_ERR(g_log_h, "Creating log %s of object is failure", str_conf); \ return RET_NOMEM; \ } \ \ - s2j_struct_get_basic_element(log_terminal, json_obj, int, level); \ - s2j_struct_get_basic_element(log_terminal, json_obj, int, on); \ - S2J_STRUCT_GET_STRING_ELEMENT_N(log_terminal, json_obj, module, MAX_MODULE_NAME_SZ); \ - \ - *input_len = sizeof(*log_terminal); \ - memcpy(input, log_terminal, *input_len); \ - \ - return RET_OK; \ + cb(st, json_obj); \ + \ + *input_len = sizeof(*st); \ + memcpy(input, st, *input_len); \ + \ + return RET_OK; \ +} + +#define TERMINAL_CHK(type, input, input_len, str_conf) { \ + COMMON_CHK(type, input, input_len, str_conf, TERMINAL_GEN_JSON) \ } extern rpc_client *g_log_client; diff --git a/Platform/user/configm/config-server/log_config/log_config_remote.c b/Platform/user/configm/config-server/log_config/log_config_remote.c index 948c938d6..da61bdefb 100755 --- a/Platform/user/configm/config-server/log_config/log_config_remote.c +++ b/Platform/user/configm/config-server/log_config/log_config_remote.c @@ -1,25 +1,32 @@ #include "log_config.h" #include "log_config_cm.h" -ret_code log_remote_config_chk(uint source, uint *config_type, +#define REMOTE_HOST_JSON(s, o) { \ + s2j_struct_get_basic_element(s, o, int, rfc); \ + s2j_struct_get_basic_element(s, o, int, port); \ + S2J_STRUCT_GET_STRING_ELEMENT_N(s, o, host, LOG_HOST_SZ); \ +} + + +ret_code log_remote_host_config_chk(uint source, uint *config_type, pointer input, int *input_len, pointer output, int *output_len) { - TERMINAL_CHK(log_console_t, input, input_len, "pty"); + COMMON_CHK(log_remote_host_t, input, input_len, "remote host", REMOTE_HOST_JSON); } -ret_code log_remote_add_config_proc(uint source, uint config_type, +ret_code log_remote_add_host_config_proc(uint source, uint config_type, pointer input, int input_len, pointer output, int *output_len) { - return log_rpc_exec(SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, input, input_len, sizeof(log_console_t)); + return log_rpc_exec(SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_ADD_HOST, input, input_len, sizeof(log_remote_host_t)); } -ret_code log_remote_del_config_proc(uint source, uint config_type, +ret_code log_remote_del_host_config_proc(uint source, uint config_type, pointer input, int input_len, pointer output, int *output_len) { - return log_rpc_exec(SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, input, input_len, sizeof(log_console_t)); + return log_rpc_exec(SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_DEL_HOST, input, input_len, sizeof(log_remote_host_t)); } diff --git a/Platform/user/logging/cmd_remote.c b/Platform/user/logging/cmd_remote.c index 22a8b2e82..dfb037559 100755 --- a/Platform/user/logging/cmd_remote.c +++ b/Platform/user/logging/cmd_remote.c @@ -32,10 +32,10 @@ static int conf_remote_by_config_id(cJSON *json_obj, const char *host, const u16 int ret = set_log_conf(json_obj, config_id); if (ret != 0) { - ULOG_ERR(g_log, "Host of log which is configured is failure"); - } - ULOG_DEBUG(g_log, "Host of log whice is configured is success"); - + ULOG_ERR(g_log, "Host of log which is configured is failure"); + } else { + ULOG_DEBUG(g_log, "Host of log whice is configured is success"); + } return ret; } diff --git a/Platform/user/logging/logging_common.h b/Platform/user/logging/logging_common.h index 33bfd1f82..984542244 100755 --- a/Platform/user/logging/logging_common.h +++ b/Platform/user/logging/logging_common.h @@ -37,8 +37,9 @@ int set_log_conf(cJSON *json_obj, uint64 config_id); int ret = set_log_conf(json_obj, conf_id); \ if (ret != 0) { \ ULOG_ERR(g_log, "Setting terminal configure of log is failure"); \ + } else { \ + ULOG_DEBUG(g_log, "Setting terminal configure of log is success"); \ } \ - ULOG_DEBUG(g_log, "Setting terminal configure of log is success"); \ return ret; \ } diff --git a/Platform/user/rpc/rpc_conn.c b/Platform/user/rpc/rpc_conn.c index 6e9199b15..03b116c0e 100755 --- a/Platform/user/rpc/rpc_conn.c +++ b/Platform/user/rpc/rpc_conn.c @@ -267,7 +267,7 @@ static void cb_rsp_read(struct ev_loop *l, struct ev_io *watcher, int revents) { //TODO why null //sessionpool has req = (rpc_request*) rpc_sessionpool_get(th->req_pool, rsp->seq); - if (req->seq != rsp->seq) { + if ((req == NULL) || (req->seq != rsp->seq)) { fprintf(stderr, "seq not equal!\n"); return; } @@ -421,7 +421,7 @@ void rpc_return_null(rpc_conn *conn) { void rpc_return_error(rpc_conn *conn, ret_code err_code, char* err_message) { int len = strlen(err_message); - err_message[len]='\0'; + //err_message[len]='\0'; len++; rpc_send_response(conn, err_code, err_message, len); } diff --git a/Platform/user/ulog/log-sched/log_console.c b/Platform/user/ulog/log-sched/log_console.c index 5f542322b..8caad9e2a 100755 --- a/Platform/user/ulog/log-sched/log_console.c +++ b/Platform/user/ulog/log-sched/log_console.c @@ -90,6 +90,7 @@ void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer if (config_log_console((const log_console_t *)input) != 0) { ULOG_ERR(g_log, "Configuring console of log is faiure"); rpc_return_error(conn, RET_ERR, "Configuring console of log is faiure"); + return; } rpc_return_null(conn); } diff --git a/Platform/user/ulog/log-sched/log_pty.c b/Platform/user/ulog/log-sched/log_pty.c index fc003f5b7..18d94b93b 100755 --- a/Platform/user/ulog/log-sched/log_pty.c +++ b/Platform/user/ulog/log-sched/log_pty.c @@ -89,6 +89,7 @@ void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data if (config_log_pty((const log_pty_t *)input) != 0) { ULOG_ERR(g_log, "Configuring pty of log is faiure"); rpc_return_error(conn, RET_ERR, "Configuring pty of log is faiure"); + return; } rpc_return_null(conn); } diff --git a/Platform/user/ulog/log-sched/log_pty.h b/Platform/user/ulog/log-sched/log_pty.h index 8e9d6bfca..4b5b3b41f 100755 --- a/Platform/user/ulog/log-sched/log_pty.h +++ b/Platform/user/ulog/log-sched/log_pty.h @@ -2,6 +2,7 @@ #define _LOG_PTY_H #include "log_console.h" +#include "rpc.h" void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data); diff --git a/Platform/user/ulog/log-sched/log_remote.c b/Platform/user/ulog/log-sched/log_remote.c index 62ca7eede..4a42e8e33 100755 --- a/Platform/user/ulog/log-sched/log_remote.c +++ b/Platform/user/ulog/log-sched/log_remote.c @@ -85,7 +85,7 @@ static int remote_conf_content(FILE *fp, const u8 level, const char *filter_mod, while ((n = getline(&line, &n, bak_fp)) != -1) { int match = match_cb(line, arg); if (match == -1) { - ULOG_ERR(g_log, "Configure which is matched is failure"); + ULOG_ERR(g_log, "Configuration which is matched is failure"); } else if (match == 0) { ULOG_DEBUG(g_log, "Be matched"); continue; @@ -203,7 +203,7 @@ static int get_log_level() } ssize_t n, n1, n2; - char *line; + char *line = NULL; u8 value; while ((n1 = getline(&line, &n, g_conf_fp)) != -1) { n2 = sscanf(line, LOG_CONF_KEY_REMOTE_LEVEL"%u", &value); @@ -253,7 +253,7 @@ static int add_remote_host(const log_remote_host_t *conf) static int del_remote_host(const log_remote_host_t *conf) { - int ret; + int ret = -1; char prefix[1] = ""; ULOG_INFO(g_log, "Deleting remote log server[%s:%u], rfc is %s", conf->host, conf->port, rfc_tbl[conf->rfc].fmt); @@ -264,13 +264,19 @@ static int del_remote_host(const log_remote_host_t *conf) if (snprintf(redirect, sizeof(redirect), "%s@%s:%u:%s", prefix, conf->host, conf->port, rfc_tbl[conf->rfc].fmt) < 0) { ULOG_ERR(g_log, "Setting remote redirect[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt); - return -1; + return ret; } - if (log_conf(7, LOG_CONF_PATH, LOG_CONF_REMOTE_FILE_NAME, NULL, - del_remote_conf_content, (void *)redirect) != 0) { + int level = get_log_level(); + if (level == -1) { + ULOG_ERR(g_log, "Getting log level is failure"); + return ret; + } + ret = log_conf(level, LOG_CONF_PATH, LOG_CONF_REMOTE_FILE_NAME, NULL, + del_remote_conf_content, (void *)redirect); + if (ret != 0) { ULOG_ERR(g_log, "Adding remote server[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt); - return -1; + return ret; } return ret; @@ -335,7 +341,12 @@ static void rpc_conf_log_remote(const log_op_t op, rpc_conn *conn, point return; } - config_log_remote_host(op, (const log_remote_host_t *)input); + if (config_log_remote_host(op, (const log_remote_host_t *)input) != 0) { + ULOG_ERR(g_log, "Configuring remote of log is faiure"); + rpc_return_error(conn, RET_ERR, "Configuring remote of log is faiure"); + return; + } + rpc_return_null(conn); } void rpc_conf_log_add_remote(rpc_conn *conn, pointer input, int input_len, pointer data) diff --git a/Platform/user/ulog/log-sched/log_sched.c b/Platform/user/ulog/log-sched/log_sched.c index 3aec6a656..d7a5660c6 100755 --- a/Platform/user/ulog/log-sched/log_sched.c +++ b/Platform/user/ulog/log-sched/log_sched.c @@ -87,8 +87,8 @@ int main(int argc, char **argv) rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, "conf_log_file", rpc_conf_log_file); rpc_server_regservice(server, SERIVCE_LOG_CONSOLE_NAME, CONF_LOG_CONSOLE_FUNC, rpc_conf_log_console); rpc_server_regservice(server, SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, rpc_conf_log_pty); - rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_add_remote", rpc_conf_log_add_remote); - rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_del_remote", rpc_conf_log_del_remote); + rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_ADD_HOST, rpc_conf_log_add_remote); + rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_DEL_HOST, rpc_conf_log_del_remote); rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_remote_level", rpc_conf_log_remote_level); /*