//解析配置信息,并进行有效性判断 struct conf * conf_create(char *filename) { rstatus_t status; struct conf *cf; //打开配置文件,创建conf结构,并初始化 cf = conf_open(filename); if (cf == NULL) { return NULL; } /* validate configuration file before parsing */ status = conf_pre_validate(cf); //检查配置格式是否符合yml标准 if (status != NC_OK) { goto error; } /* parse the configuration file */ status = conf_parse(cf); //配置解析 if (status != NC_OK) { goto error; } /* validate parsed configuration */ status = conf_post_validate(cf); //重复性判断 if (status != NC_OK) { goto error; } conf_dump(cf); fclose(cf->fh); cf->fh = NULL; return cf; error: log_stderr("nutcracker: configuration file '%s' syntax is invalid", filename); fclose(cf->fh); cf->fh = NULL; conf_destroy(cf); return NULL; }
rmt_conf * conf_create(char *filename) { int ret; rmt_conf *cf; cf = conf_open(filename); if (cf == NULL) { return NULL; } /* validate configuration file before parsing */ ret = conf_pre_validate(cf); if (ret != RMT_OK) { goto error; } conf_organizations_dump(cf); /* parse the configuration file */ ret = conf_parse(cf); if (ret != RMT_OK) { goto error; } /* validate parsed configuration */ ret = conf_post_validate(cf); if (ret != RMT_OK) { goto error; } conf_dump(cf); fclose(cf->fh); cf->fh = NULL; return cf; error: fclose(cf->fh); cf->fh = NULL; conf_destroy(cf); return NULL; }
struct conf * conf_create(char *filename) { rstatus_t status; struct conf *cf; cf = conf_open(filename); if (cf == NULL) { return NULL; } /* validate configuration file before parsing */ status = conf_pre_validate(cf); if (status != NC_OK) { goto error; } /* parse the configuration file */ status = conf_parse(cf); if (status != NC_OK) { goto error; } /* validate parsed configuration */ status = conf_post_validate(cf); if (status != NC_OK) { goto error; } conf_dump(cf); fclose(cf->fh); cf->fh = NULL; return cf; error: fclose(cf->fh); cf->fh = NULL; conf_destroy(cf); return NULL; }