Commit 582732ce authored by Andreas Gustafsson's avatar Andreas Gustafsson
Browse files

war on global variables continues: ns_g_viewlist and

ns_g_viewlock are now gone
parent 9b0e18da
......@@ -615,8 +615,8 @@ client_request(isc_task_t *task, isc_event_t *event) {
* XXXRTH View list management code will be moving to its own module
* soon.
*/
RWLOCK(&ns_g_viewlock, isc_rwlocktype_read);
for (view = ISC_LIST_HEAD(ns_g_viewlist);
RWLOCK(&ns_g_server->viewlock, isc_rwlocktype_read);
for (view = ISC_LIST_HEAD(ns_g_server->viewlist);
view != NULL;
view = ISC_LIST_NEXT(view, link)) {
/*
......@@ -627,7 +627,7 @@ client_request(isc_task_t *task, isc_event_t *event) {
break;
}
}
RWUNLOCK(&ns_g_viewlock, isc_rwlocktype_read);
RWUNLOCK(&ns_g_server->viewlock, isc_rwlocktype_read);
if (view == NULL) {
CTRACE("no view");
......
......@@ -54,9 +54,6 @@ EXTERN char * ns_g_version INIT(VERSION);
EXTERN in_port_t ns_g_port INIT(53);
EXTERN dns_zonemgr_t * ns_g_zonemgr INIT(NULL);
EXTERN dns_viewlist_t ns_g_viewlist;
EXTERN isc_rwlock_t ns_g_viewlock;
EXTERN ns_server_t * ns_g_server INIT(NULL);
/*
......
......@@ -34,10 +34,13 @@ struct ns_server {
isc_boolean_t recursion;
isc_boolean_t auth_nxdomain;
dns_transfer_format_t transfer_format;
dns_acl_t * queryacl;
dns_acl_t * recursionacl;
dns_acl_t * transferacl;
/* Server data structures. */
dns_viewlist_t viewlist;
isc_rwlock_t viewlock;
};
#define NS_SERVER_MAGIC 0x53564552 /* SVER */
......
......@@ -260,12 +260,6 @@ setup() {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "starting BIND %s", ns_g_version);
ISC_LIST_INIT(ns_g_viewlist);
result = isc_rwlock_init(&ns_g_viewlock, 0, 0);
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("isc_rwlock_init() failed: %s",
isc_result_totext(result));
result = create_managers();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("create_managers() failed: %s",
......@@ -280,7 +274,6 @@ setup() {
static void
cleanup() {
destroy_managers();
isc_rwlock_destroy(&ns_g_viewlock);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "exiting");
ns_log_shutdown();
......
......@@ -298,10 +298,10 @@ load_zone(dns_c_ctx_t *ctx, dns_c_zone_t *czone, dns_c_view_t *cview,
/*
* Do we already have a production version of this view?
*/
RWLOCK(&ns_g_viewlock, isc_rwlocktype_read);
result = dns_viewlist_find(&ns_g_viewlist, view->name, view->rdclass,
RWLOCK(&ns_g_server->viewlock, isc_rwlocktype_read);
result = dns_viewlist_find(&ns_g_server->viewlist, view->name, view->rdclass,
&pview);
RWUNLOCK(&ns_g_viewlock, isc_rwlocktype_read);
RWUNLOCK(&ns_g_server->viewlock, isc_rwlocktype_read);
if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
goto cleanup;
......@@ -521,12 +521,12 @@ load_configuration(const char *filename, ns_server_t *server) {
* Put the configuration into production.
*/
RWLOCK(&ns_g_viewlock, isc_rwlocktype_write);
RWLOCK(&server->viewlock, isc_rwlocktype_write);
oviewlist = ns_g_viewlist;
ns_g_viewlist = lctx.viewlist;
oviewlist = server->viewlist;
server->viewlist = lctx.viewlist;
RWUNLOCK(&ns_g_viewlock, isc_rwlocktype_write);
RWUNLOCK(&server->viewlock, isc_rwlocktype_write);
/*
* Cleanup old configuration.
......@@ -591,20 +591,20 @@ shutdown_server(isc_task_t *task, isc_event_t *event) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_INFO, "shutting down");
RWLOCK(&ns_g_viewlock, isc_rwlocktype_write);
RWLOCK(&server->viewlock, isc_rwlocktype_write);
for (view = ISC_LIST_HEAD(ns_g_viewlist);
for (view = ISC_LIST_HEAD(server->viewlist);
view != NULL;
view = view_next) {
view_next = ISC_LIST_NEXT(view, link);
ISC_LIST_UNLINK(ns_g_viewlist, view, link);
ISC_LIST_UNLINK(server->viewlist, view, link);
dns_view_detach(&view);
}
dns_tkey_destroy();
dns_tsig_destroy();
RWUNLOCK(&ns_g_viewlock, isc_rwlocktype_write);
RWUNLOCK(&server->viewlock, isc_rwlocktype_write);
isc_task_detach(&server_task);
......@@ -619,12 +619,14 @@ shutdown_server(isc_task_t *task, isc_event_t *event) {
isc_result_t
ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
isc_result_t result;
ns_server_t *server = isc_mem_get(mctx, sizeof(*server));
if (server == NULL)
return (ISC_R_NOMEMORY);
server->mctx = mctx;
/* Initialize. */
/* Initialize configuration data with default values. */
server->recursion = ISC_TRUE;
server->auth_nxdomain = ISC_FALSE; /* Was true in BIND 8 */
server->transfer_format = dns_one_answer;
......@@ -633,6 +635,12 @@ ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
server->recursionacl = NULL;
server->transferacl = NULL;
/* Initialize server data structures. */
ISC_LIST_INIT(server->viewlist);
result = isc_rwlock_init(&server->viewlock, 0, 0);
if (result != ISC_R_SUCCESS)
return (result);
server->magic = NS_SERVER_MAGIC;
*serverp = server;
return (ISC_R_SUCCESS);
......@@ -643,6 +651,9 @@ ns_server_destroy(ns_server_t **serverp) {
ns_server_t *server = *serverp;
REQUIRE(NS_SERVER_VALID(server));
INSIST(ISC_LIST_EMPTY(server->viewlist));
isc_rwlock_destroy(&server->viewlock);
if (server->queryacl != NULL)
dns_acl_detach(&server->queryacl);
if (server->recursionacl != 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