Пример #1
0
F_NONNULL
static const vscf_data_t* conf_load(const char* cfg_file) {
    dmn_assert(cfg_file);

    char* vscf_err;
    const vscf_data_t* cfg_root = vscf_scan_filename(cfg_file, &vscf_err);
    if(!cfg_root)
        log_fatal("Configuration load failed: %s", vscf_err);

    dmn_assert(vscf_is_hash(cfg_root));
    return cfg_root;
}
Пример #2
0
static vscf_data_t* conf_load_vscf(const char* cfg_file) {
    vscf_data_t* out = NULL;

    struct stat cfg_stat;
    if(!stat(cfg_file, &cfg_stat)) {
        log_info("Loading configuration from '%s'", cfg_file);
        out = vscf_scan_filename(cfg_file);
        if(!out)
            log_fatal("Loading configuration from '%s' failed", cfg_file);
        if(!vscf_is_hash(out)) {
            dmn_assert(vscf_is_array(out));
            log_fatal("Config file '%s' cannot be an '[ array ]' at the top level", cfg_file);
        }
    }
    else {
        log_info("No config file at '%s', using defaults", cfg_file);
    }

    return out;
}
Пример #3
0
static const vscf_data_t* conf_load_vscf(const char* cfg_dir) {
    const vscf_data_t* out = NULL;

    gdnsd_set_config_dir(cfg_dir);
    char*cfg_path = gdnsd_resolve_path_cfg("config", NULL);

    struct stat cfg_stat;
    if(!stat(cfg_path, &cfg_stat)) {
        log_info("Loading configuration from '%s'", cfg_path);
        char* vscf_err;
        out = vscf_scan_filename(cfg_path, &vscf_err);
        if(!out)
            log_fatal("Configuration from '%s' failed: %s", cfg_path, vscf_err);
        if(!vscf_is_hash(out))
            log_fatal("Configuration from '%s' failed: config was an array!", cfg_path);
    }
    else {
        log_info("No config file at '%s', using defaults + zones auto-scan", cfg_path);
    }

    free(cfg_path);
    return out;
}