X-Git-Url: http://git.archive.openwrt.org/?p=project%2Ffstools.git;a=blobdiff_plain;f=block.c;h=f41d7f6495d5fe63439daaa2d567deefd4f94522;hp=6eb19339f9a3223f3c70108d5727f8e3bfb2ce12;hb=164d78a108b24515f69ada82aadcef58572ba51e;hpb=325d23c5dad92c22720c6d1027c5761aaf12319c diff --git a/block.c b/block.c index 6eb1933..f41d7f6 100644 --- a/block.c +++ b/block.c @@ -423,33 +423,56 @@ static void mounts_update(struct vlist_tree *tree, struct vlist_node *node_new, { } -static int config_load(char *cfg) +static struct uci_package * config_try_load(struct uci_context *ctx, char *path) { - struct uci_context *ctx; + char *file = basename(path); + char *dir = dirname(path); + char *err; struct uci_package *pkg; + + uci_set_confdir(ctx, dir); + KINFO("attempting to load %s/%s\n", dir, file); + + if (uci_load(ctx, file, &pkg)) { + uci_get_errorstr(ctx, &err, file); + ERROR("unable to load configuration (%s)\n", err); + + free(err); + return NULL; + } + + return pkg; +} + +static int config_load(char *cfg) +{ + struct uci_context *ctx = uci_alloc_context(); + struct uci_package *pkg = NULL; struct uci_element *e; + char path[64]; vlist_init(&mounts, avl_strcmp, mounts_update); - ctx = uci_alloc_context(); if (cfg) { - char path[32]; - snprintf(path, 32, "%s/etc/config", cfg); - uci_set_confdir(ctx, path); - } + snprintf(path, sizeof(path), "%s/upper/etc/config/fstab", cfg); + pkg = config_try_load(ctx, path); - if (uci_load(ctx, "fstab", &pkg)) { - uci_set_confdir(ctx, "/etc/config"); - if (uci_load(ctx, "fstab", &pkg)) { - char *err; - uci_get_errorstr(ctx, &err, "fstab"); - ERROR("extroot: failed to load %s/etc/config/%s\n", - cfg ? cfg : "", err); - free(err); - return -1; + if (!pkg) { + snprintf(path, sizeof(path), "%s/etc/config/fstab", cfg); + pkg = config_try_load(ctx, path); } } + if (!pkg) { + snprintf(path, sizeof(path), "/etc/config/fstab"); + pkg = config_try_load(ctx, path); + } + + if (!pkg) { + ERROR("extroot: no usable configuration\n"); + return -1; + } + vlist_update(&mounts); uci_foreach_element(&pkg->sections, e) { struct uci_section *s = uci_to_section(e);