"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/dns/lib.c" (4 Sep 2020, 2274 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "lib.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 /*! \file */
   13 
   14 #include <stdbool.h>
   15 #include <stddef.h>
   16 
   17 #include <isc/hash.h>
   18 #include <isc/mem.h>
   19 #include <isc/mutex.h>
   20 #include <isc/once.h>
   21 #include <isc/refcount.h>
   22 #include <isc/util.h>
   23 
   24 #include <dns/db.h>
   25 #include <dns/ecdb.h>
   26 #include <dns/lib.h>
   27 #include <dns/result.h>
   28 
   29 #include <dst/dst.h>
   30 
   31 /***
   32  *** Globals
   33  ***/
   34 
   35 LIBDNS_EXTERNAL_DATA unsigned int dns_pps = 0U;
   36 
   37 /***
   38  *** Functions
   39  ***/
   40 
   41 static isc_once_t init_once = ISC_ONCE_INIT;
   42 static isc_mem_t *dns_g_mctx = NULL;
   43 static dns_dbimplementation_t *dbimp = NULL;
   44 static bool initialize_done = false;
   45 static isc_refcount_t references;
   46 
   47 static void
   48 initialize(void) {
   49     isc_result_t result;
   50 
   51     REQUIRE(!initialize_done);
   52 
   53     isc_refcount_init(&references, 0);
   54 
   55     isc_mem_create(&dns_g_mctx);
   56     dns_result_register();
   57     result = dns_ecdb_register(dns_g_mctx, &dbimp);
   58     if (result != ISC_R_SUCCESS) {
   59         goto cleanup_mctx;
   60     }
   61 
   62     result = dst_lib_init(dns_g_mctx, NULL);
   63     if (result != ISC_R_SUCCESS) {
   64         goto cleanup_db;
   65     }
   66 
   67     initialize_done = true;
   68     return;
   69 
   70 cleanup_db:
   71     if (dbimp != NULL) {
   72         dns_ecdb_unregister(&dbimp);
   73     }
   74 cleanup_mctx:
   75     if (dns_g_mctx != NULL) {
   76         isc_mem_detach(&dns_g_mctx);
   77     }
   78 }
   79 
   80 isc_result_t
   81 dns_lib_init(void) {
   82     isc_result_t result;
   83 
   84     /*
   85      * Since this routine is expected to be used by a normal application,
   86      * it should be better to return an error, instead of an emergency
   87      * abort, on any failure.
   88      */
   89     result = isc_once_do(&init_once, initialize);
   90     if (result != ISC_R_SUCCESS) {
   91         return (result);
   92     }
   93 
   94     if (!initialize_done) {
   95         return (ISC_R_FAILURE);
   96     }
   97 
   98     isc_refcount_increment0(&references);
   99 
  100     return (ISC_R_SUCCESS);
  101 }
  102 
  103 void
  104 dns_lib_shutdown(void) {
  105     if (isc_refcount_decrement(&references) == 1) {
  106         dst_lib_destroy();
  107 
  108         isc_refcount_destroy(&references);
  109 
  110         if (dbimp != NULL) {
  111             dns_ecdb_unregister(&dbimp);
  112         }
  113         if (dns_g_mctx != NULL) {
  114             isc_mem_detach(&dns_g_mctx);
  115         }
  116     }
  117 }