Home | History | Annotate | Line # | Download | only in isc
lib.c revision 1.1
      1 /*	$NetBSD: lib.c,v 1.1 2018/08/12 12:08:23 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5  *
      6  * This Source Code Form is subject to the terms of the Mozilla Public
      7  * License, v. 2.0. If a copy of the MPL was not distributed with this
      8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
      9  *
     10  * See the COPYRIGHT file distributed with this work for additional
     11  * information regarding copyright ownership.
     12  */
     13 
     14 
     15 /*! \file */
     16 
     17 #include <config.h>
     18 
     19 #include <stdio.h>
     20 #include <stdlib.h>
     21 
     22 #include <isc/app.h>
     23 #include <isc/lib.h>
     24 #include <isc/mem.h>
     25 #include <isc/msgs.h>
     26 #include <isc/once.h>
     27 #include <isc/print.h>
     28 #include <isc/socket.h>
     29 #include <isc/task.h>
     30 #include <isc/timer.h>
     31 #include <isc/util.h>
     32 
     33 /***
     34  *** Globals
     35  ***/
     36 
     37 LIBISC_EXTERNAL_DATA isc_msgcat_t *		isc_msgcat = NULL;
     38 
     39 
     40 /***
     41  *** Private
     42  ***/
     43 
     44 static isc_once_t		msgcat_once = ISC_ONCE_INIT;
     45 
     46 /***
     47  *** Functions
     48  ***/
     49 
     50 static void
     51 open_msgcat(void) {
     52 	isc_msgcat_open("libisc.cat", &isc_msgcat);
     53 }
     54 
     55 void
     56 isc_lib_initmsgcat(void) {
     57 	isc_result_t result;
     58 
     59 	/*!
     60 	 * Initialize the ISC library's message catalog, isc_msgcat, if it
     61 	 * has not already been initialized.
     62 	 */
     63 
     64 	result = isc_once_do(&msgcat_once, open_msgcat);
     65 	if (result != ISC_R_SUCCESS) {
     66 		/*
     67 		 * Normally we'd use RUNTIME_CHECK() or FATAL_ERROR(), but
     68 		 * we can't do that here, since they might call us!
     69 		 * (Note that the catalog might be open anyway, so we might
     70 		 * as well try to  provide an internationalized message.)
     71 		 */
     72 		fprintf(stderr, "%s:%d: %s: isc_once_do() %s.\n",
     73 			__FILE__, __LINE__,
     74 			isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
     75 				       ISC_MSG_FATALERROR, "fatal error"),
     76 			isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
     77 				       ISC_MSG_FAILED, "failed"));
     78 		abort();
     79 	}
     80 }
     81 
     82 static isc_once_t		register_once = ISC_ONCE_INIT;
     83 
     84 static void
     85 do_register(void) {
     86 	isc_bind9 = ISC_FALSE;
     87 
     88 	RUNTIME_CHECK(isc__mem_register() == ISC_R_SUCCESS);
     89 	RUNTIME_CHECK(isc__app_register() == ISC_R_SUCCESS);
     90 	RUNTIME_CHECK(isc__task_register() == ISC_R_SUCCESS);
     91 	RUNTIME_CHECK(isc__socket_register() == ISC_R_SUCCESS);
     92 	RUNTIME_CHECK(isc__timer_register() == ISC_R_SUCCESS);
     93 }
     94 
     95 void
     96 isc_lib_register(void) {
     97 	RUNTIME_CHECK(isc_once_do(&register_once, do_register)
     98 		      == ISC_R_SUCCESS);
     99 }
    100