diff --git a/Platform/user/ulog/log-sched/log_console.c b/Platform/user/ulog/log-sched/log_console.c index 17046c467..cbe01535a 100755 --- a/Platform/user/ulog/log-sched/log_console.c +++ b/Platform/user/ulog/log-sched/log_console.c @@ -17,6 +17,10 @@ #define SERIAL_NO_DRIVER_KEY SERIAL_DRIVER_PREFIX":unknown" #define SERIAL_PREFIX "ttyS" +#ifndef CM_LOG_CONF_CONSOLE_FILE +#define CM_LOG_CONF_CONSOLE_FILE "/etc/rsyslog.d/log-console.conf" +#endif + static int write_console_content(FILE *fp, const u8 level, const char *filter_mod, void *arg) { int ret = -1; @@ -126,3 +130,72 @@ void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer */ } + +ret_code console_initial() +{ + ret_code ret = RET_ERR; + FILE *fp = NULL; + char *pos = NULL; + char *pos2 = NULL; + char ttyfile_str[128] = ""; + int str_len = 0; + + fp = fopen(CM_LOG_CONF_CONSOLE_FILE, "r"); + if (NULL == fp) { + return ret; + } + + if (fseek(fp, 0, SEEK_SET) == -1) + { + ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno)); + + fclose(fp); + return ret; + } + + ssize_t n; + char *line = NULL; + while ((getline(&line, &n, fp)) != -1) + { + pos = strstr(line, "/"); + if (pos != NULL) + { + if ((pos2 = strstr(pos, " ")) != NULL) + { + str_len = strlen(pos) - strlen(pos2); + } + else + { + str_len = strlen(pos); + } + + memset(ttyfile_str, 0, sizeof(ttyfile_str)); + strncpy(ttyfile_str, pos, str_len); + + /* 滤除掉段尾的回车换行 */ + if ('\n' == ttyfile_str[strlen(ttyfile_str)-1]) + { + ttyfile_str[strlen(ttyfile_str)-1] = '\0'; + } + + + if(modify_authorizing(ttyfile_str) == RET_OK) + { + ULOG_DEBUG(g_log, "Modify authorizing %s successed.", ttyfile_str); + } + else + { + ULOG_DEBUG(g_log, "Modify authorizing %s failed.", ttyfile_str); + } + } + } + + ret = RET_OK; + if (NULL != fp) + { + fclose(fp); + } + return ret; + +} + diff --git a/Platform/user/ulog/log-sched/log_console.h b/Platform/user/ulog/log-sched/log_console.h index 9296cb79f..9c73ffd70 100755 --- a/Platform/user/ulog/log-sched/log_console.h +++ b/Platform/user/ulog/log-sched/log_console.h @@ -6,5 +6,7 @@ #include "rpc_common.h" void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data); +ret_code console_initial(); + #endif diff --git a/Platform/user/ulog/log-sched/log_sched.c b/Platform/user/ulog/log-sched/log_sched.c index 6c80c89e1..df4b06451 100755 --- a/Platform/user/ulog/log-sched/log_sched.c +++ b/Platform/user/ulog/log-sched/log_sched.c @@ -23,6 +23,17 @@ ulog_t *g_log = NULL; FILE *g_conf_fp; char g_conf_file[MAX_PATH_SZ]; +typedef ret_code (*initial_cb)(); +typedef struct _log_initial { + char type[20]; + initial_cb cb; +} log_initial_t; + +log_initial_t g_log_initial[] = { + {"console", console_initial} +}; + + void signal_exit() { log_sev_exit(); @@ -65,6 +76,11 @@ int main(int argc, char **argv) } } + /* 鍚勭被閰嶇疆鍒濆鍖 */ + for (int i = 0; i < (sizeof(g_log_initial) / sizeof(log_initial_t)); i++) { + g_log_initial[i].cb(); + } + rpc_server *server = rpc_server_create_ex(RPC_MODULE_SYSLOG_NAME); if (server == NULL) {