Add aaa-12 (1)增加log-pty的初始化工作--解析配置文件并加载配置; (2)增加log-pty的exit前收尾工作; (3)log-pty配置时写配置文件; (4)log-sched启动时在加载配置后重启rsyslog
RCA: SOL: 修改人:liangxia 检视人:
This commit is contained in:
parent
c5d5a411ca
commit
30ec3fac77
|
@ -383,9 +383,13 @@ int write_log_file_conf(const char *p_key_str, const char *p_value_str)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_log_file_conf(const char *key_str, char *value_str, int value_len)
|
ret_code get_log_file_conf(const char *key_str, char *value_str, int value_len)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
ret_code ret = RET_OK;
|
||||||
|
char *pos = NULL;
|
||||||
|
char *pos2 = NULL;
|
||||||
|
size_t str_len = 0;
|
||||||
|
|
||||||
if (fseek(g_conf_fp, 0, SEEK_SET) == -1) {
|
if (fseek(g_conf_fp, 0, SEEK_SET) == -1) {
|
||||||
ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno));
|
ULOG_ERR(g_log, "Seeknig config to begin is faiure:%s", strerror(errno));
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -394,22 +398,52 @@ int get_log_file_conf(const char *key_str, char *value_str, int value_len)
|
||||||
ssize_t n, n1, n2;
|
ssize_t n, n1, n2;
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
char tmp_key[MAX_LINE_SZ], tmp_value[MAX_LINE_SZ];
|
char tmp_key[MAX_LINE_SZ], tmp_value[MAX_LINE_SZ];
|
||||||
while ((n1 = getline(&line, &n, g_conf_fp)) != -1) {
|
|
||||||
ULOG_DEBUG(g_log, "config file line:%s", line);
|
while ((getline(&line, &n, g_conf_fp)) != -1)
|
||||||
n2 = sscanf(line, "%s=%s", tmp_key, tmp_value);
|
{
|
||||||
if (n2 == 1) {
|
if (strstr(line, key_str) == NULL )
|
||||||
if (strcmp(tmp_key, key_str) == 0) {
|
{
|
||||||
strncpy(value_str, tmp_value, value_len);
|
continue;
|
||||||
ret = 0;
|
}
|
||||||
break;
|
|
||||||
}
|
pos = strstr(line, "=");
|
||||||
} else if (n2 == EOF) {
|
if (pos != NULL)
|
||||||
ULOG_ERR(g_log, "Parsing level from configure is failure:%s", strerror(errno));
|
{
|
||||||
break;
|
if (strlen(pos) <= 1)
|
||||||
} else {
|
{
|
||||||
ULOG_DEBUG(g_log, "Unknown row:%s", line);
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
pos ++;
|
||||||
|
if ((pos2 = strstr(pos, " ")) != NULL)
|
||||||
|
{
|
||||||
|
str_len = strlen(pos) - strlen(pos2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str_len = strlen(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str_len >= value_len)
|
||||||
|
{
|
||||||
|
ULOG_ERR(g_log, "Get log-sched config %s, but invaild value", key_str);
|
||||||
|
ret = RET_ERR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(value_str, 0, value_len);
|
||||||
|
strncpy(value_str, pos, str_len);
|
||||||
|
|
||||||
|
/* 滤除掉段尾的回车换行 */
|
||||||
|
if ('\n' == value_str[strlen(value_str)-1])
|
||||||
|
{
|
||||||
|
value_str[strlen(value_str)-1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
ULOG_DEBUG(g_log, "Get log-sched config %s:%s", key_str, value_str);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ int log_level_to_str(const u8 level, char *str, u32 len);
|
||||||
int log_off_with_file(const char *path, const char *file_name);
|
int log_off_with_file(const char *path, const char *file_name);
|
||||||
void rpc_conf_proc(rpc_conn *conn, pointer input, int input_len, int need_len, rpc_cb cb, void *arg);
|
void rpc_conf_proc(rpc_conn *conn, pointer input, int input_len, int need_len, rpc_cb cb, void *arg);
|
||||||
int write_log_file_conf(const char *p_key_str, const char *p_value_str);
|
int write_log_file_conf(const char *p_key_str, const char *p_value_str);
|
||||||
int get_log_file_conf(const char *key_str, char *value_str, int value_len);
|
ret_code get_log_file_conf(const char *key_str, char *value_str, int value_len);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -138,7 +138,7 @@ ret_code console_initial()
|
||||||
char *pos = NULL;
|
char *pos = NULL;
|
||||||
char *pos2 = NULL;
|
char *pos2 = NULL;
|
||||||
char ttyfile_str[128] = "";
|
char ttyfile_str[128] = "";
|
||||||
int str_len = 0;
|
size_t str_len = 0;
|
||||||
|
|
||||||
fp = fopen(CM_LOG_CONF_CONSOLE_FILE, "r");
|
fp = fopen(CM_LOG_CONF_CONSOLE_FILE, "r");
|
||||||
if (NULL == fp) {
|
if (NULL == fp) {
|
||||||
|
@ -178,7 +178,6 @@ ret_code console_initial()
|
||||||
ttyfile_str[strlen(ttyfile_str)-1] = '\0';
|
ttyfile_str[strlen(ttyfile_str)-1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(modify_authorizing(ttyfile_str) == RET_OK)
|
if(modify_authorizing(ttyfile_str) == RET_OK)
|
||||||
{
|
{
|
||||||
ULOG_DEBUG(g_log, "Modify authorizing %s successed.", ttyfile_str);
|
ULOG_DEBUG(g_log, "Modify authorizing %s successed.", ttyfile_str);
|
||||||
|
|
|
@ -15,12 +15,17 @@
|
||||||
#define MAX_EVENT_NUMBER 64
|
#define MAX_EVENT_NUMBER 64
|
||||||
#define LOG_DEV_PTY_DIR LOG_DEV_DIR"pts/"
|
#define LOG_DEV_PTY_DIR LOG_DEV_DIR"pts/"
|
||||||
#define LOG_CONF_PTY_FILE_NAME "log-pty.conf"
|
#define LOG_CONF_PTY_FILE_NAME "log-pty.conf"
|
||||||
|
#define LOG_CONF_KEY_PTY_LEVEL_STR "pty.level"
|
||||||
|
#define LOG_CONF_KEY_PTY_MODULE_STR "pty.module"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int g_epoll_fd = -1;
|
int g_epoll_fd = -1;
|
||||||
int g_watch_fd = -1;
|
int g_watch_fd = -1;
|
||||||
int g_inotify_fd = -1;
|
int g_inotify_fd = -1;
|
||||||
pthread_t g_monitor_thread;
|
pthread_t g_monitor_thread;
|
||||||
|
|
||||||
|
int access(const char *pathname, int mode);
|
||||||
static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, void *arg);
|
static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, void *arg);
|
||||||
|
|
||||||
static void *pty_monitor_thread(void *arg)
|
static void *pty_monitor_thread(void *arg)
|
||||||
|
@ -206,13 +211,25 @@ static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, v
|
||||||
static int config_log_pty(const log_pty_t *conf)
|
static int config_log_pty(const log_pty_t *conf)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
char value_str[128]="";
|
||||||
|
|
||||||
switch (conf->on)
|
switch (conf->on)
|
||||||
{
|
{
|
||||||
case LOG_OFF:
|
case LOG_OFF:
|
||||||
stop_dev_pty_monitor();
|
stop_dev_pty_monitor();
|
||||||
ret = log_off_with_file(LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME);
|
ret = log_off_with_file(LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME);
|
||||||
|
|
||||||
|
/* off时,将log-sched配置文件中pty日志级别调成默认值info,即level=6 */
|
||||||
|
if (0 == ret) {
|
||||||
|
memset(value_str, 0, sizeof(value_str));
|
||||||
|
sprintf(value_str, "%u", 6);
|
||||||
|
if (write_log_file_conf(LOG_CONF_KEY_PTY_LEVEL_STR, value_str) != 0) {
|
||||||
|
ULOG_ERR(g_log, "Pty-level which is written is failure");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LOG_ON:
|
case LOG_ON:
|
||||||
if (log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, conf->module,
|
if (log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, conf->module,
|
||||||
write_pty_content, NULL) != 0) {
|
write_pty_content, NULL) != 0) {
|
||||||
|
@ -221,6 +238,24 @@ static int config_log_pty(const log_pty_t *conf)
|
||||||
} else {
|
} else {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 写pty日志级别与模块名称到log-sched配置文件 */
|
||||||
|
if (0 == ret) {
|
||||||
|
memset(value_str, 0, sizeof(value_str));
|
||||||
|
sprintf(value_str, "%u", conf->level);
|
||||||
|
if (write_log_file_conf(LOG_CONF_KEY_PTY_LEVEL_STR, value_str) != 0) {
|
||||||
|
ULOG_ERR(g_log, "Pty-level which is written is failure");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(value_str, 0, sizeof(value_str));
|
||||||
|
sprintf(value_str, "%s", conf->module);
|
||||||
|
if (write_log_file_conf(LOG_CONF_KEY_PTY_MODULE_STR, value_str) != 0) {
|
||||||
|
ULOG_ERR(g_log, "Pty-module which is written is failure");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ULOG_WARNING(g_log, "Unknown on value:%u", conf->on);
|
ULOG_WARNING(g_log, "Unknown on value:%u", conf->on);
|
||||||
|
@ -244,3 +279,48 @@ void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data
|
||||||
rpc_conf_proc(conn, input, input_len, sizeof(log_pty_t), __rpc_conf_log_pty, NULL);
|
rpc_conf_proc(conn, input, input_len, sizeof(log_pty_t), __rpc_conf_log_pty, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret_code pty_initial()
|
||||||
|
{
|
||||||
|
char value_str[128]="";
|
||||||
|
uint level = 6;
|
||||||
|
char *module = NULL;
|
||||||
|
ret_code ret = RET_OK;
|
||||||
|
|
||||||
|
memset(value_str, 0, sizeof(value_str));
|
||||||
|
sprintf(value_str, "%s%s", LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME);
|
||||||
|
if (access(value_str, 0) == 0)
|
||||||
|
{
|
||||||
|
/* 获取配置 */
|
||||||
|
memset(value_str, 0, sizeof(value_str));
|
||||||
|
if (get_log_file_conf(LOG_CONF_KEY_PTY_LEVEL_STR, value_str, sizeof(value_str)) == 0)
|
||||||
|
{
|
||||||
|
level = atoi(value_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(value_str, 0, sizeof(value_str));
|
||||||
|
if (get_log_file_conf(LOG_CONF_KEY_PTY_MODULE_STR, value_str, sizeof(value_str)) == 0)
|
||||||
|
{
|
||||||
|
module = value_str;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log_conf((u8)level, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, module,
|
||||||
|
write_pty_content, NULL) != 0)
|
||||||
|
{
|
||||||
|
ULOG_ERR(g_log, "Log's pty configure which is written is failure");
|
||||||
|
ret = RET_ERR;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ULOG_DEBUG(g_log, "Pty config level(%u) and module(%s) successed.", level, module!=NULL?module:"NULL");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret_code pty_exit()
|
||||||
|
{
|
||||||
|
stop_dev_pty_monitor();
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,7 @@
|
||||||
#include "rpc.h"
|
#include "rpc.h"
|
||||||
|
|
||||||
void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data);
|
void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data);
|
||||||
|
ret_code pty_initial();
|
||||||
|
ret_code pty_exit();
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -24,13 +24,16 @@ FILE *g_conf_fp;
|
||||||
char g_conf_file[MAX_PATH_SZ];
|
char g_conf_file[MAX_PATH_SZ];
|
||||||
|
|
||||||
typedef ret_code (*initial_cb)();
|
typedef ret_code (*initial_cb)();
|
||||||
typedef struct _log_initial {
|
typedef ret_code (*exit_cb)();
|
||||||
|
typedef struct _log_opt {
|
||||||
char type[20];
|
char type[20];
|
||||||
initial_cb cb;
|
initial_cb init_func;
|
||||||
} log_initial_t;
|
exit_cb exit_func;
|
||||||
|
} log_opt_t;
|
||||||
|
|
||||||
log_initial_t g_log_initial[] = {
|
log_opt_t g_log_opt[] = {
|
||||||
{"console", console_initial}
|
{"console", console_initial, NULL},
|
||||||
|
{"monitor", pty_initial, pty_exit}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,10 +80,15 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 各类配置初始化 */
|
/* 各类配置初始化 */
|
||||||
for (int i = 0; i < (sizeof(g_log_initial) / sizeof(log_initial_t)); i++) {
|
for (int i = 0; i < (sizeof(g_log_opt) / sizeof(log_opt_t)); i++) {
|
||||||
g_log_initial[i].cb();
|
if ( NULL != g_log_opt[i].init_func) {
|
||||||
|
g_log_opt[i].init_func();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 重启syslog */
|
||||||
|
sev_restart();
|
||||||
|
|
||||||
rpc_server *server = rpc_server_create_ex(RPC_MODULE_SYSLOG_NAME);
|
rpc_server *server = rpc_server_create_ex(RPC_MODULE_SYSLOG_NAME);
|
||||||
if (server == NULL)
|
if (server == NULL)
|
||||||
{
|
{
|
||||||
|
@ -140,6 +148,14 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
ULOG_INFO(g_log, "%s is shutdown", LOG_SCHED_MODULE_NAME);
|
ULOG_INFO(g_log, "%s is shutdown", LOG_SCHED_MODULE_NAME);
|
||||||
END:
|
END:
|
||||||
|
|
||||||
|
/* 各类配置退出前的收尾 */
|
||||||
|
for (int i = 0; i < (sizeof(g_log_opt) / sizeof(log_opt_t)); i++) {
|
||||||
|
if ( NULL != g_log_opt[i].exit_func) {
|
||||||
|
g_log_opt[i].exit_func();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (g_conf_fp != NULL) {
|
if (g_conf_fp != NULL) {
|
||||||
fclose(g_conf_fp);
|
fclose(g_conf_fp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ static sem_t g_sem;
|
||||||
static volatile int g_is_exit = 0;
|
static volatile int g_is_exit = 0;
|
||||||
static volatile sev_state_t g_sev_state = SEV_STATE_WAIT;
|
static volatile sev_state_t g_sev_state = SEV_STATE_WAIT;
|
||||||
|
|
||||||
static void sev_restart()
|
void sev_restart()
|
||||||
{
|
{
|
||||||
ULOG_DEBUG(g_log, "Log service is restarting");
|
ULOG_DEBUG(g_log, "Log service is restarting");
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
int log_sev_init();
|
int log_sev_init();
|
||||||
int log_sev_exit();
|
int log_sev_exit();
|
||||||
int log_sev_restart();
|
int log_sev_restart();
|
||||||
|
void sev_restart();
|
||||||
void sev_loop();
|
void sev_loop();
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue