2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-23 10:39:16 +00:00

dns_result_t/isc_result_t unification

This commit is contained in:
Andreas Gustafsson 1999-12-22 17:37:31 +00:00
parent 143592a649
commit 9b0e18da3d
2 changed files with 74 additions and 77 deletions

View File

@ -15,7 +15,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
/* $Id: cache.c,v 1.5 1999/12/17 01:02:49 gson Exp $ */ /* $Id: cache.c,v 1.6 1999/12/22 17:37:31 gson Exp $ */
#include <config.h> #include <config.h>
#include <limits.h> #include <limits.h>
@ -98,7 +98,7 @@ struct dns_cache {
*** Functions *** Functions
***/ ***/
static dns_result_t static isc_result_t
cache_cleaner_init(dns_cache_t *cache, cache_cleaner_init(dns_cache_t *cache,
isc_taskmgr_t *taskmgr, isc_timermgr_t *timermgr, isc_taskmgr_t *taskmgr, isc_timermgr_t *timermgr,
cache_cleaner_t *cleaner); cache_cleaner_t *cleaner);
@ -112,14 +112,13 @@ incremental_cleaning_action(isc_task_t *task, isc_event_t *event);
static void static void
cleaner_shutdown_action(isc_task_t *task, isc_event_t *event); cleaner_shutdown_action(isc_task_t *task, isc_event_t *event);
dns_result_t isc_result_t
dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
isc_timermgr_t *timermgr, dns_rdataclass_t rdclass, isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
char *db_type, unsigned int db_argc, char **db_argv, char *db_type, unsigned int db_argc, char **db_argv,
dns_cache_t **cachep) dns_cache_t **cachep)
{ {
isc_result_t iresult; isc_result_t result;
dns_result_t dresult;
dns_cache_t *cache; dns_cache_t *cache;
REQUIRE(cachep != NULL); REQUIRE(cachep != NULL);
@ -131,12 +130,12 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
return (ISC_R_NOMEMORY); return (ISC_R_NOMEMORY);
cache->mctx = mctx; cache->mctx = mctx;
iresult = isc_mutex_init(&cache->lock); result = isc_mutex_init(&cache->lock);
if (iresult != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_mutex_init() failed: %s", "isc_mutex_init() failed: %s",
isc_result_totext(iresult)); dns_result_totext(result));
dresult = ISC_R_UNEXPECTED; result = ISC_R_UNEXPECTED;
goto fail; goto fail;
} }
@ -145,24 +144,24 @@ dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
cache->rdclass = rdclass; cache->rdclass = rdclass;
cache->db = NULL; cache->db = NULL;
dresult = dns_db_create(cache->mctx, db_type, dns_rootname, ISC_TRUE, result = dns_db_create(cache->mctx, db_type, dns_rootname, ISC_TRUE,
rdclass, db_argc, db_argv, &cache->db); rdclass, db_argc, db_argv, &cache->db);
if (dresult != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;
cache->filename = NULL; cache->filename = NULL;
cache->magic = CACHE_MAGIC; cache->magic = CACHE_MAGIC;
dresult = cache_cleaner_init(cache, taskmgr, timermgr, result = cache_cleaner_init(cache, taskmgr, timermgr,
&cache->cleaner); &cache->cleaner);
RUNTIME_CHECK(dresult == ISC_R_SUCCESS); RUNTIME_CHECK(result == ISC_R_SUCCESS);
*cachep = cache; *cachep = cache;
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
fail: fail:
isc_mem_put(cache->mctx, cache, sizeof *cache); isc_mem_put(cache->mctx, cache, sizeof *cache);
return (dresult); return (result);
} }
static void static void
@ -244,7 +243,7 @@ dns_cache_attachdb(dns_cache_t *cache, dns_db_t **dbp) {
#ifdef NOTYET #ifdef NOTYET
dns_result_t isc_result_t
dns_cache_setfilename(dns_cache_t *cahce, char *filename) /* ARGSUSED */ dns_cache_setfilename(dns_cache_t *cahce, char *filename) /* ARGSUSED */
{ {
char *newname = isc_mem_strdup(filename); char *newname = isc_mem_strdup(filename);
@ -258,19 +257,19 @@ dns_cache_setfilename(dns_cache_t *cahce, char *filename) /* ARGSUSED */
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
dns_result_t isc_result_t
dns_cache_load(dns_cache_t *cache) { dns_cache_load(dns_cache_t *cache) {
dns_result_t dresult; isc_result_t result;
if (cache->filename == NULL) if (cache->filename == NULL)
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
LOCK(&cache->filelock); LOCK(&cache->filelock);
/* XXX handle TTLs in a way appropriate for the cache */ /* XXX handle TTLs in a way appropriate for the cache */
dresult = dns_db_load(cache->db, cache->filename); result = dns_db_load(cache->db, cache->filename);
UNLOCK(&cache->filelock); UNLOCK(&cache->filelock);
return (dresult); return (result);
} }
dns_result_t isc_result_t
dns_cache_dump(dns_cache_t *cache) { dns_cache_dump(dns_cache_t *cache) {
/* XXX to be written */ /* XXX to be written */
return (ISC_R_NOTIMPLEMENTED); return (ISC_R_NOTIMPLEMENTED);
@ -299,21 +298,20 @@ dns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int t) {
* Space for the object must be allocated by the caller. * Space for the object must be allocated by the caller.
*/ */
static dns_result_t static isc_result_t
cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr, cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
isc_timermgr_t *timermgr, cache_cleaner_t *cleaner) isc_timermgr_t *timermgr, cache_cleaner_t *cleaner)
{ {
isc_result_t iresult; isc_result_t result;
dns_result_t dresult;
cleaner->increment = 100; cleaner->increment = 100;
cleaner->state = cleaner_s_idle; cleaner->state = cleaner_s_idle;
cleaner->cache = cache; cleaner->cache = cache;
cleaner->iterator = NULL; cleaner->iterator = NULL;
dresult = dns_db_createiterator(cache->db, result = dns_db_createiterator(cache->db,
ISC_FALSE, &cleaner->iterator); ISC_FALSE, &cleaner->iterator);
if (dresult != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;
cleaner->task = NULL; cleaner->task = NULL;
@ -321,32 +319,32 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
cleaner->resched_event = NULL; cleaner->resched_event = NULL;
if (taskmgr != NULL && timermgr != NULL) { if (taskmgr != NULL && timermgr != NULL) {
iresult = isc_task_create(taskmgr, cache->mctx, result = isc_task_create(taskmgr, cache->mctx,
1, &cleaner->task); 1, &cleaner->task);
if (iresult != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_task_create() failed: %s", "isc_task_create() failed: %s",
isc_result_totext(iresult)); dns_result_totext(result));
dresult = ISC_R_UNEXPECTED; result = ISC_R_UNEXPECTED;
goto cleanup_dbiterator; goto cleanup_dbiterator;
} }
cleaner->cache->live_tasks++; cleaner->cache->live_tasks++;
iresult = isc_task_onshutdown(cleaner->task, result = isc_task_onshutdown(cleaner->task,
cleaner_shutdown_action, cache); cleaner_shutdown_action, cache);
RUNTIME_CHECK(iresult == ISC_R_SUCCESS); RUNTIME_CHECK(result == ISC_R_SUCCESS);
cleaner->cleaning_interval = 0; /* Initially turned off. */ cleaner->cleaning_interval = 0; /* Initially turned off. */
iresult = isc_timer_create(timermgr, isc_timertype_inactive, result = isc_timer_create(timermgr, isc_timertype_inactive,
NULL, NULL, NULL, NULL,
cleaner->task, cleaner->task,
cleaning_timer_action, cleaner, cleaning_timer_action, cleaner,
&cleaner->cleaning_timer); &cleaner->cleaning_timer);
if (iresult != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_timer_create() failed: %s", "isc_timer_create() failed: %s",
isc_result_totext(iresult)); dns_result_totext(result));
dresult = ISC_R_UNEXPECTED; result = ISC_R_UNEXPECTED;
goto cleanup_task; goto cleanup_task;
} }
@ -356,7 +354,7 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
incremental_cleaning_action, incremental_cleaning_action,
cleaner, sizeof(isc_event_t)); cleaner, sizeof(isc_event_t));
if (cleaner->resched_event == NULL) { if (cleaner->resched_event == NULL) {
dresult = ISC_R_NOMEMORY; result = ISC_R_NOMEMORY;
goto cleanup_timer; goto cleanup_timer;
} }
} }
@ -370,16 +368,15 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
cleanup_dbiterator: cleanup_dbiterator:
dns_dbiterator_destroy(&cleaner->iterator); dns_dbiterator_destroy(&cleaner->iterator);
fail: fail:
return (dresult); return (result);
} }
/* /*
* Try to clean the next n_names domain names. * Try to clean the next n_names domain names.
*/ */
static dns_result_t static isc_result_t
do_some_cleaning(cache_cleaner_t *cleaner, isc_stdtime_t now, int n_names) { do_some_cleaning(cache_cleaner_t *cleaner, isc_stdtime_t now, int n_names) {
dns_result_t dresult; isc_result_t result, return_result;
dns_result_t return_result;
REQUIRE(DNS_DBITERATOR_VALID(cleaner->iterator)); REQUIRE(DNS_DBITERATOR_VALID(cleaner->iterator));
@ -391,18 +388,18 @@ do_some_cleaning(cache_cleaner_t *cleaner, isc_stdtime_t now, int n_names) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_CACHE, ISC_LOG_DEBUG(1), DNS_LOGMODULE_CACHE, ISC_LOG_DEBUG(1),
"begin cache cleaning"); "begin cache cleaning");
dresult = dns_dbiterator_first(cleaner->iterator); result = dns_dbiterator_first(cleaner->iterator);
if (dresult == ISC_R_NOMORE) { if (result == ISC_R_NOMORE) {
/* /*
* We have an empty database, but that's OK. * We have an empty database, but that's OK.
*/ */
return_result = ISC_R_SUCCESS; return_result = ISC_R_SUCCESS;
goto idle; goto idle;
} }
if (dresult != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
"cache cleaner: dns_dbiterator_first() " "cache cleaner: dns_dbiterator_first() "
"failed: %s", dns_result_totext(dresult)); "failed: %s", dns_result_totext(result));
return_result = ISC_R_UNEXPECTED; return_result = ISC_R_UNEXPECTED;
goto idle; goto idle;
} }
@ -411,35 +408,35 @@ do_some_cleaning(cache_cleaner_t *cleaner, isc_stdtime_t now, int n_names) {
while (n_names-- > 0) { while (n_names-- > 0) {
dns_dbnode_t *node = NULL; dns_dbnode_t *node = NULL;
dresult = dns_dbiterator_current(cleaner->iterator, &node, result = dns_dbiterator_current(cleaner->iterator, &node,
(dns_name_t *) NULL); (dns_name_t *) NULL);
if (dresult != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
"cache cleaner: dns_dbiterator_current() " "cache cleaner: dns_dbiterator_current() "
"failed: %s", dns_result_totext(dresult)); "failed: %s", dns_result_totext(result));
return_result = ISC_R_UNEXPECTED; return_result = ISC_R_UNEXPECTED;
goto idle; goto idle;
} }
INSIST(node != NULL); INSIST(node != NULL);
/* Check TTLs, mark expired rdatasets stale. */ /* Check TTLs, mark expired rdatasets stale. */
dresult = dns_db_expirenode(cleaner->cache->db, node, now); result = dns_db_expirenode(cleaner->cache->db, node, now);
RUNTIME_CHECK(dresult == ISC_R_SUCCESS); RUNTIME_CHECK(result == ISC_R_SUCCESS);
/* This is where the actual freeing takes place. */ /* This is where the actual freeing takes place. */
dns_db_detachnode(cleaner->cache->db, &node); dns_db_detachnode(cleaner->cache->db, &node);
/* Step to the next node */ /* Step to the next node */
dresult = dns_dbiterator_next(cleaner->iterator); result = dns_dbiterator_next(cleaner->iterator);
if (dresult == ISC_R_NOMORE) { if (result == ISC_R_NOMORE) {
/* We have successfully cleaned the whole cache. */ /* We have successfully cleaned the whole cache. */
return_result = ISC_R_SUCCESS; return_result = ISC_R_SUCCESS;
goto idle; goto idle;
} }
if (dresult != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
"cache cleaner: dns_dbiterator_next() " "cache cleaner: dns_dbiterator_next() "
"failed: %s", dns_result_totext(dresult)); "failed: %s", dns_result_totext(result));
return_result = ISC_R_UNEXPECTED; return_result = ISC_R_UNEXPECTED;
goto idle; goto idle;
} }
@ -456,11 +453,11 @@ do_some_cleaning(cache_cleaner_t *cleaner, isc_stdtime_t now, int n_names) {
cleaner->state = cleaner_s_idle; cleaner->state = cleaner_s_idle;
done: done:
dresult = dns_dbiterator_pause(cleaner->iterator); result = dns_dbiterator_pause(cleaner->iterator);
if (dresult != ISC_R_SUCCESS && dresult != ISC_R_NOMORE) { if (result != ISC_R_SUCCESS && result != ISC_R_NOMORE) {
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
"cache cleaner: dns_dbiterator_pause() " "cache cleaner: dns_dbiterator_pause() "
"failed: %s", dns_result_totext(dresult)); "failed: %s", dns_result_totext(result));
return (ISC_R_UNEXPECTED); return (ISC_R_UNEXPECTED);
} }
return (return_result); return (return_result);
@ -514,40 +511,40 @@ incremental_cleaning_action(isc_task_t *task, isc_event_t *event) {
/* /*
* Do immediate cleaning. * Do immediate cleaning.
*/ */
dns_result_t isc_result_t
dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now) { dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now) {
dns_result_t dresult; isc_result_t result;
dns_dbiterator_t *iterator = NULL; dns_dbiterator_t *iterator = NULL;
dresult = dns_db_createiterator(cache->db, ISC_FALSE, &iterator); result = dns_db_createiterator(cache->db, ISC_FALSE, &iterator);
if (dresult != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return dresult; return result;
dresult = dns_dbiterator_first(iterator); result = dns_dbiterator_first(iterator);
while (dresult == ISC_R_SUCCESS) { while (result == ISC_R_SUCCESS) {
dns_dbnode_t *node = NULL; dns_dbnode_t *node = NULL;
dresult = dns_dbiterator_current(iterator, &node, result = dns_dbiterator_current(iterator, &node,
(dns_name_t *) NULL); (dns_name_t *) NULL);
if (dresult != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
break; break;
/* Check TTLs, mark expired rdatasets stale. */ /* Check TTLs, mark expired rdatasets stale. */
dresult = dns_db_expirenode(cache->db, node, now); result = dns_db_expirenode(cache->db, node, now);
RUNTIME_CHECK(dresult == ISC_R_SUCCESS); RUNTIME_CHECK(result == ISC_R_SUCCESS);
/* This is where the actual freeing takes place. */ /* This is where the actual freeing takes place. */
dns_db_detachnode(cache->db, &node); dns_db_detachnode(cache->db, &node);
dresult = dns_dbiterator_next(iterator); result = dns_dbiterator_next(iterator);
} }
dns_dbiterator_destroy(&iterator); dns_dbiterator_destroy(&iterator);
if (dresult == ISC_R_NOMORE) if (result == ISC_R_NOMORE)
dresult = ISC_R_SUCCESS; result = ISC_R_SUCCESS;
return dresult; return result;
} }
/* /*

View File

@ -63,7 +63,7 @@ ISC_LANG_BEGINDECLS
*** Functions *** Functions
***/ ***/
dns_result_t isc_result_t
dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
isc_timermgr_t *timermgr, dns_rdataclass_t rdclass, isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
char *db_type, unsigned int db_argc, char **db_argv, char *db_type, unsigned int db_argc, char **db_argv,
@ -152,7 +152,7 @@ dns_cache_attachdb(dns_cache_t *cache, dns_db_t **dbp);
*/ */
dns_result_t isc_result_t
dns_cache_setfilename(dns_cache_t *cahce, char *filename); dns_cache_setfilename(dns_cache_t *cahce, char *filename);
/* /*
* If 'filename' is non-NULL, make the cache persistent. * If 'filename' is non-NULL, make the cache persistent.
@ -166,7 +166,7 @@ dns_cache_setfilename(dns_cache_t *cahce, char *filename);
* Various file-related failures * Various file-related failures
*/ */
dns_result_t isc_result_t
dns_cache_load(dns_cache_t *cache); dns_cache_load(dns_cache_t *cache);
/* /*
* If the cache has a file name, load the cache contents from the file. * If the cache has a file name, load the cache contents from the file.
@ -187,7 +187,7 @@ dns_cache_load(dns_cache_t *cache);
* Various failures depending on the database implementation type * Various failures depending on the database implementation type
*/ */
dns_result_t isc_result_t
dns_cache_dump(dns_cache_t *cache); dns_cache_dump(dns_cache_t *cache);
/* /*
* If the cache has a file name, write the cache contents to disk, * If the cache has a file name, write the cache contents to disk,
@ -207,7 +207,7 @@ dns_cache_dump(dns_cache_t *cache);
* Various failures depending on the database implementation type * Various failures depending on the database implementation type
*/ */
dns_result_t isc_result_t
dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now); dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now);
/* /*
* Force immediate cleaning of the cache, freeing all rdatasets * Force immediate cleaning of the cache, freeing all rdatasets