Commit 5c9c1d54 authored by Daniel Salzman's avatar Daniel Salzman

knot: change zone_load_contents to return error code

parent 624d44e8
......@@ -783,8 +783,9 @@ static int cmd_checkzone(cmd_args_t *args)
}
/* Create zone loader context. */
zone_contents_t *contents = zone_load_contents(conf(), conf_dname(&id));
if (contents == NULL) {
zone_contents_t *contents;
int ret = zone_load_contents(conf(), conf_dname(&id), &contents);
if (ret != KNOT_EOK) {
rc = 1;
continue;
}
......
......@@ -320,35 +320,37 @@ int event_load(zone_t *zone)
time_t mtime = zonefile_mtime(filename);
free(filename);
uint32_t dnssec_refresh = time(NULL);
zone_contents_t *contents = zone_load_contents(conf(), zone->name);
if (!contents) {
return KNOT_ERROR;
zone_contents_t *contents;
int ret = zone_load_contents(conf(), zone->name, &contents);
if (ret != KNOT_EOK) {
return ret;
}
/* Store zonefile serial and apply changes from the journal. */
zone->zonefile_serial = zone_contents_serial(contents);
int result = zone_load_journal(conf(), zone, contents);
if (result != KNOT_EOK) {
ret = zone_load_journal(conf(), zone, contents);
if (ret != KNOT_EOK) {
goto fail;
}
/* Post load actions - calculate delta, sign with DNSSEC... */
/*! \todo issue #242 dnssec signing should occur in the special event */
result = zone_load_post(conf(), contents, zone, &dnssec_refresh);
if (result != KNOT_EOK) {
if (result == KNOT_ESPACE) {
ret = zone_load_post(conf(), contents, zone, &dnssec_refresh);
if (ret != KNOT_EOK) {
if (ret == KNOT_ESPACE) {
log_zone_error(zone->name, "journal size is too small "
"to fit the changes");
} else {
log_zone_error(zone->name, "failed to store changes into "
"journal (%s)", knot_strerror(result));
"journal (%s)", knot_strerror(ret));
}
goto fail;
}
/* Check zone contents consistency. */
result = zone_load_check(conf(), contents);
if (result != KNOT_EOK) {
ret = zone_load_check(conf(), contents);
if (ret != KNOT_EOK) {
goto fail;
}
......@@ -392,7 +394,7 @@ int event_load(zone_t *zone)
fail:
zone_contents_deep_free(&contents);
return result;
return ret;
}
static int try_refresh(zone_t *zone, const conf_remote_t *master, void *ctx)
......
......@@ -24,10 +24,12 @@
#include "knot/updates/apply.h"
#include "libknot/libknot.h"
zone_contents_t *zone_load_contents(conf_t *conf, const knot_dname_t *zone_name)
int zone_load_contents(conf_t *conf, const knot_dname_t *zone_name,
zone_contents_t **contents)
{
assert(conf);
assert(zone_name);
assert(contents);
zloader_t zl;
char *zonefile = conf_zonefile(conf, zone_name);
......@@ -35,7 +37,7 @@ zone_contents_t *zone_load_contents(conf_t *conf, const knot_dname_t *zone_name)
int ret = zonefile_open(&zl, zonefile, zone_name, conf_bool(&val));
free(zonefile);
if (ret != KNOT_EOK) {
return NULL;
return ret;
}
/* Set the zone type (master/slave). If zone has no master set, we
......@@ -43,13 +45,13 @@ zone_contents_t *zone_load_contents(conf_t *conf, const knot_dname_t *zone_name)
*/
zl.creator->master = !zone_load_can_bootstrap(conf, zone_name);
zone_contents_t *zone_contents = zonefile_load(&zl);
*contents = zonefile_load(&zl);
zonefile_close(&zl);
if (zone_contents == NULL) {
return NULL;
if (*contents == NULL) {
return KNOT_ERROR;
}
return zone_contents;
return KNOT_EOK;
}
/*! \brief Check zone configuration constraints. */
......
......@@ -26,9 +26,11 @@
*
* \param conf
* \param zone_name
* \return new zone contents or NULL
* \param contents
* \return KNOT_EOK or an error
*/
zone_contents_t *zone_load_contents(conf_t *conf, const knot_dname_t *zone_name);
int zone_load_contents(conf_t *conf, const knot_dname_t *zone_name,
zone_contents_t **contents);
/*!
* \brief Check loaded zone contents validity.
......
......@@ -223,7 +223,14 @@ int zonefile_open(zloader_t *loader, const char *source,
zs_deinit(&loader->scanner);
free(origin_str);
free(zc);
return KNOT_ERROR;
switch (loader->scanner.error.code) {
case ZS_FILE_OPEN:
case ZS_FILE_INVALID:
return KNOT_EFILE;
default:
return KNOT_EOK;
}
}
free(origin_str);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment