main
|-----.....
|-----tracker_load_from_conf_file
|-----
tracker_load_status_from_file
|-----base64_init_ex
|-----.....
在main函数中,调用tracker_load_status_from_file从状态文件中获取状态信息到g_tracker_last_status变量中
-
if ((result=tracker_load_status_from_file(&g_tracker_last_status)) != 0)//从状态文件中读取状态信息
-
{
-
log_destroy();
-
return result;
-
}
-
typedef struct {
-
time_t up_time; //tracker的uptime
-
time_t last_check_time; //tracker的最后checktime
-
} TrackerStatus
-
//从状态文件获取tracker的状态信息
-
int tracker_load_status_from_file(TrackerStatus *pStatus)
-
{
-
char full_filename[MAX_PATH_SIZE];
-
IniContext iniContext;
-
int result;
-
-
snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \
-
g_fdfs_base_path, TRACKER_STATUS_FILENAME); //这个地址是 g_fdfs_base_path/data/.tracker_status,这个文件是个隐藏文件,g_fdfs_base_path是从配置tracker的配置文件中获取得到的
-
if (!fileExists(full_filename)) //由于程序刚刚初始化,这个文件应该还没有被创建,所以这里直接返回了
-
{
-
return 0;
-
}
-
-
memset(&iniContext, 0, sizeof(IniContext));
-
if ((result=iniLoadFromFile(full_filename, &iniContext)) != 0) //iniLoadFromFile在以前读取配置文件的过程中分析过
-
{
-
logError("file: "__FILE__", line: %d, " \
-
"load from status file \"%s\" fail, " \
-
"error code: %d", \
-
__LINE__, full_filename, result);
-
return result;
-
}
-
-
pStatus->up_time = iniGetIntValue(NULL, TRACKER_STATUS_ITEM_UP_TIME, \ //获取up_time
-
&iniContext, 0);
-
pStatus->last_check_time = iniGetIntValue(NULL, \ //获取last_check_time
-
TRACKER_STATUS_ITEM_LAST_CHECK_TIME, &iniContext, 0);
-
-
iniFreeContext(&iniContext); //释放iniContext空间,这个函数也在读取配置文件的过程中分析过
-
-
return 0;
-
}
tracker_load_status_from_file执行完毕后,tracker从配置文件中读取的信息保存在全局变量g_tracker_last_status中了
阅读(713) | 评论(0) | 转发(0) |