1*eabc0478Schristos /* $NetBSD: lib.c,v 1.2 2024/08/18 20:47:14 christos Exp $ */ 2897be3a4Schristos 3897be3a4Schristos /* 4897be3a4Schristos * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC") 5897be3a4Schristos * Copyright (C) 1999-2001 Internet Software Consortium. 6897be3a4Schristos * 7897be3a4Schristos * Permission to use, copy, modify, and/or distribute this software for any 8897be3a4Schristos * purpose with or without fee is hereby granted, provided that the above 9897be3a4Schristos * copyright notice and this permission notice appear in all copies. 10897be3a4Schristos * 11897be3a4Schristos * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 12897be3a4Schristos * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 13897be3a4Schristos * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 14897be3a4Schristos * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15897be3a4Schristos * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 16897be3a4Schristos * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17897be3a4Schristos * PERFORMANCE OF THIS SOFTWARE. 18897be3a4Schristos */ 19897be3a4Schristos 20897be3a4Schristos /* Id: lib.c,v 1.16 2009/09/02 23:48:02 tbox Exp */ 21897be3a4Schristos 22897be3a4Schristos /*! \file */ 23897be3a4Schristos 24897be3a4Schristos #include <config.h> 25897be3a4Schristos 26897be3a4Schristos #include <stdio.h> 27897be3a4Schristos #include <stdlib.h> 28897be3a4Schristos 29897be3a4Schristos #include <isc/app.h> 30897be3a4Schristos #include <isc/lib.h> 31897be3a4Schristos #include <isc/mem.h> 32897be3a4Schristos #include <isc/msgs.h> 33897be3a4Schristos #include <isc/once.h> 34897be3a4Schristos #include <isc/socket.h> 35897be3a4Schristos #include <isc/task.h> 36897be3a4Schristos #include <isc/timer.h> 37897be3a4Schristos #include <isc/util.h> 38897be3a4Schristos 39897be3a4Schristos /*** 40897be3a4Schristos *** Globals 41897be3a4Schristos ***/ 42897be3a4Schristos 43897be3a4Schristos LIBISC_EXTERNAL_DATA isc_msgcat_t * isc_msgcat = NULL; 44897be3a4Schristos 45897be3a4Schristos 46897be3a4Schristos /*** 47897be3a4Schristos *** Private 48897be3a4Schristos ***/ 49897be3a4Schristos 50897be3a4Schristos static isc_once_t msgcat_once = ISC_ONCE_INIT; 51897be3a4Schristos 52897be3a4Schristos /*** 53897be3a4Schristos *** Functions 54897be3a4Schristos ***/ 55897be3a4Schristos 56897be3a4Schristos static void 57897be3a4Schristos open_msgcat(void) { 58897be3a4Schristos isc_msgcat_open("libisc.cat", &isc_msgcat); 59897be3a4Schristos } 60897be3a4Schristos 61897be3a4Schristos void 62897be3a4Schristos isc_lib_initmsgcat(void) { 63897be3a4Schristos isc_result_t result; 64897be3a4Schristos 65897be3a4Schristos /*! 66897be3a4Schristos * Initialize the ISC library's message catalog, isc_msgcat, if it 67897be3a4Schristos * has not already been initialized. 68897be3a4Schristos */ 69897be3a4Schristos 70897be3a4Schristos result = isc_once_do(&msgcat_once, open_msgcat); 71897be3a4Schristos if (result != ISC_R_SUCCESS) { 72897be3a4Schristos /* 73897be3a4Schristos * Normally we'd use RUNTIME_CHECK() or FATAL_ERROR(), but 74897be3a4Schristos * we can't do that here, since they might call us! 75897be3a4Schristos * (Note that the catalog might be open anyway, so we might 76897be3a4Schristos * as well try to provide an internationalized message.) 77897be3a4Schristos */ 78897be3a4Schristos fprintf(stderr, "%s:%d: %s: isc_once_do() %s.\n", 79897be3a4Schristos __FILE__, __LINE__, 80897be3a4Schristos isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL, 81897be3a4Schristos ISC_MSG_FATALERROR, "fatal error"), 82897be3a4Schristos isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL, 83897be3a4Schristos ISC_MSG_FAILED, "failed")); 84897be3a4Schristos abort(); 85897be3a4Schristos } 86897be3a4Schristos } 87897be3a4Schristos 88897be3a4Schristos #ifndef BIND9 89897be3a4Schristos static isc_once_t register_once = ISC_ONCE_INIT; 90897be3a4Schristos 91897be3a4Schristos static void 92897be3a4Schristos do_register(void) { 93897be3a4Schristos RUNTIME_CHECK(isc__mem_register() == ISC_R_SUCCESS); 94897be3a4Schristos RUNTIME_CHECK(isc__app_register() == ISC_R_SUCCESS); 95897be3a4Schristos RUNTIME_CHECK(isc__task_register() == ISC_R_SUCCESS); 96897be3a4Schristos RUNTIME_CHECK(isc__socket_register() == ISC_R_SUCCESS); 97897be3a4Schristos RUNTIME_CHECK(isc__timer_register() == ISC_R_SUCCESS); 98897be3a4Schristos } 99897be3a4Schristos 100897be3a4Schristos void 101897be3a4Schristos isc_lib_register() { 102897be3a4Schristos RUNTIME_CHECK(isc_once_do(®ister_once, do_register) 103897be3a4Schristos == ISC_R_SUCCESS); 104897be3a4Schristos } 105897be3a4Schristos #endif 106