Commit 8f79820c authored by Andreas Gustafsson's avatar Andreas Gustafsson
Browse files

wired up the 'cleaning-interval' config option

parent 59602a44
......@@ -75,13 +75,13 @@ static isc_task_t * server_task;
static isc_result_t
create_default_view(isc_mem_t *mctx, dns_rdataclass_t rdclass,
dns_view_t **viewp)
create_default_view(dns_c_ctx_t *cctx, isc_mem_t *mctx,
dns_rdataclass_t rdclass, dns_view_t **viewp)
{
dns_view_t *view;
dns_cache_t *cache;
isc_result_t result;
isc_int32_t cleaning_interval;
REQUIRE(viewp != NULL && *viewp == NULL);
......@@ -102,6 +102,9 @@ create_default_view(isc_mem_t *mctx, dns_rdataclass_t rdclass,
if (result != ISC_R_SUCCESS)
goto cleanup;
dns_view_setcache(view, cache);
cleaning_interval = 3600; /* Default is 1 hour. */
(void) dns_c_ctx_getcleaninterval(cctx, &cleaning_interval);
dns_cache_setcleaninginterval(cache, cleaning_interval);
dns_cache_detach(&cache);
/*
......@@ -282,7 +285,7 @@ load_zone(dns_c_ctx_t *ctx, dns_c_zone_t *czone, dns_c_view_t *cview,
* Create a default view.
*/
tview = NULL;
result = create_default_view(ctx->mem, czone->zclass,
result = create_default_view(ctx, ns_g_mctx, czone->zclass,
&tview);
if (result != ISC_R_SUCCESS)
return (result);
......@@ -398,7 +401,7 @@ load_configuration(const char *filename, ns_server_t *server) {
isc_result_t result;
ns_load_t lctx;
dns_c_cbks_t callbacks;
dns_c_ctx_t *configctx, *oconfigctx;
dns_c_ctx_t *configctx;
dns_view_t *view, *view_next;
dns_viewlist_t oviewlist;
dns_aclconfctx_t aclconfctx;
......@@ -456,8 +459,8 @@ load_configuration(const char *filename, ns_server_t *server) {
*/
if (ISC_LIST_EMPTY(lctx.viewlist)) {
view = NULL;
result = create_default_view(ns_g_mctx, dns_rdataclass_in,
&view);
result = create_default_view(configctx, ns_g_mctx,
dns_rdataclass_in, &view);
if (result != ISC_R_SUCCESS)
ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
"could not create default view");
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: cache.c,v 1.4 1999/12/16 23:29:04 explorer Exp $ */
/* $Id: cache.c,v 1.5 1999/12/17 01:02:49 gson Exp $ */
#include <config.h>
#include <limits.h>
......@@ -59,7 +59,7 @@ typedef enum {
struct cache_cleaner {
dns_cache_t *cache;
isc_task_t *task;
int cleaning_interval; /* The cleaning-interval from
unsigned int cleaning_interval; /* The cleaning-interval from
named.conf, in seconds. */
isc_timer_t *cleaning_timer;
isc_event_t *resched_event; /* Sent by cleaner task to
......@@ -278,6 +278,22 @@ dns_cache_dump(dns_cache_t *cache) {
#endif
void
dns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int t) {
LOCK(&cache->lock);
cache->cleaner.cleaning_interval = t;
if (t == 0) {
isc_timer_reset(cache->cleaner.cleaning_timer, isc_timertype_inactive,
NULL, NULL, ISC_TRUE);
} else {
isc_interval_t interval;
isc_interval_set(&interval, cache->cleaner.cleaning_interval, 0);
isc_timer_reset(cache->cleaner.cleaning_timer, isc_timertype_ticker,
NULL, &interval, ISC_FALSE);
}
UNLOCK(&cache->lock);
}
/*
* Initialize the cache cleaner object at *cleaner.
* Space for the object must be allocated by the caller.
......@@ -290,7 +306,7 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
isc_result_t iresult;
dns_result_t dresult;
cleaner->increment = 10; /* XXX debugging value; 100 realistic? */
cleaner->increment = 100;
cleaner->state = cleaner_s_idle;
cleaner->cache = cache;
......@@ -305,8 +321,6 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
cleaner->resched_event = NULL;
if (taskmgr != NULL && timermgr != NULL) {
isc_interval_t interval;
iresult = isc_task_create(taskmgr, cache->mctx,
1, &cleaner->task);
if (iresult != ISC_R_SUCCESS) {
......@@ -322,11 +336,9 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
cleaner_shutdown_action, cache);
RUNTIME_CHECK(iresult == ISC_R_SUCCESS);
/* XXX get this from the configuration file */
cleaner->cleaning_interval = 2 * 3600; /* seconds */
isc_interval_set(&interval, cleaner->cleaning_interval, 0);
iresult = isc_timer_create(timermgr, isc_timertype_ticker,
NULL, &interval,
cleaner->cleaning_interval = 0; /* Initially turned off. */
iresult = isc_timer_create(timermgr, isc_timertype_inactive,
NULL, NULL,
cleaner->task,
cleaning_timer_action, cleaner,
&cleaner->cleaning_timer);
......
......@@ -215,6 +215,12 @@ dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now);
* references.
*/
void
dns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int interval);
/*
* Set the periodic cache cleaning interval to 'interval' seconds.
*/
ISC_LANG_ENDDECLS
#endif /* DNS_CACHE_H */
......
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