Mod aaa-12 log pty add pthread lock

RCA:
SOL:
修改人:zhangtao
检视人:
This commit is contained in:
zhangtaohz 2019-08-30 17:34:00 +08:00
parent b143e20424
commit 3d7c220514
1 changed files with 72 additions and 41 deletions

View File

@ -20,20 +20,62 @@
#define LOG_CONF_KEY_PTY_LEVEL_STR "pty.level"
#define LOG_CONF_KEY_PTY_MODULE_STR "pty.module"
pthread_mutex_t g_mutex_pty;
int g_epoll_fd = -1;
volatile int g_epoll_fd = -1;
int g_watch_fd = -1;
int g_inotify_fd = -1;
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 ret_code write_pty_conf()
{
char value_str[128]="";
uint level = LOG_INFO;
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;
}
pthread_mutex_lock(&g_mutex_pty);
int ret_conf = log_conf((u8)level, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, module,
write_pty_content, NULL);
pthread_mutex_unlock(&g_mutex_pty);
if (ret_conf != 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;
}
static void *pty_monitor_thread(void *arg)
{
struct epoll_event events[MAX_EVENT_NUMBER];
int ret;
ret_code ret_c;
char buf[MAX_LINE_SZ];
ssize_t len;
char *ptr;
@ -82,8 +124,11 @@ static void *pty_monitor_thread(void *arg)
sleep(1);
ULOG_DEBUG(g_log, "Current ev mask:%u, wo will write configure and restart rsyslog", inotify_ev->mask);
log_conf(LOG_INFO, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, NULL,
write_pty_content, NULL);
ret_c = write_pty_conf();
if (ret_c != RET_OK) {
ULOG_ERR(g_log, "Pty monitor write pty configure is failure(code:%d)", ret_c);
continue;
}
if (log_sev_restart() != 0) {
ULOG_ERR(g_log, "Pty monitor restart rsyslog 2 is failure");
@ -233,10 +278,12 @@ static int config_log_pty(const log_pty_t *conf)
break;
case LOG_ON:
if (log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, conf->module,
write_pty_content, NULL) != 0) {
pthread_mutex_lock(&g_mutex_pty);
ret = log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, conf->module,
write_pty_content, NULL);
pthread_mutex_unlock(&g_mutex_pty);
if (ret != 0) {
ULOG_ERR(g_log, "Log's pty configure which is written is failure");
ret = -1;
} else {
ret = 0;
}
@ -283,38 +330,16 @@ void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data
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);
int thread_ret = pthread_mutex_init(&g_mutex_pty, NULL);
if (thread_ret != 0) {
ULOG_DEBUG(g_log, "Initiating pthread lock is failure(cdoe:%d)", thread_ret);
}
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");
}
ret_code ret = write_pty_conf();
if (ret != RET_OK) {
ULOG_DEBUG(g_log, "Initiating pty is failure(cdoe:%d)", ret);
} else {
ULOG_INFO(g_log, "Initiating pty is success");
}
return ret;
@ -322,7 +347,13 @@ ret_code pty_initial()
ret_code pty_exit()
{
ret_code ret = RET_OK;
int thread_ret = pthread_mutex_destroy(&g_mutex_pty);
if (0 != thread_ret) {
ret = RET_ERR;
ULOG_DEBUG(g_log, "Destroying pthread lock is failure(cdoe:%d)", thread_ret);
}
stop_dev_pty_monitor();
return RET_OK;
return ret;
}