diff --git a/src/entry/Maat_api.cpp b/src/entry/Maat_api.cpp index cae6fec..e13d68a 100644 --- a/src/entry/Maat_api.cpp +++ b/src/entry/Maat_api.cpp @@ -493,7 +493,7 @@ Maat_feather_t Maat_feather(int max_thread_num,const char* table_info_path,void* feather->backgroud_update_enabled=1; feather->foreign_cont_linger=0; snprintf(feather->foreign_cont_dir, sizeof(feather->foreign_cont_dir), "%s_files", table_info_path); - pthread_mutex_init(&(feather->backgroud_update_mutex),NULL); + pthread_mutex_init(&(feather->background_update_mutex),NULL); snprintf(feather->table_info_fn,sizeof(feather->table_info_fn),"%s",table_info_path); return feather; } @@ -510,14 +510,14 @@ int Maat_set_feather_opt(Maat_feather_t feather,enum MAAT_INIT_OPT type,const vo { if(intval==0) { - pthread_mutex_lock(&(_feather->backgroud_update_mutex)); + pthread_mutex_lock(&(_feather->background_update_mutex)); MESA_handle_runtime_log(_feather->logger,RLOG_LV_INFO,maat_module , "Background update is disabled, current version %lld." ,_feather->maat_version); } else { - pthread_mutex_unlock(&(_feather->backgroud_update_mutex)); + pthread_mutex_unlock(&(_feather->background_update_mutex)); MESA_handle_runtime_log(_feather->logger,RLOG_LV_INFO,maat_module , "Background update is enabled, current version %lld." ,_feather->maat_version); @@ -678,7 +678,7 @@ int Maat_set_feather_opt(Maat_feather_t feather,enum MAAT_INIT_OPT type,const vo case MAAT_OPT_LOAD_VERSION_FROM: _feather->load_version_from=*((long long*)value); _feather->backgroud_update_enabled=1; - pthread_mutex_lock((&_feather->backgroud_update_mutex)); + pthread_mutex_lock((&_feather->background_update_mutex)); MESA_handle_runtime_log(_feather->logger,RLOG_LV_INFO,maat_module , "Maat load version from %lld, stops backgroud update." ,_feather->load_version_from); @@ -932,11 +932,11 @@ int Maat_table_callback_register(Maat_feather_t feather,short table_id, return -1; } //plugin table register blocks background update. - pthread_mutex_lock(&(_feather->backgroud_update_mutex)); + pthread_mutex_lock(&(_feather->background_update_mutex)); idx=plugin_desc->cb_plug_cnt; if(idx==MAX_PLUGIN_PER_TABLE) { - pthread_mutex_unlock(&(_feather->backgroud_update_mutex)); + pthread_mutex_unlock(&(_feather->background_update_mutex)); return -1; } plugin_desc->cb_plug_cnt++; @@ -946,7 +946,7 @@ int Maat_table_callback_register(Maat_feather_t feather,short table_id, plugin_desc->cb_plug[idx].u_para=u_para; if(_feather->scanner==NULL) { - pthread_mutex_unlock(&(_feather->backgroud_update_mutex)); + pthread_mutex_unlock(&(_feather->background_update_mutex)); return 1; } plugin_aux = &(_feather->scanner->table_rt[table_id]->plugin); @@ -970,7 +970,7 @@ int Maat_table_callback_register(Maat_feather_t feather,short table_id, finish(u_para); } } - pthread_mutex_unlock(&(_feather->backgroud_update_mutex)); + pthread_mutex_unlock(&(_feather->background_update_mutex)); return 1; } @@ -1011,7 +1011,7 @@ int Maat_rule_get_ex_new_index(Maat_feather_t feather, const char* compile_table return -1; } struct compile_table_desc* compile_desc=&(p_table->compile); - pthread_mutex_lock(&(_feather->backgroud_update_mutex)); + pthread_mutex_lock(&(_feather->background_update_mutex)); if(compile_desc->ex_data_num==MAX_COMPILE_EX_DATA_NUM) { ret=-1; @@ -1032,7 +1032,7 @@ int Maat_rule_get_ex_new_index(Maat_feather_t feather, const char* compile_table MESA_htable_iterate(_feather->scanner->compile_hash, rule_ex_data_new_cb, compile_desc->ex_desc+idx); } failed: - pthread_mutex_unlock(&(_feather->backgroud_update_mutex)); + pthread_mutex_unlock(&(_feather->background_update_mutex)); return idx; } @@ -1206,6 +1206,9 @@ int Maat_plugin_EX_register(Maat_feather_t feather, int table_id, "%s failed: key or valid flag column are not specified", __FUNCTION__); return -1; } + + pthread_mutex_lock(&(_feather->background_update_mutex)); + plugin_desc->ex_desc.new_func=new_func; plugin_desc->ex_desc.free_func=free_func; plugin_desc->ex_desc.dup_func=dup_func; @@ -1213,17 +1216,14 @@ int Maat_plugin_EX_register(Maat_feather_t feather, int table_id, plugin_desc->ex_desc.argl=argl; plugin_desc->ex_desc.argp=argp; plugin_desc->have_exdata=1; - if(_feather->scanner==NULL) + if(_feather->scanner!=NULL) { - return 0; + table_rt=_feather->scanner->table_rt[table_id]; + assert(table_rt->plugin.key2ex_hash==NULL); + table_rt->plugin.key2ex_hash=plugin_EX_htable_new(table_desc, table_rt->plugin.cache_lines, + table_rt->plugin.cache_line_num, _feather->logger); } - - pthread_mutex_lock(&(_feather->backgroud_update_mutex)); - table_rt=_feather->scanner->table_rt[table_id]; - assert(table_rt->plugin.key2ex_hash==NULL); - table_rt->plugin.key2ex_hash=plugin_EX_htable_new(table_desc, table_rt->plugin.cache_lines, - table_rt->plugin.cache_line_num, _feather->logger); - pthread_mutex_unlock(&(_feather->backgroud_update_mutex)); + pthread_mutex_unlock(&(_feather->background_update_mutex)); return 0; } @@ -2266,10 +2266,10 @@ int Maat_read_state(Maat_feather_t feather,enum MAAT_STATE_OPT type, void* valu { return -1; } - if(0==pthread_mutex_trylock(&(_feather->backgroud_update_mutex))) + if(0==pthread_mutex_trylock(&(_feather->background_update_mutex))) { *int_val=0; - pthread_mutex_unlock(&(_feather->backgroud_update_mutex)); + pthread_mutex_unlock(&(_feather->background_update_mutex)); } else { diff --git a/src/entry/Maat_rule.cpp b/src/entry/Maat_rule.cpp index 803d70e..e091ccc 100644 --- a/src/entry/Maat_rule.cpp +++ b/src/entry/Maat_rule.cpp @@ -32,7 +32,7 @@ #include "stream_fuzzy_hash.h" #include "gram_index_engine.h" -int MAAT_FRAME_VERSION_2_5_20181212=1; +int MAAT_FRAME_VERSION_2_5_20181216=1; const char* CHARSET_STRING[]={"NONE","gbk","big5","unicode","utf8","bin", "unicode_ascii_esc","unicode_ascii_aligned","unicode_ncr_dec","unicode_ncr_hex","url_encode_gb2312","url_encode_utf8",""}; @@ -3565,17 +3565,20 @@ void *thread_rule_monitor(void *arg) //pthread_setname_np are introduced in glibc2.12 //ret=pthread_setname_np(pthread_self(),maat_name); assert(ret>=0); + + pthread_mutex_lock(&(feather->background_update_mutex)); if(feather->DEFERRED_LOAD_ON!=0) { MESA_handle_runtime_log(feather->logger,RLOG_LV_INFO,maat_module, "Deferred Loading ON, updating in %s.",__func__); maat_read_full_config(feather); } + pthread_mutex_unlock(&(feather->background_update_mutex)); while(feather->still_working) { usleep(feather->scan_interval_ms*1000); scan_dir_cnt++; - if(0==pthread_mutex_trylock(&(feather->backgroud_update_mutex))) + if(0==pthread_mutex_trylock(&(feather->background_update_mutex))) { switch(feather->input_mode) { @@ -3693,7 +3696,7 @@ void *thread_rule_monitor(void *arg) feather->scanner->version,feather->scanner->cfg_num); } } - pthread_mutex_unlock(&(feather->backgroud_update_mutex)); + pthread_mutex_unlock(&(feather->background_update_mutex)); } garbage_bury(feather->garbage_q,feather->effect_interval_ms/1000+10,feather->logger); if(feather->stat_on==1&&time(NULL)%2==0)//output every 2 seconds diff --git a/src/inc_internal/Maat_rule_internal.h b/src/inc_internal/Maat_rule_internal.h index 00b5529..c73afe9 100644 --- a/src/inc_internal/Maat_rule_internal.h +++ b/src/inc_internal/Maat_rule_internal.h @@ -350,7 +350,7 @@ struct _Maat_feather_t char table_info_fn[MAX_TABLE_NAME_LEN]; char compile_tn[MAX_TABLE_NAME_LEN]; char group_tn[MAX_TABLE_NAME_LEN]; - pthread_mutex_t backgroud_update_mutex; + pthread_mutex_t background_update_mutex; unsigned char decrypt_key[MAX_TABLE_NAME_LEN]; pthread_t cfg_mon_t;