diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/MESA_handle_logger.c | 6 | ||||
| -rw-r--r-- | src/MESA_shm_ring_queue.c | 75 |
2 files changed, 68 insertions, 13 deletions
diff --git a/src/MESA_handle_logger.c b/src/MESA_handle_logger.c index f472a38..b0f910b 100644 --- a/src/MESA_handle_logger.c +++ b/src/MESA_handle_logger.c @@ -332,15 +332,15 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const log_handle_t *p_handle = (log_handle_t *)handle; int n = 0; int payload_len = 0; - struct MESA_log_buf lbuf; - if(p_handle == NULL || p_handle->runtime_log_file == NULL){ + struct MESA_shm_log_buf lbuf; + if(p_handle == NULL || p_handle->runtime_log_file == NULL || module == NULL){ return; } if(p_handle->zc == NULL){ return; } struct MESA_pthread_private *pri = (struct MESA_pthread_private *)pthread_getspecific(MESA_pthread_key); - int match_result = MESA_shm_match_consumer_rule(level, p_handle->pid); + int match_result = MESA_shm_match_consumer_rule(level, p_handle->pid, module); if(match_result != MESA_MATCH_CONSUMER_RULE_SUCCESS){ if(pri != NULL && match_result == MESA_MATCH_CONSUMER_RULE_FAIL_PID){ /*the process pid will not be consumed, we need to free the memory and recycle the ring queue*/ diff --git a/src/MESA_shm_ring_queue.c b/src/MESA_shm_ring_queue.c index 13cb23e..94f10ca 100644 --- a/src/MESA_shm_ring_queue.c +++ b/src/MESA_shm_ring_queue.c @@ -15,7 +15,7 @@ struct MESA_shm_overview *MESA_shm_ovw = NULL; struct MESA_shm_queue_head *MESA_ring_queue_head[MESA_SHM_RING_QUEUE_NUM] = {NULL}; int MESA_shm_ovw_id = -1; -struct MESA_consumer *MESA_consumer_status = NULL; +struct MESA_shm_consumer *MESA_consumer_status = NULL; void MESA_shm_init_ring_queue_mutex(struct MESA_shm_overview *ovw) @@ -82,9 +82,9 @@ void MESA_shm_register_sginal_handler() signal(SIGQUIT, MESA_shm_check_unlink); return ; } -int MESA_shm_alloc_overview(struct MESA_shm_overview **ovw, int *ovw_id, struct MESA_consumer **consumer_status) +int MESA_shm_alloc_overview(struct MESA_shm_overview **ovw, int *ovw_id, struct MESA_shm_consumer **consumer_status) { - int shmsize = (sizeof(struct MESA_shm_overview) * MESA_SHM_RING_QUEUE_NUM) + sizeof(struct MESA_consumer); + int shmsize = (sizeof(struct MESA_shm_overview) * MESA_SHM_RING_QUEUE_NUM) + sizeof(struct MESA_shm_consumer); struct MESA_shm_overview *shm_overview = NULL; struct MESA_shm_overview *tmp_ovw = NULL; int i = 0; @@ -108,7 +108,7 @@ int MESA_shm_alloc_overview(struct MESA_shm_overview **ovw, int *ovw_id, struct } *ovw = shm_overview; *ovw_id = shmid; - *consumer_status = (struct MESA_consumer *)(shm_overview + MESA_SHM_RING_QUEUE_NUM); + *consumer_status = (struct MESA_shm_consumer *)(shm_overview + MESA_SHM_RING_QUEUE_NUM); } }else{ @@ -118,7 +118,7 @@ int MESA_shm_alloc_overview(struct MESA_shm_overview **ovw, int *ovw_id, struct } *ovw = shm_overview; *ovw_id = shmid; - *consumer_status = (struct MESA_consumer *)(shm_overview + MESA_SHM_RING_QUEUE_NUM); + *consumer_status = (struct MESA_shm_consumer *)(shm_overview + MESA_SHM_RING_QUEUE_NUM); } return 0; } @@ -274,7 +274,7 @@ void MESA_shm_ring_queue_push_write_pos(struct MESA_shm_queue_head *head) /* (int)log_file_len + (str)log_file + '\0' + (int)level + (int)module_len + (str)module + '\0' + (int)payload_len + (str)payload + '\0' */ -int MESA_shm_copy_buf_to_ring_queue(struct MESA_shm_queue_head *head, struct MESA_log_buf *lbuf) +int MESA_shm_copy_buf_to_ring_queue(struct MESA_shm_queue_head *head, struct MESA_shm_log_buf *lbuf) { int available_len = 0, payload_len = 0; int *pi = NULL;; @@ -375,7 +375,7 @@ int MESA_shm_match_pid(int *p_pid, int cur_pid) if(p_pid[0] == 0){ return MESA_MATCH_CONSUMER_RULE_SUCCESS; } - for(i = 0; i < MESA_CONSUMER_CARE_PID_NUM; i++){ + for(i = 0; i < MESA_SHM_PID_NUM; i++){ if(p_pid[i] == 0){ break ; } @@ -385,7 +385,58 @@ int MESA_shm_match_pid(int *p_pid, int cur_pid) } return MESA_MATCH_CONSUMER_RULE_FAIL; } -int MESA_shm_match_consumer_rule(int level, int pid) +int MESA_shm_string_match_success(char *src, int src_len, char *pattern, int pattern_len) { + int i = 0; + int j = 0; + int start_pos = -1; + int match = -1; + while(i < src_len){ + if(j < pattern_len && src[i] == pattern[j]){ + i++; + j++; + } + else if(j < pattern_len && pattern[j] == '*'){ + start_pos = j; + match = i; + j = start_pos + 1; + } + else if(start_pos != -1){ + match++; + i = match; + j = start_pos + 1; + } + else{ + return 0; + } + } + while(j < pattern_len && pattern[j] == '*'){ + j++ ; + }; + return (j==pattern_len); +} + +int MESA_shm_match_module(const char *module) +{ + int i; + int shn_module_len; + char *shm_module; + int enable = *((int *)MESA_consumer_status->module[0]); + if(enable == 0){ + return MESA_MATCH_CONSUMER_RULE_SUCCESS; + } + for(i = 0; i < MESA_SHM_MODULE_NUM; i++){ + shn_module_len = *((int *)MESA_consumer_status->module[i]); + if(shn_module_len == 0){ + break ; + } + shm_module = MESA_consumer_status->module[i] + sizeof(int); + if(MESA_shm_string_match_success((char *)module, (int)strlen(module), shm_module, shn_module_len)){ + return MESA_MATCH_CONSUMER_RULE_SUCCESS; + } + } + return MESA_MATCH_CONSUMER_RULE_FAIL; +} +int MESA_shm_match_consumer_rule(int level, int pid, const char *module) { static __thread unsigned long long reload_age = 0; static __thread int last_pid_match_result = MESA_MATCH_CONSUMER_RULE_SUCCESS; @@ -399,12 +450,12 @@ int MESA_shm_match_consumer_rule(int level, int pid) return MESA_MATCH_CONSUMER_RULE_FAIL_LEVEL; } /* - only need to match pid once after the consumer restart, + only need to match pid once after consumer or producer restart, in order to improve matching speed for producer process */ if(MESA_consumer_status->reload_age != reload_age){ reload_age = MESA_consumer_status->reload_age; - if(MESA_shm_match_pid(MESA_consumer_status->care_pid, pid) == MESA_MATCH_CONSUMER_RULE_FAIL){ + if(MESA_shm_match_pid(MESA_consumer_status->pid, pid) == MESA_MATCH_CONSUMER_RULE_FAIL){ last_pid_match_result = MESA_MATCH_CONSUMER_RULE_FAIL; return MESA_MATCH_CONSUMER_RULE_FAIL_PID; } @@ -414,6 +465,10 @@ int MESA_shm_match_consumer_rule(int level, int pid) return MESA_MATCH_CONSUMER_RULE_FAIL_PID; } } + if(MESA_shm_match_module(module) == MESA_MATCH_CONSUMER_RULE_FAIL){ + return MESA_MATCH_CONSUMER_RULE_FAIL_MODULE; + } + return MESA_MATCH_CONSUMER_RULE_SUCCESS; } |
