Commit 43597a72 authored by Jan Včelák's avatar Jan Včelák 🚀
Browse files

timers: API change, allow returning of error code

parent a657a9da
......@@ -782,9 +782,9 @@ int conf_open(const char* path)
}
/* Open zone timers db. */
nconf->timers_db = open_timers_db(nconf->storage);
if (nconf->timers_db == NULL) {
log_warning("cannot open timers db");
ret = open_timers_db(nconf->storage, &nconf->timers_db);
if (ret != KNOT_EOK) {
log_warning("cannot open timers DB (%s)", knot_strerror(ret));
}
/* Replace current config. */
......@@ -810,7 +810,6 @@ int conf_open(const char* path)
/* Free old config. */
conf_free(oldconf);
}
return KNOT_EOK;
}
......
......@@ -118,23 +118,27 @@ static int read_timers(knot_txn_t *txn, const zone_t *zone, time_t *timers)
/* -------- API ------------------------------------------------------------- */
knot_namedb_t *open_timers_db(const char *storage)
int open_timers_db(const char *storage, knot_namedb_t **db_ptr)
{
#ifndef HAVE_LMDB
// No-op if we don't have lmdb, all other operations will no-op as well then
return NULL;
#else
if (!storage || !db_ptr) {
return KNOT_EINVAL;
}
const struct namedb_api *api = namedb_lmdb_api();
if (!api) {
return KNOT_EOK;
}
char *path = sprintf_alloc("%s/timers", storage);
if (!path) {
return NULL;
return KNOT_ENOMEM;
}
knot_namedb_t *db = namedb_lmdb_api()->init(path, NULL);
int ret = api->init(path, db_ptr, NULL);
free(path);
return db;
#endif
return ret;
}
void close_timers_db(knot_namedb_t *timer_db)
......
......@@ -23,11 +23,12 @@
/*!
* \brief Opens zone timers db. No-op without LMDB support.
*
* \param storage Path to storage directory.
* \param[in] storage Path to storage directory.
* \param[out] timer_db Created database.
*
* \return Created database.
* \return KNOT_E*
*/
knot_namedb_t *open_timers_db(const char *storage);
int open_timers_db(const char *storage, knot_namedb_t **timer_db);
/*!
* \brief Closes zone timers db.
......
......@@ -58,8 +58,9 @@ int main(int argc, char *argv[])
ret = knot_zonedb_insert(zone_db, zone_2);
assert(ret == KNOT_EOK);
knot_namedb_t *db = open_timers_db(dbid);
ok(db != NULL, "zone timers: create");
knot_namedb_t *db = NULL;
ret = open_timers_db(dbid, &db);
ok(ret == KNOT_EOK && db != NULL, "zone timers: create");
// Set up events in the future.
const time_t now = time(NULL);
......
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