main.c revision 1b67d9b719766459344caededa1e3f670985d311
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews/*
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 2004-2010 Internet Systems Consortium, Inc. ("ISC")
2f072c2982861ec2e86e97f8a3ed199fe45c1f70Michael Graff * Copyright (C) 1999-2003 Internet Software Consortium.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews *
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 *
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.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff/* $Id: main.c,v 1.178 2010/06/26 23:46:49 tbox Exp $ */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson/*! \file */
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson#include <config.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#include <ctype.h>
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#include <stdlib.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <string.h>
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
d981ca645597116d227a48bf37cc5edc061c854dBob Halley#include <isc/app.h>
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews#include <isc/backtrace.h>
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews#include <isc/commandline.h>
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews#include <isc/dir.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <isc/entropy.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <isc/file.h>
0bd044c2afee944d93879a7de82cd2ccc0635798David Lawrence#include <isc/hash.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <isc/os.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <isc/platform.h>
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff#include <isc/print.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <isc/resource.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <isc/stdio.h>
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#include <isc/string.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <isc/task.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <isc/timer.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <isc/util.h>
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <isccc/result.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <dns/dispatch.h>
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson#include <dns/name.h>
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff#include <dns/result.h>
0bd044c2afee944d93879a7de82cd2ccc0635798David Lawrence#include <dns/view.h>
0bd044c2afee944d93879a7de82cd2ccc0635798David Lawrence
0bd044c2afee944d93879a7de82cd2ccc0635798David Lawrence#include <dst/result.h>
5d15501996f597d9bbb734d88d4549828e28000bMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews/*
0bd044c2afee944d93879a7de82cd2ccc0635798David Lawrence * Defining NS_MAIN provides storage declarations (rather than extern)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * for variables in named/globals.h.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#define NS_MAIN 1
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson#include <named/builtin.h>
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson#include <named/control.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <named/globals.h> /* Explicit, though named/log.h includes it. */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <named/interfacemgr.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <named/log.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <named/os.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <named/server.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <named/lwresd.h>
ea8651059209b96fa005e06a0b9b33ae5a8eacd4David Lawrence#include <named/main.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#ifdef HAVE_LIBSCF
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#include <named/ns_smf_globals.h>
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#endif
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews/*
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Include header files for database drivers here.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews/* #include "xxdb.h" */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson/*
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Include DLZ drivers if appropriate.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#ifdef DLZ
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#include <dlz/dlz_drivers.h>
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#endif
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews/*
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * The maximum number of stack frames to dump on assertion failure.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#ifndef BACKTRACE_MAXFRAME
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#define BACKTRACE_MAXFRAME 128
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews#endif
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic isc_boolean_t want_stats = ISC_FALSE;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic char program_name[ISC_DIR_NAMEMAX] = "named";
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic char absolute_conffile[ISC_DIR_PATHMAX];
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic char saved_command_line[512];
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic char version[512];
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic unsigned int maxsocks = 0;
822f6cdabb1edd44472c7a758b5cae71376fa9beBrian Wellingtonstatic int maxudp = 0;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsvoid
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffns_main_earlywarning(const char *format, ...) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson va_list args;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson va_start(args, format);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (ns_g_lctx != NULL) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews NS_LOGMODULE_MAIN, ISC_LOG_WARNING,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews format, args);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews } else {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fprintf(stderr, "%s: ", program_name);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews vfprintf(stderr, format, args);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fprintf(stderr, "\n");
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fflush(stderr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews }
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews va_end(args);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsvoid
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsns_main_earlyfatal(const char *format, ...) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews va_list args;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews va_start(args, format);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (ns_g_lctx != NULL) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews format, args);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "exiting (due to early fatal error)");
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews } else {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fprintf(stderr, "%s: ", program_name);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews vfprintf(stderr, format, args);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fprintf(stderr, "\n");
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fflush(stderr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews }
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews va_end(args);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews exit(1);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark AndrewsISC_PLATFORM_NORETURN_PRE static void
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsassertion_failed(const char *file, int line, isc_assertiontype_t type,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews const char *cond) ISC_PLATFORM_NORETURN_POST;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic void
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsassertion_failed(const char *file, int line, isc_assertiontype_t type,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews const char *cond)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson{
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews void *tracebuf[BACKTRACE_MAXFRAME];
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson int i, nframes;
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson isc_result_t result;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson const char *logsuffix = "";
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson const char *fname;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /*
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Handle assertion failures.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (ns_g_lctx != NULL) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /*
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Reset the assertion callback in case it is the log
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * routines causing the assertion.
b5da378f2987a115491c291d062252f3152d8db8Brian Wellington */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_assertion_setcallback(NULL);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews result = isc_backtrace_gettrace(tracebuf, BACKTRACE_MAXFRAME,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews &nframes);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (result == ISC_R_SUCCESS && nframes > 0)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews logsuffix = ", back trace";
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson "%s:%d: %s(%s) failed%s", file, line,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_assertion_typetotext(type), cond, logsuffix);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (result == ISC_R_SUCCESS) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews for (i = 0; i < nframes; i++) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson unsigned long offset;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson fname = NULL;
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson result = isc_backtrace_getsymbol(tracebuf[i],
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson &fname,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson &offset);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result == ISC_R_SUCCESS) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_write(ns_g_lctx,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews NS_LOGCATEGORY_GENERAL,
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff NS_LOGMODULE_MAIN,
d981ca645597116d227a48bf37cc5edc061c854dBob Halley ISC_LOG_CRITICAL,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews "#%d %p in %s()+0x%lx", i,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews tracebuf[i], fname,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews offset);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews } else {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_write(ns_g_lctx,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews NS_LOGMODULE_MAIN,
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews ISC_LOG_CRITICAL,
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews "#%d %p in ??", i,
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews tracebuf[i]);
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews }
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews }
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews }
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "exiting (due to assertion failure)");
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews } else {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fprintf(stderr, "%s:%d: %s(%s) failed\n",
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews file, line, isc_assertion_typetotext(type), cond);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fflush(stderr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews }
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (ns_g_coreok)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews abort();
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews exit(1);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark AndrewsISC_PLATFORM_NORETURN_PRE static void
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewslibrary_fatal_error(const char *file, int line, const char *format,
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews va_list args)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark AndrewsISC_FORMAT_PRINTF(3, 0) ISC_PLATFORM_NORETURN_POST;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic void
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewslibrary_fatal_error(const char *file, int line, const char *format,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews va_list args)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews{
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews /*
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews * Handle isc_error_fatal() calls from our libraries.
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (ns_g_lctx != NULL) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff /*
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Reset the error callback in case it is the log
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * routines causing the assertion.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_error_setfatal(NULL);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews "%s:%d: fatal error:", file, line);
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews format, args);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "exiting (due to fatal error in library)");
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews } else {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fprintf(stderr, "%s:%d: fatal error: ", file, line);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews vfprintf(stderr, format, args);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fprintf(stderr, "\n");
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fflush(stderr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews }
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (ns_g_coreok)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews abort();
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews exit(1);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic void
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewslibrary_unexpected_error(const char *file, int line, const char *format,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews va_list args) ISC_FORMAT_PRINTF(3, 0);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic void
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewslibrary_unexpected_error(const char *file, int line, const char *format,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews va_list args)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews{
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley /*
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews * Handle isc_error_unexpected() calls from our libraries.
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (ns_g_lctx != NULL) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson NS_LOGMODULE_MAIN, ISC_LOG_ERROR,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "%s:%d: unexpected error:", file, line);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
d981ca645597116d227a48bf37cc5edc061c854dBob Halley NS_LOGMODULE_MAIN, ISC_LOG_ERROR,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews format, args);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews } else {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fprintf(stderr, "%s:%d: fatal error: ", file, line);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews vfprintf(stderr, format, args);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fprintf(stderr, "\n");
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fflush(stderr);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews }
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafssonstatic void
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafssonlwresd_usage(void) {
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson fprintf(stderr,
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}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic void
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafssonusage(void) {
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson if (ns_g_lwresdonly) {
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson lwresd_usage();
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson return;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews }
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews fprintf(stderr,
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");
d981ca645597116d227a48bf37cc5edc061c854dBob Halley}
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrewsstatic void
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellingtonsave_command_line(int argc, char *argv[]) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington int i;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington char *src;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews char *dst;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews char *eob;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews const char truncated[] = "...";
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson isc_boolean_t quoted = ISC_FALSE;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington dst = saved_command_line;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington eob = saved_command_line + sizeof(saved_command_line);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington for (i = 1; i < argc && dst < eob; i++) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington *dst++ = ' ';
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington src = argv[i];
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington while (*src != '\0' && dst < eob) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington /*
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 */
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington if (quoted || isalnum(*src & 0xff) ||
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington *src == '-' || *src == '_' ||
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington *src == '.' || *src == '/') {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington *dst++ = *src++;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington quoted = ISC_FALSE;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington } else {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington *dst++ = '\\';
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington quoted = ISC_TRUE;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington }
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington }
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington }
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington INSIST(sizeof(saved_command_line) >= sizeof(truncated));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington if (dst == eob)
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington strcpy(eob - sizeof(truncated), truncated);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington else
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington *dst = '\0';
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington}
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graffstatic int
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellingtonparse_int(char *arg, const char *desc) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington char *endp;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington int tmp;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington long int ltmp;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews ltmp = strtol(arg, &endp, 10);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews tmp = (int) ltmp;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff if (*endp != '\0')
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington if (tmp < 0 || tmp != ltmp)
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington ns_main_earlyfatal("%s '%s' out of range", desc, arg);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington return (tmp);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic struct flag_def {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington const char *name;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington unsigned int value;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington} mem_debug_flags[] = {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington { "trace", ISC_MEM_DEBUGTRACE },
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington { "record", ISC_MEM_DEBUGRECORD },
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington { "usage", ISC_MEM_DEBUGUSAGE },
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington { "size", ISC_MEM_DEBUGSIZE },
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington { "mctx", ISC_MEM_DEBUGCTX },
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington { NULL, 0 }
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington};
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellingtonstatic void
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellingtonset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington for (;;) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington const struct flag_def *def;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington const char *end = strchr(arg, ',');
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington int arglen;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington if (end == NULL)
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington end = arg + strlen(arg);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington arglen = end - arg;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington for (def = defs; def->name != NULL; def++) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington if (arglen == (int)strlen(def->name) &&
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington memcmp(arg, def->name, arglen) == 0) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington *ret |= def->value;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington goto found;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington }
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington }
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington found:
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington if (*end == '\0')
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington break;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington arg = end + 1;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington }
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington}
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellingtonstatic void
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellingtonparse_command_line(int argc, char *argv[]) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington int ch;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington int port;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_boolean_t disable6 = ISC_FALSE;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_boolean_t disable4 = ISC_FALSE;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington save_command_line(argc, argv);
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_commandline_errprint = ISC_FALSE;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington while ((ch = isc_commandline_parse(argc, argv,
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington "46c:C:d:E:fFgi:lm:n:N:p:P:"
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington "sS:t:T:u:vVx:")) != -1) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington switch (ch) {
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington case '4':
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington if (disable4)
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington ns_main_earlyfatal("cannot specify -4 and -6");
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington if (isc_net_probeipv4() != ISC_R_SUCCESS)
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington ns_main_earlyfatal("IPv4 not supported by OS");
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington isc_net_disableipv6();
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington disable6 = ISC_TRUE;
b5da378f2987a115491c291d062252f3152d8db8Brian Wellington break;
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson case '6':
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson if (disable6)
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 isc_net_disableipv4();
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff disable4 = ISC_TRUE;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews break;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews case 'c':
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley ns_g_conffile = isc_commandline_argument;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews lwresd_g_conffile = isc_commandline_argument;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington if (lwresd_g_useresolvconf)
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington ns_main_earlyfatal("cannot specify -c and -C");
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews ns_g_conffileset = ISC_TRUE;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington break;
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington case 'C':
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington lwresd_g_resolvconffile = isc_commandline_argument;
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson if (ns_g_conffileset)
d8813e2ceee2f4adaf697931c2491de265ce5eb9Brian Wellington ns_main_earlyfatal("cannot specify -c and -C");
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews lwresd_g_useresolvconf = ISC_TRUE;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley break;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff case 'd':
d981ca645597116d227a48bf37cc5edc061c854dBob Halley ns_g_debuglevel = parse_int(isc_commandline_argument,
d981ca645597116d227a48bf37cc5edc061c854dBob Halley "debug level");
d981ca645597116d227a48bf37cc5edc061c854dBob Halley break;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley case 'E':
d981ca645597116d227a48bf37cc5edc061c854dBob Halley ns_g_engine = isc_commandline_argument;
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson break;
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson case 'f':
d981ca645597116d227a48bf37cc5edc061c854dBob Halley ns_g_foreground = ISC_TRUE;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff break;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley case 'g':
d981ca645597116d227a48bf37cc5edc061c854dBob Halley ns_g_foreground = ISC_TRUE;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff ns_g_logstderr = ISC_TRUE;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley break;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley /* XXXBEW -i should be removed */
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley case 'i':
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley lwresd_g_defaultpidfile = isc_commandline_argument;
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson break;
542deb20c44666a870855bf755a100d254db074dAndreas Gustafsson case 'l':
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley ns_g_lwresdonly = ISC_TRUE;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff break;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley case 'm':
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley set_flags(isc_commandline_argument, mem_debug_flags,
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley &isc_mem_debugging);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley break;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley case 'N': /* Deprecated. */
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley case 'n':
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley ns_g_cpus = parse_int(isc_commandline_argument,
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley "number of cpus");
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley if (ns_g_cpus == 0)
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley ns_g_cpus = 1;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley break;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley case 'p':
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley port = parse_int(isc_commandline_argument, "port");
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley if (port < 1 || port > 65535)
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley ns_main_earlyfatal("port '%s' out of range",
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews isc_commandline_argument);
ns_g_port = port;
break;
/* XXXBEW Should -P be removed? */
case 'P':
port = parse_int(isc_commandline_argument, "port");
if (port < 1 || port > 65535)
ns_main_earlyfatal("port '%s' out of range",
isc_commandline_argument);
lwresd_g_listenport = port;
break;
case 's':
/* XXXRTH temporary syntax */
want_stats = ISC_TRUE;
break;
case 'S':
maxsocks = parse_int(isc_commandline_argument,
"max number of sockets");
break;
case 't':
/* XXXJAB should we make a copy? */
ns_g_chrootdir = isc_commandline_argument;
break;
case 'T': /* NOT DOCUMENTED */
/*
* clienttest: make clients single shot with their
* own memory context.
*/
if (!strcmp(isc_commandline_argument, "clienttest"))
ns_g_clienttest = ISC_TRUE;
else if (!strcmp(isc_commandline_argument, "nosoa"))
ns_g_nosoa = ISC_TRUE;
else if (!strcmp(isc_commandline_argument, "maxudp512"))
maxudp = 512;
else if (!strcmp(isc_commandline_argument, "maxudp1460"))
maxudp = 1460;
else
fprintf(stderr, "unknown -T flag '%s\n",
isc_commandline_argument);
break;
case 'u':
ns_g_username = isc_commandline_argument;
break;
case 'v':
printf("BIND %s\n", ns_g_version);
exit(0);
case 'V':
printf("BIND %s built with %s\n", ns_g_version,
ns_g_configargs);
exit(0);
case 'F':
/* Reserved for FIPS mode */
/* FALLTHROUGH */
case '?':
usage();
if (isc_commandline_option == '?')
exit(0);
ns_main_earlyfatal("unknown option '-%c'",
isc_commandline_option);
/* FALLTHROUGH */
default:
ns_main_earlyfatal("parsing options returned %d", ch);
}
}
argc -= isc_commandline_index;
argv += isc_commandline_index;
if (argc > 0) {
usage();
ns_main_earlyfatal("extra command line arguments");
}
}
static isc_result_t
create_managers(void) {
isc_result_t result;
unsigned int socks;
#ifdef ISC_PLATFORM_USETHREADS
if (ns_g_cpus == 0)
ns_g_cpus = ns_g_cpus_detected;
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_INFO, "found %u CPU%s, using %u worker thread%s",
ns_g_cpus_detected, ns_g_cpus_detected == 1 ? "" : "s",
ns_g_cpus, ns_g_cpus == 1 ? "" : "s");
#else
ns_g_cpus = 1;
#endif
result = isc_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_taskmgr_create() failed: %s",
isc_result_totext(result));
return (ISC_R_UNEXPECTED);
}
result = isc_timermgr_create(ns_g_mctx, &ns_g_timermgr);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_timermgr_create() failed: %s",
isc_result_totext(result));
return (ISC_R_UNEXPECTED);
}
result = isc_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_socketmgr_create() failed: %s",
isc_result_totext(result));
return (ISC_R_UNEXPECTED);
}
isc__socketmgr_maxudp(ns_g_socketmgr, maxudp);
result = isc_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);
if (result == ISC_R_SUCCESS) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER,
ISC_LOG_INFO, "using up to %u sockets", socks);
}
result = isc_entropy_create(ns_g_mctx, &ns_g_entropy);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_entropy_create() failed: %s",
isc_result_totext(result));
return (ISC_R_UNEXPECTED);
}
result = isc_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_hash_create() failed: %s",
isc_result_totext(result));
return (ISC_R_UNEXPECTED);
}
return (ISC_R_SUCCESS);
}
static void
destroy_managers(void) {
ns_lwresd_shutdown();
isc_entropy_detach(&ns_g_entropy);
if (ns_g_fallbackentropy != NULL)
isc_entropy_detach(&ns_g_fallbackentropy);
/*
* isc_taskmgr_destroy() will block until all tasks have exited,
*/
isc_taskmgr_destroy(&ns_g_taskmgr);
isc_timermgr_destroy(&ns_g_timermgr);
isc_socketmgr_destroy(&ns_g_socketmgr);
/*
* isc_hash_destroy() cannot be called as long as a resolver may be
* running. Calling this after isc_taskmgr_destroy() ensures the
* call is safe.
*/
isc_hash_destroy();
}
static void
dump_symboltable() {
int i;
isc_result_t result;
const char *fname;
const void *addr;
if (isc__backtrace_nsymbols == 0)
return;
if (!isc_log_wouldlog(ns_g_lctx, ISC_LOG_DEBUG(99)))
return;
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_DEBUG(99), "Symbol table:");
for (i = 0, result = ISC_R_SUCCESS; result == ISC_R_SUCCESS; i++) {
addr = NULL;
fname = NULL;
result = isc_backtrace_getsymbolfromindex(i, &addr, &fname);
if (result == ISC_R_SUCCESS) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_DEBUG(99),
"[%d] %p %s", i, addr, fname);
}
}
}
static void
setup(void) {
isc_result_t result;
isc_resourcevalue_t old_openfiles;
#ifdef HAVE_LIBSCF
char *instance = NULL;
#endif
/*
* Get the user and group information before changing the root
* directory, so the administrator does not need to keep a copy
* of the user and group databases in the chroot'ed environment.
*/
ns_os_inituserinfo(ns_g_username);
/*
* Initialize time conversion information
*/
ns_os_tzset();
ns_os_opendevnull();
#ifdef HAVE_LIBSCF
/* Check if named is under smf control, before chroot. */
result = ns_smf_get_instance(&instance, 0, ns_g_mctx);
/* We don't care about instance, just check if we got one. */
if (result == ISC_R_SUCCESS)
ns_smf_got_instance = 1;
else
ns_smf_got_instance = 0;
if (instance != NULL)
isc_mem_free(ns_g_mctx, instance);
#endif /* HAVE_LIBSCF */
#ifdef PATH_RANDOMDEV
/*
* Initialize system's random device as fallback entropy source
* if running chroot'ed.
*/
if (ns_g_chrootdir != NULL) {
result = isc_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("isc_entropy_create() failed: %s",
isc_result_totext(result));
result = isc_entropy_createfilesource(ns_g_fallbackentropy,
PATH_RANDOMDEV);
if (result != ISC_R_SUCCESS) {
ns_main_earlywarning("could not open pre-chroot "
"entropy source %s: %s",
PATH_RANDOMDEV,
isc_result_totext(result));
isc_entropy_detach(&ns_g_fallbackentropy);
}
}
#endif
#ifdef ISC_PLATFORM_USETHREADS
/*
* Check for the number of cpu's before ns_os_chroot().
*/
ns_g_cpus_detected = isc_os_ncpus();
#endif
ns_os_chroot(ns_g_chrootdir);
/*
* For operating systems which have a capability mechanism, now
* is the time to switch to minimal privs and change our user id.
* On traditional UNIX systems, this call will be a no-op, and we
* will change the user ID after reading the config file the first
* time. (We need to read the config file to know which possibly
* privileged ports to bind() to.)
*/
ns_os_minprivs();
result = ns_log_init(ISC_TF(ns_g_username != NULL));
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("ns_log_init() failed: %s",
isc_result_totext(result));
/*
* Now is the time to daemonize (if we're not running in the
* foreground). We waited until now because we wanted to get
* a valid logging context setup. We cannot daemonize any later,
* because calling create_managers() will create threads, which
* would be lost after fork().
*/
if (!ns_g_foreground)
ns_os_daemonize();
/*
* We call isc_app_start() here as some versions of FreeBSD's fork()
* destroys all the signal handling it sets up.
*/
result = isc_app_start();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("isc_app_start() failed: %s",
isc_result_totext(result));
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "starting BIND %s%s", ns_g_version,
saved_command_line);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "built with %s", ns_g_configargs);
dump_symboltable();
/*
* Get the initial resource limits.
*/
(void)isc_resource_getlimit(isc_resource_stacksize,
&ns_g_initstacksize);
(void)isc_resource_getlimit(isc_resource_datasize,
&ns_g_initdatasize);
(void)isc_resource_getlimit(isc_resource_coresize,
&ns_g_initcoresize);
(void)isc_resource_getlimit(isc_resource_openfiles,
&ns_g_initopenfiles);
/*
* System resources cannot effectively be tuned on some systems.
* Raise the limit in such cases for safety.
*/
old_openfiles = ns_g_initopenfiles;
ns_os_adjustnofile();
(void)isc_resource_getlimit(isc_resource_openfiles,
&ns_g_initopenfiles);
if (old_openfiles != ns_g_initopenfiles) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"adjusted limit on open files from "
"%" ISC_PRINT_QUADFORMAT "u to "
"%" ISC_PRINT_QUADFORMAT "u",
old_openfiles, ns_g_initopenfiles);
}
/*
* If the named configuration filename is relative, prepend the current
* directory's name before possibly changing to another directory.
*/
if (! isc_file_isabsolute(ns_g_conffile)) {
result = isc_file_absolutepath(ns_g_conffile,
absolute_conffile,
sizeof(absolute_conffile));
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("could not construct absolute path "
"of configuration file: %s",
isc_result_totext(result));
ns_g_conffile = absolute_conffile;
}
/*
* Record the server's startup time.
*/
result = isc_time_now(&ns_g_boottime);
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("isc_time_now() failed: %s",
isc_result_totext(result));
result = create_managers();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("create_managers() failed: %s",
isc_result_totext(result));
ns_builtin_init();
/*
* Add calls to register sdb drivers here.
*/
/* xxdb_init(); */
#ifdef DLZ
/*
* Register any DLZ drivers.
*/
result = dlz_drivers_init();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("dlz_drivers_init() failed: %s",
isc_result_totext(result));
#endif
ns_server_create(ns_g_mctx, &ns_g_server);
}
static void
cleanup(void) {
destroy_managers();
ns_server_destroy(&ns_g_server);
ns_builtin_deinit();
/*
* Add calls to unregister sdb drivers here.
*/
/* xxdb_clear(); */
#ifdef DLZ
/*
* Unregister any DLZ drivers.
*/
dlz_drivers_clear();
#endif
dns_name_destroy();
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "exiting");
ns_log_shutdown();
}
static char *memstats = NULL;
void
ns_main_setmemstats(const char *filename) {
/*
* Caller has to ensure locking.
*/
if (memstats != NULL) {
free(memstats);
memstats = NULL;
}
if (filename == NULL)
return;
memstats = malloc(strlen(filename) + 1);
if (memstats)
strcpy(memstats, filename);
}
#ifdef HAVE_LIBSCF
/*
* Get FMRI for the named process.
*/
isc_result_t
ns_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx) {
scf_handle_t *h = NULL;
int namelen;
char *instance;
REQUIRE(ins_name != NULL && *ins_name == NULL);
if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
if (debug)
UNEXPECTED_ERROR(__FILE__, __LINE__,
"scf_handle_create() failed: %s",
scf_strerror(scf_error()));
return (ISC_R_FAILURE);
}
if (scf_handle_bind(h) == -1) {
if (debug)
UNEXPECTED_ERROR(__FILE__, __LINE__,
"scf_handle_bind() failed: %s",
scf_strerror(scf_error()));
scf_handle_destroy(h);
return (ISC_R_FAILURE);
}
if ((namelen = scf_myname(h, NULL, 0)) == -1) {
if (debug)
UNEXPECTED_ERROR(__FILE__, __LINE__,
"scf_myname() failed: %s",
scf_strerror(scf_error()));
scf_handle_destroy(h);
return (ISC_R_FAILURE);
}
if ((instance = isc_mem_allocate(mctx, namelen + 1)) == NULL) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"ns_smf_get_instance memory "
"allocation failed: %s",
isc_result_totext(ISC_R_NOMEMORY));
scf_handle_destroy(h);
return (ISC_R_FAILURE);
}
if (scf_myname(h, instance, namelen + 1) == -1) {
if (debug)
UNEXPECTED_ERROR(__FILE__, __LINE__,
"scf_myname() failed: %s",
scf_strerror(scf_error()));
scf_handle_destroy(h);
isc_mem_free(mctx, instance);
return (ISC_R_FAILURE);
}
scf_handle_destroy(h);
*ins_name = instance;
return (ISC_R_SUCCESS);
}
#endif /* HAVE_LIBSCF */
int
main(int argc, char *argv[]) {
isc_result_t result;
#ifdef HAVE_LIBSCF
char *instance = NULL;
#endif
/*
* Record version in core image.
* strings named.core | grep "named version:"
*/
strlcat(version,
#if defined(NO_VERSION_DATE) || !defined(__DATE__)
"named version: BIND " VERSION,
#else
"named version: BIND " VERSION " (" __DATE__ ")",
#endif
sizeof(version));
result = isc_file_progname(*argv, program_name, sizeof(program_name));
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("program name too long");
if (strcmp(program_name, "lwresd") == 0)
ns_g_lwresdonly = ISC_TRUE;
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("failed to build internal symbol table");
isc_assertion_setcallback(assertion_failed);
isc_error_setfatal(library_fatal_error);
isc_error_setunexpected(library_unexpected_error);
ns_os_init(program_name);
dns_result_register();
dst_result_register();
isccc_result_register();
parse_command_line(argc, argv);
/*
* Warn about common configuration error.
*/
if (ns_g_chrootdir != NULL) {
int len = strlen(ns_g_chrootdir);
if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&
(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))
ns_main_earlywarning("config filename (-c %s) contains "
"chroot path (-t %s)",
ns_g_conffile, ns_g_chrootdir);
}
result = isc_mem_create(0, 0, &ns_g_mctx);
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("isc_mem_create() failed: %s",
isc_result_totext(result));
isc_mem_setname(ns_g_mctx, "main", NULL);
setup();
/*
* Start things running and then wait for a shutdown request
* or reload.
*/
do {
result = isc_app_run();
if (result == ISC_R_RELOAD) {
ns_server_reloadwanted(ns_g_server);
} else if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_run(): %s",
isc_result_totext(result));
/*
* Force exit.
*/
result = ISC_R_SUCCESS;
}
} while (result != ISC_R_SUCCESS);
#ifdef HAVE_LIBSCF
if (ns_smf_want_disable == 1) {
result = ns_smf_get_instance(&instance, 1, ns_g_mctx);
if (result == ISC_R_SUCCESS && instance != NULL) {
if (smf_disable_instance(instance, 0) != 0)
UNEXPECTED_ERROR(__FILE__, __LINE__,
"smf_disable_instance() "
"failed for %s : %s",
instance,
scf_strerror(scf_error()));
}
if (instance != NULL)
isc_mem_free(ns_g_mctx, instance);
}
#endif /* HAVE_LIBSCF */
cleanup();
if (want_stats) {
isc_mem_stats(ns_g_mctx, stdout);
isc_mutex_stats(stdout);
}
if (ns_g_memstatistics && memstats != NULL) {
FILE *fp = NULL;
result = isc_stdio_open(memstats, "w", &fp);
if (result == ISC_R_SUCCESS) {
isc_mem_stats(ns_g_mctx, fp);
isc_mutex_stats(fp);
isc_stdio_close(fp);
}
}
isc_mem_destroy(&ns_g_mctx);
isc_mem_checkdestroyed(stderr);
ns_main_setmemstats(NULL);
isc_app_finish();
ns_os_closedevnull();
ns_os_shutdown();
return (0);
}