lib.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2009, 2013, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1999-2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: lib.c,v 1.16 2009/09/02 23:48:02 tbox Exp $ */
00019 
00020 /*! \file */
00021 
00022 #include <config.h>
00023 
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 
00027 #include <isc/app.h>
00028 #include <isc/lib.h>
00029 #include <isc/mem.h>
00030 #include <isc/msgs.h>
00031 #include <isc/once.h>
00032 #include <isc/socket.h>
00033 #include <isc/task.h>
00034 #include <isc/timer.h>
00035 #include <isc/util.h>
00036 
00037 /***
00038  *** Globals
00039  ***/
00040 
00041 LIBISC_EXTERNAL_DATA isc_msgcat_t *             isc_msgcat = NULL;
00042 
00043 
00044 /***
00045  *** Private
00046  ***/
00047 
00048 static isc_once_t               msgcat_once = ISC_ONCE_INIT;
00049 
00050 /***
00051  *** Functions
00052  ***/
00053 
00054 static void
00055 open_msgcat(void) {
00056         isc_msgcat_open("libisc.cat", &isc_msgcat);
00057 }
00058 
00059 void
00060 isc_lib_initmsgcat(void) {
00061         isc_result_t result;
00062 
00063         /*!
00064          * Initialize the ISC library's message catalog, isc_msgcat, if it
00065          * has not already been initialized.
00066          */
00067 
00068         result = isc_once_do(&msgcat_once, open_msgcat);
00069         if (result != ISC_R_SUCCESS) {
00070                 /*
00071                  * Normally we'd use RUNTIME_CHECK() or FATAL_ERROR(), but
00072                  * we can't do that here, since they might call us!
00073                  * (Note that the catalog might be open anyway, so we might
00074                  * as well try to  provide an internationalized message.)
00075                  */
00076                 fprintf(stderr, "%s:%d: %s: isc_once_do() %s.\n",
00077                         __FILE__, __LINE__,
00078                         isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
00079                                        ISC_MSG_FATALERROR, "fatal error"),
00080                         isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
00081                                        ISC_MSG_FAILED, "failed"));
00082                 abort();
00083         }
00084 }
00085 
00086 static isc_once_t               register_once = ISC_ONCE_INIT;
00087 
00088 static void
00089 do_register(void) {
00090         isc_bind9 = ISC_FALSE;
00091 
00092         RUNTIME_CHECK(isc__mem_register() == ISC_R_SUCCESS);
00093         RUNTIME_CHECK(isc__app_register() == ISC_R_SUCCESS);
00094         RUNTIME_CHECK(isc__task_register() == ISC_R_SUCCESS);
00095         RUNTIME_CHECK(isc__socket_register() == ISC_R_SUCCESS);
00096         RUNTIME_CHECK(isc__timer_register() == ISC_R_SUCCESS);
00097 }
00098 
00099 void
00100 isc_lib_register(void) {
00101         RUNTIME_CHECK(isc_once_do(&register_once, do_register)
00102                       == ISC_R_SUCCESS);
00103 }

Generated on Tue Apr 28 17:41:04 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha