2015-10-10 18:30:12 +08:00
|
|
|
#include "MESA_handle_logger.h"
|
|
|
|
|
#include "config_monitor.h"
|
2018-09-24 18:49:18 +08:00
|
|
|
#include "Maat_utils.h"
|
2015-10-10 18:30:12 +08:00
|
|
|
#include <dirent.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
2017-09-16 15:02:12 +08:00
|
|
|
#include <sys/stat.h>
|
2017-06-09 20:46:28 +08:00
|
|
|
#include <openssl/evp.h>
|
2017-09-10 19:02:28 +08:00
|
|
|
|
2017-09-13 11:40:56 +08:00
|
|
|
#define module_config_monitor (module_name_str("MAAT_FILE_MONITOR"))
|
2017-09-10 19:02:28 +08:00
|
|
|
|
2015-10-10 18:30:12 +08:00
|
|
|
|
|
|
|
|
#define CM_UPDATE_TYPE_ERR -1
|
|
|
|
|
#define CM_UPDATE_TYPE_NONE 0
|
|
|
|
|
|
|
|
|
|
#define CM_MAX_TABLE_NUM 256
|
|
|
|
|
#define MAX_CONFIG_FN_LEN 256
|
2018-07-05 17:34:06 +08:00
|
|
|
#define MAX_CONFIG_LINE (1024*16)
|
2017-06-09 20:46:28 +08:00
|
|
|
|
|
|
|
|
|
2015-10-10 18:30:12 +08:00
|
|
|
//#define USING_DICTATOR 1
|
|
|
|
|
extern "C" void __real_free(void*p);
|
|
|
|
|
struct cm_table_info_t
|
|
|
|
|
{
|
|
|
|
|
char table_name[MAX_CONFIG_FN_LEN];
|
|
|
|
|
char cfg_path[MAX_CONFIG_FN_LEN];
|
|
|
|
|
int cfg_num;
|
2017-06-09 20:46:28 +08:00
|
|
|
char encryp_algorithm[MAX_CONFIG_FN_LEN];
|
2015-10-10 18:30:12 +08:00
|
|
|
};
|
2020-01-22 20:49:45 +08:00
|
|
|
char* read_nxt_line_from_buff(const char* buff, size_t buff_size, size_t* offset, char*line, int line_size)
|
2017-06-09 20:46:28 +08:00
|
|
|
{
|
|
|
|
|
int this_offset=0;
|
2020-01-13 19:05:24 +08:00
|
|
|
const char* p;
|
2020-03-31 19:52:26 +08:00
|
|
|
//search for CRLF, aka CR '\r'(old Mac), LF '\n'(UNIX) or CRLF"\r\n" (Windows)
|
|
|
|
|
p=(const char*)memchr(buff+*offset,'\n',buff_size-*offset);
|
|
|
|
|
if(p==NULL)// NOT "\n" or "\r\n"
|
2017-06-09 20:46:28 +08:00
|
|
|
{
|
2020-03-31 19:52:26 +08:00
|
|
|
p=(const char*)memchr(buff+*offset,'\r',buff_size-*offset);
|
2017-06-09 20:46:28 +08:00
|
|
|
}
|
|
|
|
|
if(p!=NULL)//point to next character
|
|
|
|
|
{
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
else //Treat rest buff has no CRLF as a line.
|
|
|
|
|
{
|
|
|
|
|
p=buff+buff_size;
|
|
|
|
|
}
|
|
|
|
|
this_offset=p-(buff+*offset);
|
2020-01-13 19:05:24 +08:00
|
|
|
memcpy(line,buff+*offset, MIN(this_offset,line_size-1));
|
2017-06-09 20:46:28 +08:00
|
|
|
*offset+=this_offset;
|
2020-01-13 19:05:24 +08:00
|
|
|
line[MIN(this_offset,line_size-1)]='\0';
|
2017-06-09 20:46:28 +08:00
|
|
|
return line;
|
|
|
|
|
}
|
2015-10-10 18:30:12 +08:00
|
|
|
//replacement of glibc scandir, to adapt dictator malloc wrap
|
|
|
|
|
#define ENLARGE_STEP 1024
|
|
|
|
|
int my_scandir(const char *dir, struct dirent ***namelist,
|
|
|
|
|
int(*filter)(const struct dirent *),
|
|
|
|
|
int(*compar)(const void *, const void *))
|
|
|
|
|
{
|
|
|
|
|
DIR * od;
|
|
|
|
|
int n = 0;
|
|
|
|
|
int DIR_ENT_SIZE=ENLARGE_STEP;
|
|
|
|
|
struct dirent ** list = NULL;
|
|
|
|
|
struct dirent * p;
|
|
|
|
|
struct dirent entry,*result;
|
|
|
|
|
|
|
|
|
|
if((dir == NULL) || (namelist == NULL))
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
od = opendir(dir);
|
|
|
|
|
if(od == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
list = (struct dirent **)malloc(DIR_ENT_SIZE*sizeof(struct dirent *));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(0==readdir_r(od,&entry,&result))
|
|
|
|
|
{
|
|
|
|
|
if(result==NULL)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if( filter && !filter(&entry))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
p = (struct dirent *)malloc(sizeof(struct dirent));
|
|
|
|
|
memcpy((void *)p,(void *)(&entry),sizeof(struct dirent));
|
|
|
|
|
list[n] = p;
|
|
|
|
|
|
|
|
|
|
n++;
|
|
|
|
|
if(n >= DIR_ENT_SIZE)
|
|
|
|
|
{
|
|
|
|
|
DIR_ENT_SIZE+=ENLARGE_STEP;
|
|
|
|
|
list=(struct dirent **)realloc((void*)list,DIR_ENT_SIZE*sizeof(struct dirent *));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closedir(od);
|
|
|
|
|
|
|
|
|
|
*namelist = list;
|
|
|
|
|
|
|
|
|
|
if(compar)
|
|
|
|
|
qsort((void *)*namelist,n,sizeof(struct dirent *),compar);
|
|
|
|
|
|
|
|
|
|
return n;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
int filter_fn(const struct dirent * ent)
|
|
|
|
|
{
|
2016-12-19 15:27:31 +08:00
|
|
|
// files in xfs are not DT_REG.
|
|
|
|
|
// if(ent->d_type != DT_REG)
|
|
|
|
|
// return 0;
|
2015-10-10 18:30:12 +08:00
|
|
|
|
|
|
|
|
return (strncmp(ent->d_name,"full_config_index",strlen("full_config_index")) == 0||
|
|
|
|
|
strncmp(ent->d_name,"inc_config_index",strlen("inc_config_index")) == 0);
|
|
|
|
|
}
|
2017-12-06 18:12:32 +08:00
|
|
|
int get_new_idx_path(long long current_version,const char*file_dir,void* logger,char*** idx_path,int*idx_num)
|
2015-10-10 18:30:12 +08:00
|
|
|
{
|
|
|
|
|
struct dirent **namelist;
|
|
|
|
|
int n=0,i=0,sscanf_ret;
|
|
|
|
|
|
|
|
|
|
char update_str[32]={0};
|
2017-12-06 18:12:32 +08:00
|
|
|
long long latest_ful_version=0,latest_inc_version=0;
|
|
|
|
|
long long config_seq=0;
|
2015-10-10 18:30:12 +08:00
|
|
|
int *inc_file_idx;
|
|
|
|
|
int full_file_idx=0,inc_idx_num=0,path_len=0;
|
|
|
|
|
|
|
|
|
|
int update_type=CM_UPDATE_TYPE_NONE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
n = my_scandir(file_dir, &namelist, filter_fn, (int (*)(const void*, const void*))alphasort);
|
|
|
|
|
if (n < 0)
|
|
|
|
|
{
|
|
|
|
|
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,module_config_monitor,"scan dir error");
|
|
|
|
|
update_type=CM_UPDATE_TYPE_ERR;
|
|
|
|
|
return update_type;
|
|
|
|
|
}
|
|
|
|
|
inc_file_idx=(int*)calloc(sizeof(int),n);
|
|
|
|
|
inc_idx_num=0;
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
config_seq=0;
|
|
|
|
|
if((strcmp(namelist[i]->d_name, ".") == 0) || (strcmp(namelist[i]->d_name, "..") == 0))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2018-11-14 18:37:20 +08:00
|
|
|
if(strlen(namelist[i]->d_name)>42)
|
2015-10-10 18:30:12 +08:00
|
|
|
{
|
|
|
|
|
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,module_config_monitor
|
2018-11-14 18:37:20 +08:00
|
|
|
,"config file %s filename too long,should like full_config_index.00000000000000000001"
|
2015-10-10 18:30:12 +08:00
|
|
|
,namelist[i]->d_name);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-12-06 18:12:32 +08:00
|
|
|
sscanf_ret=sscanf(namelist[i]->d_name,"%[a-zA-Z]_config_index.%lld",update_str,&config_seq);
|
2015-10-10 18:30:12 +08:00
|
|
|
if(sscanf_ret!=2)
|
|
|
|
|
{
|
|
|
|
|
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,module_config_monitor
|
2018-11-14 18:37:20 +08:00
|
|
|
,"config file %s filename error,should like full_config_index.00000000000000000001"
|
2015-10-10 18:30:12 +08:00
|
|
|
,namelist[i]->d_name);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(strncasecmp(update_str,"full",strlen(update_str))==0)
|
|
|
|
|
{
|
|
|
|
|
if(config_seq>latest_ful_version)
|
|
|
|
|
{
|
|
|
|
|
latest_ful_version=config_seq;
|
|
|
|
|
full_file_idx=i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(strncasecmp(update_str,"inc",strlen(update_str))==0)
|
|
|
|
|
{
|
|
|
|
|
if(config_seq>current_version)
|
|
|
|
|
{
|
|
|
|
|
inc_file_idx[inc_idx_num]=i;
|
|
|
|
|
inc_idx_num++;
|
|
|
|
|
if(config_seq>latest_inc_version)
|
|
|
|
|
{
|
|
|
|
|
latest_inc_version=config_seq;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,module_config_monitor
|
|
|
|
|
,"config file %s,not full or inc config"
|
|
|
|
|
,namelist[i]->d_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//full update
|
|
|
|
|
if(latest_ful_version>current_version)
|
|
|
|
|
{
|
|
|
|
|
*idx_path=(char**)malloc(sizeof(char**));
|
|
|
|
|
path_len=strlen(file_dir)+strlen(namelist[full_file_idx]->d_name)+1+1;
|
|
|
|
|
(*idx_path)[0]=(char*)malloc(path_len);
|
|
|
|
|
snprintf((*idx_path)[0],path_len,"%s/%s",file_dir,namelist[full_file_idx]->d_name);
|
|
|
|
|
*idx_num=1;
|
|
|
|
|
update_type=CM_UPDATE_TYPE_FULL;
|
|
|
|
|
}
|
2017-09-16 15:02:12 +08:00
|
|
|
//inc update,it's possible that do inc after full update in this function,but we'll process it at next loop.
|
2015-10-10 18:30:12 +08:00
|
|
|
else if(latest_inc_version>current_version)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
*idx_path=(char**)malloc(sizeof(char**)*inc_idx_num);
|
|
|
|
|
for(i=0;i<inc_idx_num;i++)
|
|
|
|
|
{
|
|
|
|
|
path_len=strlen(file_dir)+strlen(namelist[inc_file_idx[i]]->d_name)+1+1;
|
|
|
|
|
(*idx_path)[i]=(char*)malloc(path_len);
|
|
|
|
|
snprintf((*idx_path)[i],path_len,"%s/%s",file_dir,namelist[inc_file_idx[i]]->d_name);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
*idx_num=inc_idx_num;
|
|
|
|
|
update_type=CM_UPDATE_TYPE_INC;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
update_type=CM_UPDATE_TYPE_NONE;
|
|
|
|
|
}
|
|
|
|
|
free(inc_file_idx);
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
free(namelist[i]);
|
|
|
|
|
}
|
|
|
|
|
free(namelist);
|
|
|
|
|
|
|
|
|
|
return update_type;
|
|
|
|
|
}
|
|
|
|
|
int cm_read_cfg_index_file(const char* path,struct cm_table_info_t* idx,int size,void* logger)
|
|
|
|
|
{
|
|
|
|
|
FILE* fp=NULL;
|
|
|
|
|
fp=fopen(path,"r");
|
|
|
|
|
int ret=0,i=0;
|
2017-06-09 20:46:28 +08:00
|
|
|
char line[MAX_CONFIG_LINE];
|
2017-09-16 15:02:12 +08:00
|
|
|
struct stat file_info;
|
2015-10-10 18:30:12 +08:00
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
2017-06-15 17:56:06 +08:00
|
|
|
memset(line,0,sizeof(line));
|
2017-06-09 20:46:28 +08:00
|
|
|
fgets(line,sizeof(line),fp);
|
|
|
|
|
ret=sscanf(line,"%s\t%d\t%s\t%s",idx[i].table_name
|
2015-10-10 18:30:12 +08:00
|
|
|
,&(idx[i].cfg_num)
|
2017-06-09 20:46:28 +08:00
|
|
|
,idx[i].cfg_path
|
|
|
|
|
,idx[i].encryp_algorithm);
|
2017-09-16 15:02:12 +08:00
|
|
|
if(!(ret==3||ret==4)||idx[i].cfg_num==0)//jump over empty line
|
2015-10-10 18:30:12 +08:00
|
|
|
{
|
2017-09-16 15:02:12 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
ret=stat(idx[i].cfg_path,&file_info);
|
|
|
|
|
if(ret!=0)
|
|
|
|
|
{
|
|
|
|
|
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,module_config_monitor ,"%s of %s not exisit",
|
|
|
|
|
idx[i].cfg_path,
|
|
|
|
|
path);
|
2017-09-30 14:14:29 +08:00
|
|
|
fclose(fp);
|
2017-09-16 15:02:12 +08:00
|
|
|
return -1;
|
2015-10-10 18:30:12 +08:00
|
|
|
}
|
2017-09-16 15:02:12 +08:00
|
|
|
i++;
|
2015-10-10 18:30:12 +08:00
|
|
|
if(i==size)
|
|
|
|
|
{
|
|
|
|
|
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,module_config_monitor ,"Too much lines in %s",path);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cm_read_table_file(struct cm_table_info_t* index,
|
2017-08-09 18:27:08 +08:00
|
|
|
int (*update)(const char*,const char*,void*),
|
2015-10-10 18:30:12 +08:00
|
|
|
void* u_para,
|
2020-01-13 19:05:24 +08:00
|
|
|
const char* key,
|
2015-10-10 18:30:12 +08:00
|
|
|
void* logger)
|
|
|
|
|
{
|
|
|
|
|
int cfg_num=0,i=0;
|
2017-08-09 18:27:08 +08:00
|
|
|
int ret=0;
|
2020-01-13 19:05:24 +08:00
|
|
|
char error_string[MAX_CONFIG_FN_LEN];
|
2015-10-10 18:30:12 +08:00
|
|
|
char line[MAX_CONFIG_LINE]={0},*ret_str=NULL;
|
2020-01-13 19:05:24 +08:00
|
|
|
char* table_file_buff=NULL;
|
2020-01-22 20:49:45 +08:00
|
|
|
size_t file_sz=0, file_offset=0;
|
2020-01-13 19:05:24 +08:00
|
|
|
|
2017-06-09 20:46:28 +08:00
|
|
|
if(strlen(index->encryp_algorithm)>0)
|
|
|
|
|
{
|
|
|
|
|
if(key==NULL||strlen((const char*)key)==0)
|
|
|
|
|
{
|
2017-12-21 09:36:13 +08:00
|
|
|
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,module_config_monitor,"update error, no key to decrypt %s.",index->cfg_path);
|
2017-06-09 20:46:28 +08:00
|
|
|
return -1;
|
|
|
|
|
}
|
2020-01-22 20:49:45 +08:00
|
|
|
ret=decrypt_open(index->cfg_path, key, index->encryp_algorithm, (unsigned char**)&table_file_buff, &file_sz, error_string, sizeof(error_string));
|
|
|
|
|
if(ret<0)
|
2017-06-09 20:46:28 +08:00
|
|
|
{
|
2020-01-22 20:49:45 +08:00
|
|
|
MESA_handle_runtime_log(logger, RLOG_LV_FATAL, module_config_monitor, "update error, decrypt %s failed: %s",
|
2020-01-13 19:05:24 +08:00
|
|
|
index->cfg_path, error_string);
|
2017-06-09 20:46:28 +08:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-01-22 20:49:45 +08:00
|
|
|
ret=load_file_to_memory(index->cfg_path, (unsigned char**)&table_file_buff, &file_sz);
|
|
|
|
|
if(ret<0)
|
2020-01-13 19:05:24 +08:00
|
|
|
{
|
2020-01-22 20:49:45 +08:00
|
|
|
MESA_handle_runtime_log(logger, RLOG_LV_FATAL, module_config_monitor, "update error, open %s failed: %s",
|
2020-01-13 19:05:24 +08:00
|
|
|
index->cfg_path, error_string);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 20:46:28 +08:00
|
|
|
}
|
2020-01-13 19:05:24 +08:00
|
|
|
read_nxt_line_from_buff(table_file_buff, file_sz, &file_offset, line, sizeof(line));
|
|
|
|
|
sscanf(line, "%d\n", &cfg_num);
|
|
|
|
|
|
2015-10-10 18:30:12 +08:00
|
|
|
if(cfg_num!=index->cfg_num)
|
|
|
|
|
{
|
2020-01-13 19:05:24 +08:00
|
|
|
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,module_config_monitor, "file %s config num not matched", index->cfg_path);
|
2015-10-10 18:30:12 +08:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<cfg_num;i++)
|
|
|
|
|
{
|
|
|
|
|
line[sizeof(line)-1]='\0';
|
2020-01-13 19:05:24 +08:00
|
|
|
|
|
|
|
|
ret_str=read_nxt_line_from_buff(table_file_buff, file_sz, &file_offset, line, sizeof(line));
|
|
|
|
|
|
2015-10-10 18:30:12 +08:00
|
|
|
if(ret_str==NULL)
|
|
|
|
|
{
|
|
|
|
|
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,module_config_monitor ,
|
|
|
|
|
"update error,file %s line_num %d less than claimed %d",
|
|
|
|
|
index->cfg_path,i,cfg_num);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if(line[sizeof(line)-1]!='\0')
|
|
|
|
|
{
|
|
|
|
|
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,module_config_monitor ,
|
|
|
|
|
"update error,line size more than %u at of file %s:%d",
|
|
|
|
|
sizeof(line),index->cfg_path,i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-08-09 18:27:08 +08:00
|
|
|
ret=update(index->table_name,line,u_para);
|
|
|
|
|
if(ret<0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-10-10 18:30:12 +08:00
|
|
|
}
|
2020-01-13 19:05:24 +08:00
|
|
|
|
|
|
|
|
free(table_file_buff);
|
|
|
|
|
|
2015-10-10 18:30:12 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
const char* path2filename(const char*path)
|
|
|
|
|
{
|
|
|
|
|
int i=0;
|
|
|
|
|
for(i=strlen(path);i>0;i--)
|
|
|
|
|
{
|
|
|
|
|
if(path[i]=='/')
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return path+i+1;
|
|
|
|
|
}
|
2017-12-06 18:12:32 +08:00
|
|
|
void config_monitor_traverse(long long version,const char*idx_dir,
|
|
|
|
|
void (*start)(long long, int, void*),//vesion,CM_UPDATE_TYPE_*,u_para
|
|
|
|
|
int (*update)(const char*, const char*, void*),//table name ,line ,u_para
|
|
|
|
|
void (*finish)(void*),//u_para
|
2015-10-10 18:30:12 +08:00
|
|
|
void* u_para,
|
2020-01-13 19:05:24 +08:00
|
|
|
const char* dec_key,
|
2015-10-10 18:30:12 +08:00
|
|
|
void* logger)
|
2017-12-06 18:12:32 +08:00
|
|
|
|
2015-10-10 18:30:12 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int update_type=CM_UPDATE_TYPE_NONE;
|
2017-12-06 18:12:32 +08:00
|
|
|
long long new_version=0;
|
2015-10-10 18:30:12 +08:00
|
|
|
char**idx_path_array=NULL;
|
|
|
|
|
const char* table_filename=NULL;
|
|
|
|
|
char str_not_care[256]={0};
|
|
|
|
|
int idx_num=0,table_num=0,i=0,j=0;
|
|
|
|
|
struct cm_table_info_t table_array[CM_MAX_TABLE_NUM];
|
2017-09-28 20:24:20 +08:00
|
|
|
memset(table_array,0,sizeof(table_array));
|
2015-10-10 18:30:12 +08:00
|
|
|
update_type=get_new_idx_path(version, idx_dir,logger, &idx_path_array, &idx_num);
|
|
|
|
|
if(update_type==CM_UPDATE_TYPE_FULL||update_type==CM_UPDATE_TYPE_INC)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for(i=0;i<idx_num;i++)
|
|
|
|
|
{
|
|
|
|
|
MESA_handle_runtime_log(logger,RLOG_LV_INFO,module_config_monitor ,
|
|
|
|
|
"load %s",idx_path_array[i]);
|
|
|
|
|
table_num=cm_read_cfg_index_file(idx_path_array[i],table_array, CM_MAX_TABLE_NUM,logger);
|
2017-09-16 15:02:12 +08:00
|
|
|
if(table_num<0)
|
|
|
|
|
{
|
|
|
|
|
MESA_handle_runtime_log(logger,RLOG_LV_INFO,module_config_monitor ,
|
|
|
|
|
"load %s faild, abandon udpate.",idx_path_array[i]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-10-10 18:30:12 +08:00
|
|
|
table_filename=path2filename(idx_path_array[i]);
|
2017-12-06 18:12:32 +08:00
|
|
|
sscanf(table_filename,"%[a-zA-Z]_config_index.%lld",str_not_care,&new_version);
|
2018-01-26 18:47:51 +08:00
|
|
|
if(start!=NULL)
|
|
|
|
|
{
|
|
|
|
|
start(new_version,update_type,u_para);
|
|
|
|
|
}
|
2015-10-10 18:30:12 +08:00
|
|
|
for(j=0;j<table_num;j++)
|
|
|
|
|
{
|
2020-01-13 19:05:24 +08:00
|
|
|
cm_read_table_file(table_array+j, update, u_para, dec_key, logger);
|
2015-10-10 18:30:12 +08:00
|
|
|
}
|
2018-01-26 18:47:51 +08:00
|
|
|
if(finish!=NULL)
|
|
|
|
|
{
|
|
|
|
|
finish(u_para);
|
|
|
|
|
}
|
2015-10-10 18:30:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(i=0;i<idx_num;i++)
|
|
|
|
|
{
|
|
|
|
|
free(idx_path_array[i]);
|
|
|
|
|
}
|
|
|
|
|
free(idx_path_array);//free null is OK
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|