}
log_very_verbose("Loading config file: %s", config_file);
- if (!config_file_read(cft)) {
+ if (!config_file_read_from_file(cft)) {
log_error("Failed to load config file %s", config_file);
goto bad;
}
return r;
}
-int config_file_read(struct dm_config_tree *cft)
+int config_file_read_from_file(struct dm_config_tree *cft)
{
const char *filename = NULL;
struct config_source *cs = dm_config_get_custom(cft);
struct stat info;
struct device fake_dev = { 0 };
struct dm_str_list *alias;
- int free_fake = 0;
int fd;
int r;
cf = cs->source.file;
+ if (cf->dev)
+ return_0;
+
/* fixme: get rid of fake dev and just
add separate code paths for files */
- if (!cf->dev) {
- if (!(alias = zalloc(sizeof(*alias))))
- return_0;
- if (!(alias->str = strdup(filename))) {
- free(alias);
- return_0;
- }
- dev_init(&fake_dev);
- fake_dev.flags = DEV_REGULAR;
- dm_list_add(&fake_dev.aliases, &alias->list);
-
- if ((fd = open(filename, O_RDONLY, 0777)) < 0) {
- log_error("Failed to open config file %s.", filename);
- free((void*)alias->str);
- free((void*)alias);
- return_0;
- }
- fake_dev.fd = fd;
- free_fake = 1;
- cf->dev = &fake_dev;
+ if (!(alias = zalloc(sizeof(*alias))))
+ return_0;
+ if (!(alias->str = strdup(filename))) {
+ free(alias);
+ return_0;
}
+ dev_init(&fake_dev);
+ fake_dev.flags = DEV_REGULAR;
+ dm_list_add(&fake_dev.aliases, &alias->list);
- r = config_file_read_fd(cft, cf->dev, DEV_IO_MDA_CONTENT, 0, (size_t) info.st_size, 0, 0,
- (checksum_fn_t) NULL, 0, 0, 0);
-
- if (free_fake) {
+ if ((fd = open(filename, O_RDONLY, 0777)) < 0) {
+ log_error("Failed to open config file %s.", filename);
free((void*)alias->str);
free((void*)alias);
- close(fd);
- } else {
- if (!dev_close(cf->dev))
- stack;
+ return_0;
}
+ fake_dev.fd = fd;
+ cf->dev = &fake_dev;
+
+ r = config_file_read_fd(cft, cf->dev, DEV_IO_MDA_CONTENT, 0, (size_t) info.st_size, 0, 0,
+ (checksum_fn_t) NULL, 0, 0, 0);
+
+ free((void*)alias->str);
+ free((void*)alias);
+ close(fd);
+
cf->dev = NULL;
return r;
off_t offset, size_t size, off_t offset2, size_t size2,
checksum_fn_t checksum_fn, uint32_t checksum,
int skip_parse, int no_dup_node_check);
-int config_file_read(struct dm_config_tree *cft);
+int config_file_read_from_file(struct dm_config_tree *cft);
struct dm_config_tree *config_file_open_and_read(const char *config_file, config_source_t source,
struct cmd_context *cmd);
int config_write(struct dm_config_tree *cft, struct config_def_tree_spec *tree_spec,