1*a466cc55SCy Schubert /*
2*a466cc55SCy Schubert * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
3*a466cc55SCy Schubert * Copyright (C) 1999-2001 Internet Software Consortium.
4*a466cc55SCy Schubert *
5*a466cc55SCy Schubert * Permission to use, copy, modify, and/or distribute this software for any
6*a466cc55SCy Schubert * purpose with or without fee is hereby granted, provided that the above
7*a466cc55SCy Schubert * copyright notice and this permission notice appear in all copies.
8*a466cc55SCy Schubert *
9*a466cc55SCy Schubert * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10*a466cc55SCy Schubert * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11*a466cc55SCy Schubert * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12*a466cc55SCy Schubert * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13*a466cc55SCy Schubert * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14*a466cc55SCy Schubert * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15*a466cc55SCy Schubert * PERFORMANCE OF THIS SOFTWARE.
16*a466cc55SCy Schubert */
17*a466cc55SCy Schubert
18*a466cc55SCy Schubert /* $Id: lib.c,v 1.16 2009/09/02 23:48:02 tbox Exp $ */
19*a466cc55SCy Schubert
20*a466cc55SCy Schubert /*! \file */
21*a466cc55SCy Schubert
22*a466cc55SCy Schubert #include <config.h>
23*a466cc55SCy Schubert
24*a466cc55SCy Schubert #include <stdio.h>
25*a466cc55SCy Schubert #include <stdlib.h>
26*a466cc55SCy Schubert
27*a466cc55SCy Schubert #include <isc/app.h>
28*a466cc55SCy Schubert #include <isc/lib.h>
29*a466cc55SCy Schubert #include <isc/mem.h>
30*a466cc55SCy Schubert #include <isc/msgs.h>
31*a466cc55SCy Schubert #include <isc/once.h>
32*a466cc55SCy Schubert #include <isc/socket.h>
33*a466cc55SCy Schubert #include <isc/task.h>
34*a466cc55SCy Schubert #include <isc/timer.h>
35*a466cc55SCy Schubert #include <isc/util.h>
36*a466cc55SCy Schubert
37*a466cc55SCy Schubert /***
38*a466cc55SCy Schubert *** Globals
39*a466cc55SCy Schubert ***/
40*a466cc55SCy Schubert
41*a466cc55SCy Schubert LIBISC_EXTERNAL_DATA isc_msgcat_t * isc_msgcat = NULL;
42*a466cc55SCy Schubert
43*a466cc55SCy Schubert
44*a466cc55SCy Schubert /***
45*a466cc55SCy Schubert *** Private
46*a466cc55SCy Schubert ***/
47*a466cc55SCy Schubert
48*a466cc55SCy Schubert static isc_once_t msgcat_once = ISC_ONCE_INIT;
49*a466cc55SCy Schubert
50*a466cc55SCy Schubert /***
51*a466cc55SCy Schubert *** Functions
52*a466cc55SCy Schubert ***/
53*a466cc55SCy Schubert
54*a466cc55SCy Schubert static void
open_msgcat(void)55*a466cc55SCy Schubert open_msgcat(void) {
56*a466cc55SCy Schubert isc_msgcat_open("libisc.cat", &isc_msgcat);
57*a466cc55SCy Schubert }
58*a466cc55SCy Schubert
59*a466cc55SCy Schubert void
isc_lib_initmsgcat(void)60*a466cc55SCy Schubert isc_lib_initmsgcat(void) {
61*a466cc55SCy Schubert isc_result_t result;
62*a466cc55SCy Schubert
63*a466cc55SCy Schubert /*!
64*a466cc55SCy Schubert * Initialize the ISC library's message catalog, isc_msgcat, if it
65*a466cc55SCy Schubert * has not already been initialized.
66*a466cc55SCy Schubert */
67*a466cc55SCy Schubert
68*a466cc55SCy Schubert result = isc_once_do(&msgcat_once, open_msgcat);
69*a466cc55SCy Schubert if (result != ISC_R_SUCCESS) {
70*a466cc55SCy Schubert /*
71*a466cc55SCy Schubert * Normally we'd use RUNTIME_CHECK() or FATAL_ERROR(), but
72*a466cc55SCy Schubert * we can't do that here, since they might call us!
73*a466cc55SCy Schubert * (Note that the catalog might be open anyway, so we might
74*a466cc55SCy Schubert * as well try to provide an internationalized message.)
75*a466cc55SCy Schubert */
76*a466cc55SCy Schubert fprintf(stderr, "%s:%d: %s: isc_once_do() %s.\n",
77*a466cc55SCy Schubert __FILE__, __LINE__,
78*a466cc55SCy Schubert isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
79*a466cc55SCy Schubert ISC_MSG_FATALERROR, "fatal error"),
80*a466cc55SCy Schubert isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
81*a466cc55SCy Schubert ISC_MSG_FAILED, "failed"));
82*a466cc55SCy Schubert abort();
83*a466cc55SCy Schubert }
84*a466cc55SCy Schubert }
85*a466cc55SCy Schubert
86*a466cc55SCy Schubert #ifndef BIND9
87*a466cc55SCy Schubert static isc_once_t register_once = ISC_ONCE_INIT;
88*a466cc55SCy Schubert
89*a466cc55SCy Schubert static void
do_register(void)90*a466cc55SCy Schubert do_register(void) {
91*a466cc55SCy Schubert RUNTIME_CHECK(isc__mem_register() == ISC_R_SUCCESS);
92*a466cc55SCy Schubert RUNTIME_CHECK(isc__app_register() == ISC_R_SUCCESS);
93*a466cc55SCy Schubert RUNTIME_CHECK(isc__task_register() == ISC_R_SUCCESS);
94*a466cc55SCy Schubert RUNTIME_CHECK(isc__socket_register() == ISC_R_SUCCESS);
95*a466cc55SCy Schubert RUNTIME_CHECK(isc__timer_register() == ISC_R_SUCCESS);
96*a466cc55SCy Schubert }
97*a466cc55SCy Schubert
98*a466cc55SCy Schubert void
isc_lib_register()99*a466cc55SCy Schubert isc_lib_register() {
100*a466cc55SCy Schubert RUNTIME_CHECK(isc_once_do(®ister_once, do_register)
101*a466cc55SCy Schubert == ISC_R_SUCCESS);
102*a466cc55SCy Schubert }
103*a466cc55SCy Schubert #endif
104