2017-09-08 16:39:09 -04:00
|
|
|
/*
|
2018-02-23 03:53:12 -05:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2017-09-08 16:39:09 -04:00
|
|
|
*
|
|
|
|
|
* 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
|
2020-09-14 19:50:58 -04:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 03:53:12 -05:00
|
|
|
*
|
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
|
* information regarding copyright ownership.
|
2017-09-08 16:39:09 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*! \file */
|
|
|
|
|
|
2018-04-17 11:29:14 -04:00
|
|
|
#include <stdbool.h>
|
2017-09-08 16:39:09 -04:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
|
|
#include <isc/mem.h>
|
|
|
|
|
#include <isc/mutex.h>
|
|
|
|
|
#include <isc/once.h>
|
2019-05-17 07:25:48 -04:00
|
|
|
#include <isc/refcount.h>
|
2017-09-08 16:39:09 -04:00
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
|
|
|
|
#include <dns/name.h>
|
|
|
|
|
|
|
|
|
|
#include <ns/lib.h>
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Globals
|
|
|
|
|
***/
|
|
|
|
|
|
2020-02-12 09:33:32 -05:00
|
|
|
LIBNS_EXTERNAL_DATA unsigned int ns_pps = 0U;
|
2017-09-08 16:39:09 -04:00
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Private
|
|
|
|
|
***/
|
|
|
|
|
|
2020-02-14 00:35:17 -05:00
|
|
|
static isc_once_t init_once = ISC_ONCE_INIT;
|
|
|
|
|
static isc_mem_t *ns_g_mctx = NULL;
|
|
|
|
|
static bool initialize_done = false;
|
2019-05-17 07:25:48 -04:00
|
|
|
static isc_refcount_t references;
|
2017-09-08 16:39:09 -04:00
|
|
|
|
|
|
|
|
static void
|
2020-02-14 00:35:17 -05:00
|
|
|
initialize(void) {
|
2020-03-30 16:49:55 -04:00
|
|
|
REQUIRE(!initialize_done);
|
2017-09-08 16:39:09 -04:00
|
|
|
|
2019-09-05 12:40:57 -04:00
|
|
|
isc_mem_create(&ns_g_mctx);
|
2017-09-08 16:39:09 -04:00
|
|
|
|
2019-05-17 07:25:48 -04:00
|
|
|
isc_refcount_init(&references, 0);
|
2018-04-17 11:29:14 -04:00
|
|
|
initialize_done = true;
|
2017-09-08 16:39:09 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isc_result_t
|
2020-02-14 00:35:17 -05:00
|
|
|
ns_lib_init(void) {
|
2017-09-08 16:39:09 -04:00
|
|
|
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);
|
2020-02-13 16:28:07 -05:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2017-09-08 16:39:09 -04:00
|
|
|
return (result);
|
2020-02-13 16:28:07 -05:00
|
|
|
}
|
2017-09-08 16:39:09 -04:00
|
|
|
|
2020-02-13 16:28:07 -05:00
|
|
|
if (!initialize_done) {
|
2017-09-08 16:39:09 -04:00
|
|
|
return (ISC_R_FAILURE);
|
2020-02-13 16:28:07 -05:00
|
|
|
}
|
2017-09-08 16:39:09 -04:00
|
|
|
|
2019-07-23 10:24:50 -04:00
|
|
|
isc_refcount_increment0(&references);
|
2017-09-08 16:39:09 -04:00
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2020-02-14 00:35:17 -05:00
|
|
|
ns_lib_shutdown(void) {
|
2019-05-17 07:25:48 -04:00
|
|
|
if (isc_refcount_decrement(&references) == 1) {
|
2019-07-23 08:27:30 -04:00
|
|
|
isc_refcount_destroy(&references);
|
2019-05-17 07:25:48 -04:00
|
|
|
if (ns_g_mctx != NULL) {
|
|
|
|
|
isc_mem_detach(&ns_g_mctx);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-08 16:39:09 -04:00
|
|
|
}
|