main.c revision 1b67d9b719766459344caededa1e3f670985d311
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 2004-2010 Internet Systems Consortium, Inc. ("ISC")
2f072c2982861ec2e86e97f8a3ed199fe45c1f70Michael Graff * Copyright (C) 1999-2003 Internet Software Consortium.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * purpose with or without fee is hereby granted, provided that the above
2f072c2982861ec2e86e97f8a3ed199fe45c1f70Michael Graff * copyright notice and this permission notice appear in all copies.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * PERFORMANCE OF THIS SOFTWARE.
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff/* $Id: main.c,v 1.178 2010/06/26 23:46:49 tbox Exp $ */
0bd044c2afee944d93879a7de82cd2ccc0635798David Lawrence * Defining NS_MAIN provides storage declarations (rather than extern)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * for variables in named/globals.h.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <named/globals.h> /* Explicit, though named/log.h includes it. */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Include header files for database drivers here.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews/* #include "xxdb.h" */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Include DLZ drivers if appropriate.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * The maximum number of stack frames to dump on assertion failure.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic char program_name[ISC_DIR_NAMEMAX] = "named";
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic unsigned int maxsocks = 0;
822f6cdabb1edd44472c7a758b5cae71376fa9beBrian Wellingtonstatic int maxudp = 0;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffns_main_earlywarning(const char *format, ...) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "exiting (due to early fatal error)");
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsassertion_failed(const char *file, int line, isc_assertiontype_t type,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsassertion_failed(const char *file, int line, isc_assertiontype_t type,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews const char *cond)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Handle assertion failures.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Reset the assertion callback in case it is the log
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * routines causing the assertion.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews result = isc_backtrace_gettrace(tracebuf, BACKTRACE_MAXFRAME,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_assertion_typetotext(type), cond, logsuffix);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews for (i = 0; i < nframes; i++) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson unsigned long offset;
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson result = isc_backtrace_getsymbol(tracebuf[i],
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews "#%d %p in %s()+0x%lx", i,
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews "#%d %p in ??", i,
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "exiting (due to assertion failure)");
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews file, line, isc_assertion_typetotext(type), cond);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewslibrary_fatal_error(const char *file, int line, const char *format,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark AndrewsISC_FORMAT_PRINTF(3, 0) ISC_PLATFORM_NORETURN_POST;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewslibrary_fatal_error(const char *file, int line, const char *format,
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews * Handle isc_error_fatal() calls from our libraries.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Reset the error callback in case it is the log
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * routines causing the assertion.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "exiting (due to fatal error in library)");
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fprintf(stderr, "%s:%d: fatal error: ", file, line);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewslibrary_unexpected_error(const char *file, int line, const char *format,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewslibrary_unexpected_error(const char *file, int line, const char *format,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Handle isc_error_unexpected() calls from our libraries.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fprintf(stderr, "%s:%d: fatal error: ", file, line);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] "
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "[-d debuglevel]\n"
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews " [-f|-g] [-n number_of_cpus] [-p port] "
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "[-P listen-port] [-s]\n"
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews " [-t chrootdir] [-u username] [-i pidfile]\n"
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews " [-m {usage|trace|record|size|mctx}]\n");
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "usage: named [-4|-6] [-c conffile] [-d debuglevel] "
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "[-E engine] [-f|-g]\n"
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews " [-n number_of_cpus] [-p port] [-s] "
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "[-t chrootdir] [-u username]\n"
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff " [-m {usage|trace|record|size|mctx}]\n");
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington eob = saved_command_line + sizeof(saved_command_line);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington * This won't perfectly produce a shell-independent
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington * pastable command line in all circumstances, but
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington * comes close, and for practical purposes will
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington * nearly always be fine.
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington INSIST(sizeof(saved_command_line) >= sizeof(truncated));
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington strcpy(eob - sizeof(truncated), truncated);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington ns_main_earlyfatal("%s '%s' out of range", desc, arg);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic struct flag_def {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellingtonset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington for (def = defs; def->name != NULL; def++) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellingtonparse_command_line(int argc, char *argv[]) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington while ((ch = isc_commandline_parse(argc, argv,
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington "46c:C:d:E:fFgi:lm:n:N:p:P:"
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington ns_main_earlyfatal("cannot specify -4 and -6");
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington ns_main_earlyfatal("IPv4 not supported by OS");
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff ns_main_earlyfatal("cannot specify -4 and -6");
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson if (isc_net_probeipv6() != ISC_R_SUCCESS)
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson ns_main_earlyfatal("IPv6 not supported by OS");
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington ns_main_earlyfatal("cannot specify -c and -C");
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington lwresd_g_resolvconffile = isc_commandline_argument;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington ns_main_earlyfatal("cannot specify -c and -C");
d981ca645597116d227a48bf37cc5edc061c854dBob Halley ns_g_debuglevel = parse_int(isc_commandline_argument,
d981ca645597116d227a48bf37cc5edc061c854dBob Halley "debug level");
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley /* XXXBEW -i should be removed */
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley lwresd_g_defaultpidfile = isc_commandline_argument;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley set_flags(isc_commandline_argument, mem_debug_flags,
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley "number of cpus");
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley port = parse_int(isc_commandline_argument, "port");
exit(0);
exit(0);
usage();
exit(0);
if (argc > 0) {
usage();
static isc_result_t
create_managers(void) {
unsigned int socks;
#ifdef ISC_PLATFORM_USETHREADS
if (ns_g_cpus == 0)
return (ISC_R_UNEXPECTED);
return (ISC_R_UNEXPECTED);
return (ISC_R_UNEXPECTED);
return (ISC_R_UNEXPECTED);
return (ISC_R_UNEXPECTED);
return (ISC_R_SUCCESS);
destroy_managers(void) {
dump_symboltable() {
const char *fname;
const void *addr;
if (isc__backtrace_nsymbols == 0)
setup(void) {
#ifdef HAVE_LIBSCF
ns_os_tzset();
#ifdef HAVE_LIBSCF
ns_smf_got_instance = 0;
#ifdef PATH_RANDOMDEV
#ifdef ISC_PLATFORM_USETHREADS
if (!ns_g_foreground)
sizeof(absolute_conffile));
#ifdef DLZ
cleanup(void) {
#ifdef DLZ
if (memstats)
#ifdef HAVE_LIBSCF
int namelen;
char *instance;
if (debug)
return (ISC_R_FAILURE);
if (debug)
return (ISC_R_FAILURE);
if (debug)
return (ISC_R_FAILURE);
return (ISC_R_FAILURE);
if (debug)
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
#ifdef HAVE_LIBSCF
* strings named.core | grep "named version:"
sizeof(version));
setup();
#ifdef HAVE_LIBSCF
cleanup();
if (want_stats) {