2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-02 15:45:25 +00:00

[master] add libns and remove liblwres

4708.   [cleanup]       Legacy Windows builds (i.e. for XP and earlier)
                        are no longer supported. [RT #45186]

4707.	[func]		The lightweight resolver daemon and library (lwresd
			and liblwres) have been removed. [RT #45186]

4706.	[func]		Code implementing name server query processing has
			been moved from bin/named to a new library "libns".
			Functions remaining in bin/named are now prefixed
			with "named_" rather than "ns_".  This will make it
			easier to write unit tests for name server code, or
			link name server functionality into new tools.
			[RT #45186]
This commit is contained in:
Evan Hunt
2017-09-08 13:39:09 -07:00
parent 60387eb495
commit 8eb88aafee
567 changed files with 7123 additions and 85013 deletions

102
lib/ns/lib.c Normal file
View File

@@ -0,0 +1,102 @@
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <stddef.h>
#include <isc/mem.h>
#include <isc/msgcat.h>
#include <isc/mutex.h>
#include <isc/once.h>
#include <isc/util.h>
#include <dns/name.h>
#include <ns/lib.h>
/***
*** Globals
***/
LIBNS_EXTERNAL_DATA unsigned int ns_pps = 0U;
/***
*** Private
***/
static isc_once_t init_once = ISC_ONCE_INIT;
static isc_mem_t *ns_g_mctx = NULL;
static isc_boolean_t initialize_done = ISC_FALSE;
static isc_mutex_t reflock;
static unsigned int references = 0;
static void
initialize(void) {
isc_result_t result;
REQUIRE(initialize_done == ISC_FALSE);
result = isc_mem_create(0, 0, &ns_g_mctx);
if (result != ISC_R_SUCCESS)
return;
result = isc_mutex_init(&reflock);
if (result != ISC_R_SUCCESS)
goto cleanup_mctx;
initialize_done = ISC_TRUE;
return;
cleanup_mctx:
if (ns_g_mctx != NULL)
isc_mem_detach(&ns_g_mctx);
}
isc_result_t
ns_lib_init(void) {
isc_result_t result;
/*
* Since this routine is expected to be used by a normal application,
* it should be better to return an error, instead of an emergency
* abort, on any failure.
*/
result = isc_once_do(&init_once, initialize);
if (result != ISC_R_SUCCESS)
return (result);
if (!initialize_done)
return (ISC_R_FAILURE);
LOCK(&reflock);
references++;
UNLOCK(&reflock);
return (ISC_R_SUCCESS);
}
void
ns_lib_shutdown(void) {
isc_boolean_t cleanup_ok = ISC_FALSE;
LOCK(&reflock);
if (--references == 0)
cleanup_ok = ISC_TRUE;
UNLOCK(&reflock);
if (!cleanup_ok)
return;
if (ns_g_mctx != NULL)
isc_mem_detach(&ns_g_mctx);
}