main.c revision 25b95d31ce658326510bef979cf2909c6eddc428
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson/*
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * Copyright (C) 2004-2012 Internet Systems Consortium, Inc. ("ISC")
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * Copyright (C) 1999-2003 Internet Software Consortium.
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson *
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * Permission to use, copy, modify, and/or distribute this software for any
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson *
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * PERFORMANCE OF THIS SOFTWARE.
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson */
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson/* $Id: main.c,v 1.187 2012/02/06 23:46:44 tbox Exp $ */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson/*! \file */
9db88ce113701a6fb600a67aaa65764d800e25b0Mark Andrews
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <config.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <ctype.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <stdlib.h>
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews#include <string.h>
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/app.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/backtrace.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/commandline.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/dir.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/entropy.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/file.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/hash.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/os.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/platform.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/print.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/resource.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/stdio.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/string.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/task.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/timer.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/util.h>
9db88ce113701a6fb600a67aaa65764d800e25b0Mark Andrews
9db88ce113701a6fb600a67aaa65764d800e25b0Mark Andrews#include <isccc/result.h>
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉#include <dns/dispatch.h>
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉#include <dns/name.h>
9db88ce113701a6fb600a67aaa65764d800e25b0Mark Andrews#include <dns/result.h>
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉#include <dns/view.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <dst/result.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <dlz/dlz_dlopen_driver.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson/*
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Defining NS_MAIN provides storage declarations (rather than extern)
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * for variables in named/globals.h.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#define NS_MAIN 1
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉#include <named/builtin.h>
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉#include <named/control.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <named/globals.h> /* Explicit, though named/log.h includes it. */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <named/interfacemgr.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <named/log.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <named/os.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <named/server.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <named/lwresd.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <named/main.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef HAVE_LIBSCF
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <named/ns_smf_globals.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef OPENSSL
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews#include <openssl/opensslv.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef HAVE_LIBXML2
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <libxml/xmlversion.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson/*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Include header files for database drivers here.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson/* #include "xxdb.h" */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef CONTRIB_DLZ
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson/*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Include contributed DLZ drivers if appropriate.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
1bf8f4b77df1e1f8c1ce8326679ab02bac235c09Mark Andrews#include <dlz/dlz_drivers.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson/*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * The maximum number of stack frames to dump on assertion failure.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
1bf8f4b77df1e1f8c1ce8326679ab02bac235c09Mark Andrews#ifndef BACKTRACE_MAXFRAME
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#define BACKTRACE_MAXFRAME 128
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrews
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrewsstatic isc_boolean_t want_stats = ISC_FALSE;
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrewsstatic char program_name[ISC_DIR_NAMEMAX] = "named";
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrewsstatic char absolute_conffile[ISC_DIR_PATHMAX];
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrewsstatic char saved_command_line[512];
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrewsstatic char version[512];
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrewsstatic unsigned int maxsocks = 0;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstatic int maxudp = 0;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonvoid
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonns_main_earlywarning(const char *format, ...) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson va_list args;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson va_start(args, format);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_lctx != NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson NS_LOGMODULE_MAIN, ISC_LOG_WARNING,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson format, args);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson } else {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "%s: ", program_name);
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson vfprintf(stderr, format, args);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fflush(stderr);
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews }
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews va_end(args);
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews}
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews
66f51d8678c8fcc7256354b599317f67455120fdMark Andrewsvoid
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonns_main_earlyfatal(const char *format, ...) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson va_list args;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson va_start(args, format);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_lctx != NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson format, args);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "exiting (due to early fatal error)");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson } else {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "%s: ", program_name);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson vfprintf(stderr, format, args);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 fprintf(stderr, "\n");
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 fflush(stderr);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson va_end(args);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson exit(1);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉}
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉ISC_PLATFORM_NORETURN_PRE static void
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonassertion_failed(const char *file, int line, isc_assertiontype_t type,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson const char *cond) ISC_PLATFORM_NORETURN_POST;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrewsstatic void
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrewsassertion_failed(const char *file, int line, isc_assertiontype_t type,
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrews const char *cond)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson{
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson void *tracebuf[BACKTRACE_MAXFRAME];
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews int i, nframes;
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson isc_result_t result;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson const char *logsuffix = "";
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson const char *fname;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Handle assertion failures.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_lctx != NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Reset the assertion callback in case it is the log
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * routines causing the assertion.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_assertion_setcallback(NULL);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 result = isc_backtrace_gettrace(tracebuf, BACKTRACE_MAXFRAME,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 &nframes);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (result == ISC_R_SUCCESS && nframes > 0)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson logsuffix = ", back trace";
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "%s:%d: %s(%s) failed%s", file, line,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_assertion_typetotext(type), cond, logsuffix);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (result == ISC_R_SUCCESS) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 for (i = 0; i < nframes; i++) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 unsigned long offset;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 fname = NULL;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 result = isc_backtrace_getsymbol(tracebuf[i],
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 &fname,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 &offset);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (result == ISC_R_SUCCESS) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 NS_LOGCATEGORY_GENERAL,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 NS_LOGMODULE_MAIN,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ISC_LOG_CRITICAL,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "#%d %p in %s()+0x%lx", i,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 tracebuf[i], fname,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 offset);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 } else {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 NS_LOGCATEGORY_GENERAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson NS_LOGMODULE_MAIN,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ISC_LOG_CRITICAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "#%d %p in ??", i,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson tracebuf[i]);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 }
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrews NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "exiting (due to assertion failure)");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson } else {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "%s:%d: %s(%s) failed\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson file, line, isc_assertion_typetotext(type), cond);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fflush(stderr);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_coreok)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson abort();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson exit(1);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas GustafssonISC_PLATFORM_NORETURN_PRE static void
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonlibrary_fatal_error(const char *file, int line, const char *format,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson va_list args)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas GustafssonISC_FORMAT_PRINTF(3, 0) ISC_PLATFORM_NORETURN_POST;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstatic void
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonlibrary_fatal_error(const char *file, int line, const char *format,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson va_list args)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson{
9db88ce113701a6fb600a67aaa65764d800e25b0Mark Andrews /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Handle isc_error_fatal() calls from our libraries.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_lctx != NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Reset the error callback in case it is the log
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * routines causing the assertion.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_error_setfatal(NULL);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "%s:%d: fatal error:", file, line);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson format, args);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "exiting (due to fatal error in library)");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson } else {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "%s:%d: fatal error: ", file, line);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson vfprintf(stderr, format, args);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fflush(stderr);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 }
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (ns_g_coreok)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 abort();
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 exit(1);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉}
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrewsstatic void
66f51d8678c8fcc7256354b599317f67455120fdMark Andrewslibrary_unexpected_error(const char *file, int line, const char *format,
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrews va_list args) ISC_FORMAT_PRINTF(3, 0);
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson
bd3946db298667e769804b2e978df2d6dcd85e29Mark Andrewsstatic void
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonlibrary_unexpected_error(const char *file, int line, const char *format,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson va_list args)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson{
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Handle isc_error_unexpected() calls from our libraries.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_lctx != NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson NS_LOGMODULE_MAIN, ISC_LOG_ERROR,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "%s:%d: unexpected error:", file, line);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson NS_LOGMODULE_MAIN, ISC_LOG_ERROR,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson format, args);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson } else {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "%s:%d: fatal error: ", file, line);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson vfprintf(stderr, format, args);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fflush(stderr);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstatic void
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonlwresd_usage(void) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "[-d debuglevel]\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson " [-f|-g] [-n number_of_cpus] [-p port] "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "[-P listen-port] [-s]\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson " [-t chrootdir] [-u username] [-i pidfile]\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson " [-m {usage|trace|record|size|mctx}]\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstatic void
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonusage(void) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_lwresdonly) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson lwresd_usage();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson return;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "usage: named [-4|-6] [-c conffile] [-d debuglevel] "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "[-E engine] [-f|-g]\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson " [-n number_of_cpus] [-p port] [-s] "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "[-t chrootdir] [-u username]\n"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson " [-m {usage|trace|record|size|mctx}]\n");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstatic void
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonsave_command_line(int argc, char *argv[]) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson int i;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson char *src;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson char *dst;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson char *eob;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson const char truncated[] = "...";
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_boolean_t quoted = ISC_FALSE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson dst = saved_command_line;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson eob = saved_command_line + sizeof(saved_command_line);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson for (i = 1; i < argc && dst < eob; i++) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson *dst++ = ' ';
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson src = argv[i];
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson while (*src != '\0' && dst < eob) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * This won't perfectly produce a shell-independent
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * pastable command line in all circumstances, but
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * comes close, and for practical purposes will
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * nearly always be fine.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (quoted || isalnum(*src & 0xff) ||
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson *src == '-' || *src == '_' ||
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson *src == '.' || *src == '/') {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson *dst++ = *src++;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson quoted = ISC_FALSE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson } else {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson *dst++ = '\\';
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson quoted = ISC_TRUE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson INSIST(sizeof(saved_command_line) >= sizeof(truncated));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (dst == eob)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson strcpy(eob - sizeof(truncated), truncated);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson else
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson *dst = '\0';
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstatic int
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉parse_int(char *arg, const char *desc) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 char *endp;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 int tmp;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 long int ltmp;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ltmp = strtol(arg, &endp, 10);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 tmp = (int) ltmp;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (*endp != '\0')
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (tmp < 0 || tmp != ltmp)
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_main_earlyfatal("%s '%s' out of range", desc, arg);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 return (tmp);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉}
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉static struct flag_def {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 const char *name;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 unsigned int value;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉} mem_debug_flags[] = {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 { "trace", ISC_MEM_DEBUGTRACE },
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 { "record", ISC_MEM_DEBUGRECORD },
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 { "usage", ISC_MEM_DEBUGUSAGE },
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 { "size", ISC_MEM_DEBUGSIZE },
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 { "mctx", ISC_MEM_DEBUGCTX },
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 { NULL, 0 }
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉};
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstatic void
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson for (;;) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 const struct flag_def *def;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 const char *end = strchr(arg, ',');
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 int arglen;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (end == NULL)
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 end = arg + strlen(arg);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 arglen = end - arg;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 for (def = defs; def->name != NULL; def++) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (arglen == (int)strlen(def->name) &&
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 memcmp(arg, def->name, arglen) == 0) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 *ret |= def->value;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 goto found;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 }
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 }
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 found:
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (*end == '\0')
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 break;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 arg = end + 1;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 }
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉}
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉static void
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉parse_command_line(int argc, char *argv[]) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 int ch;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 int port;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_boolean_t disable6 = ISC_FALSE;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_boolean_t disable4 = ISC_FALSE;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 save_command_line(argc, argv);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_commandline_errprint = ISC_FALSE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson while ((ch = isc_commandline_parse(argc, argv,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "46c:C:d:E:fFgi:lm:n:N:p:P:"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "sS:t:T:U:u:vVx:")) != -1) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson switch (ch) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case '4':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (disable4)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("cannot specify -4 and -6");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (isc_net_probeipv4() != ISC_R_SUCCESS)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("IPv4 not supported by OS");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_net_disableipv6();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson disable6 = ISC_TRUE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case '6':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (disable6)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("cannot specify -4 and -6");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (isc_net_probeipv6() != ISC_R_SUCCESS)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("IPv6 not supported by OS");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_net_disableipv4();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson disable4 = ISC_TRUE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'c':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_conffile = isc_commandline_argument;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson lwresd_g_conffile = isc_commandline_argument;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (lwresd_g_useresolvconf)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("cannot specify -c and -C");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_conffileset = ISC_TRUE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'C':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson lwresd_g_resolvconffile = isc_commandline_argument;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_conffileset)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("cannot specify -c and -C");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson lwresd_g_useresolvconf = ISC_TRUE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'd':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_debuglevel = parse_int(isc_commandline_argument,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "debug level");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'E':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_engine = isc_commandline_argument;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'f':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_foreground = ISC_TRUE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'g':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_foreground = ISC_TRUE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_logstderr = ISC_TRUE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* XXXBEW -i should be removed */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'i':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson lwresd_g_defaultpidfile = isc_commandline_argument;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'l':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_lwresdonly = ISC_TRUE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'm':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson set_flags(isc_commandline_argument, mem_debug_flags,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson &isc_mem_debugging);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'N': /* Deprecated. */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'n':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_cpus = parse_int(isc_commandline_argument,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "number of cpus");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_cpus == 0)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_cpus = 1;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'p':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson port = parse_int(isc_commandline_argument, "port");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (port < 1 || port > 65535)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("port '%s' out of range",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_commandline_argument);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_port = port;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* XXXBEW Should -P be removed? */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'P':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson port = parse_int(isc_commandline_argument, "port");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (port < 1 || port > 65535)
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson ns_main_earlyfatal("port '%s' out of range",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_commandline_argument);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson lwresd_g_listenport = port;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 's':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* XXXRTH temporary syntax */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson want_stats = ISC_TRUE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'S':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson maxsocks = parse_int(isc_commandline_argument,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "max number of sockets");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 't':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* XXXJAB should we make a copy? */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_chrootdir = isc_commandline_argument;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'T': /* NOT DOCUMENTED */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * clienttest: make clients single shot with their
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * own memory context.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * delay=xxxx: delay client responses by xxxx ms to
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * simulate remote servers.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (!strcmp(isc_commandline_argument, "clienttest"))
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ns_g_clienttest = ISC_TRUE;
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews else if (!strcmp(isc_commandline_argument, "nosoa"))
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_nosoa = ISC_TRUE;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 else if (!strcmp(isc_commandline_argument, "noaa"))
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_g_noaa = ISC_TRUE;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 else if (!strcmp(isc_commandline_argument, "maxudp512"))
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 maxudp = 512;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 else if (!strcmp(isc_commandline_argument, "maxudp1460"))
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 maxudp = 1460;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 else if (!strcmp(isc_commandline_argument, "dropedns"))
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_g_dropedns = ISC_TRUE;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 else if (!strcmp(isc_commandline_argument, "noedns"))
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_g_noedns = ISC_TRUE;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 else if (!strncmp(isc_commandline_argument,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "maxudp=", 7))
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 maxudp = atoi(isc_commandline_argument + 7);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 else if (!strncmp(isc_commandline_argument,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "delay=", 6))
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_delay = atoi(isc_commandline_argument + 6);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson else if (!strcmp(isc_commandline_argument, "nosyslog"))
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_nosyslog = ISC_TRUE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson else
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fprintf(stderr, "unknown -T flag '%s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_commandline_argument);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'U':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_udpdisp = parse_int(isc_commandline_argument,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "number of UDP listeners "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "per interface");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'u':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_username = isc_commandline_argument;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson break;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'v':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson printf("BIND %s\n", ns_g_version);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson exit(0);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'V':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson printf("BIND %s <id:%s> built with %s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_version, ns_g_srcid, ns_g_configargs);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef OPENSSL
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson printf("using OpenSSL version: %s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson OPENSSL_VERSION_TEXT);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef HAVE_LIBXML2
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson printf("using libxml2 version: %s\n",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson LIBXML_DOTTED_VERSION);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson exit(0);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case 'F':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* Reserved for FIPS mode */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* FALLTHROUGH */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case '?':
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson usage();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (isc_commandline_option == '?')
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson exit(0);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("unknown option '-%c'",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_commandline_option);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* FALLTHROUGH */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson default:
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("parsing options returned %d", ch);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson argc -= isc_commandline_index;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson argv += isc_commandline_index;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson POST(argv);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (argc > 0) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson usage();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("extra command line arguments");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstatic isc_result_t
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssoncreate_managers(void) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_result_t result;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson unsigned int socks;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef ISC_PLATFORM_USETHREADS
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_cpus == 0)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_cpus = ns_g_cpus_detected;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ISC_LOG_INFO, "found %u CPU%s, using %u worker thread%s",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_cpus_detected, ns_g_cpus_detected == 1 ? "" : "s",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_cpus, ns_g_cpus == 1 ? "" : "s");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#else
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_cpus = 1;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef WIN32
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_udpdisp = 1;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#else
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_udpdisp == 0 || ns_g_udpdisp > ns_g_cpus)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_udpdisp = ns_g_cpus;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ISC_LOG_INFO, "using %u UDP listener%s per interface",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_udpdisp, ns_g_udpdisp == 1 ? "" : "s");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = isc_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (result != ISC_R_SUCCESS) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson UNEXPECTED_ERROR(__FILE__, __LINE__,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "isc_taskmgr_create() failed: %s",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_result_totext(result));
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews return (ISC_R_UNEXPECTED);
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews }
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews result = isc_timermgr_create(ns_g_mctx, &ns_g_timermgr);
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews if (result != ISC_R_SUCCESS) {
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__,
8ac1acc30d0f405222ffa7b2b93131d9d4e18599Mark Andrews "isc_timermgr_create() failed: %s",
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrews isc_result_totext(result));
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrews return (ISC_R_UNEXPECTED);
e2cf0e8ff9ff37121518af5b34b9e4de7abbb47cMark Andrews }
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson result = isc_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);
81e805888bcd4bd2a6d5c986fade6ffdf7d88a54Andreas Gustafsson if (result != ISC_R_SUCCESS) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 UNEXPECTED_ERROR(__FILE__, __LINE__,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "isc_socketmgr_create() failed: %s",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_result_totext(result));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 return (ISC_R_UNEXPECTED);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 }
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc__socketmgr_maxudp(ns_g_socketmgr, maxudp);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 result = isc_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (result == ISC_R_SUCCESS) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews NS_LOGMODULE_SERVER,
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews ISC_LOG_INFO, "using up to %u sockets", socks);
66f51d8678c8fcc7256354b599317f67455120fdMark Andrews }
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 result = isc_entropy_create(ns_g_mctx, &ns_g_entropy);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 UNEXPECTED_ERROR(__FILE__, __LINE__,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "isc_entropy_create() failed: %s",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_result_totext(result));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 return (ISC_R_UNEXPECTED);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 }
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 result = isc_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 UNEXPECTED_ERROR(__FILE__, __LINE__,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "isc_hash_create() failed: %s",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_result_totext(result));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 return (ISC_R_UNEXPECTED);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 }
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 return (ISC_R_SUCCESS);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉}
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉static void
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉destroy_managers(void) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ns_lwresd_shutdown();
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_entropy_detach(&ns_g_entropy);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (ns_g_fallbackentropy != NULL)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_entropy_detach(&ns_g_fallbackentropy);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 /*
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * isc_taskmgr_destroy() will block until all tasks have exited,
bd3946db298667e769804b2e978df2d6dcd85e29Mark Andrews */
bd3946db298667e769804b2e978df2d6dcd85e29Mark Andrews isc_taskmgr_destroy(&ns_g_taskmgr);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_timermgr_destroy(&ns_g_timermgr);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_socketmgr_destroy(&ns_g_socketmgr);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * isc_hash_destroy() cannot be called as long as a resolver may be
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * running. Calling this after isc_taskmgr_destroy() ensures the
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * call is safe.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_hash_destroy();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstatic void
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssondump_symboltable() {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson int i;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_result_t result;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson const char *fname;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson const void *addr;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (isc__backtrace_nsymbols == 0)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson return;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (!isc_log_wouldlog(ns_g_lctx, ISC_LOG_DEBUG(99)))
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson return;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ISC_LOG_DEBUG(99), "Symbol table:");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson for (i = 0, result = ISC_R_SUCCESS; result == ISC_R_SUCCESS; i++) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson addr = NULL;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson fname = NULL;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = isc_backtrace_getsymbolfromindex(i, &addr, &fname);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (result == ISC_R_SUCCESS) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson NS_LOGMODULE_MAIN, ISC_LOG_DEBUG(99),
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "[%d] %p %s", i, addr, fname);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstatic void
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonsetup(void) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_result_t result;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_resourcevalue_t old_openfiles;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef HAVE_LIBSCF
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson char *instance = NULL;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Get the user and group information before changing the root
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * directory, so the administrator does not need to keep a copy
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * of the user and group databases in the chroot'ed environment.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_os_inituserinfo(ns_g_username);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Initialize time conversion information
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_os_tzset();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_os_opendevnull();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef HAVE_LIBSCF
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* Check if named is under smf control, before chroot. */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = ns_smf_get_instance(&instance, 0, ns_g_mctx);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* We don't care about instance, just check if we got one. */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (result == ISC_R_SUCCESS)
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_smf_got_instance = 1;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 else
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_smf_got_instance = 0;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (instance != NULL)
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_mem_free(ns_g_mctx, instance);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉#endif /* HAVE_LIBSCF */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉#ifdef PATH_RANDOMDEV
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 /*
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Initialize system's random device as fallback entropy source
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * if running chroot'ed.
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_chrootdir != NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = isc_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (result != ISC_R_SUCCESS)
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_main_earlyfatal("isc_entropy_create() failed: %s",
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_result_totext(result));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 result = isc_entropy_createfilesource(ns_g_fallbackentropy,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson PATH_RANDOMDEV);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (result != ISC_R_SUCCESS) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_main_earlywarning("could not open pre-chroot "
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "entropy source %s: %s",
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 PATH_RANDOMDEV,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_result_totext(result));
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_entropy_detach(&ns_g_fallbackentropy);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 }
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 }
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉#endif
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef ISC_PLATFORM_USETHREADS
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 /*
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Check for the number of cpu's before ns_os_chroot().
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_g_cpus_detected = isc_os_ncpus();
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉#endif
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_os_chroot(ns_g_chrootdir);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * For operating systems which have a capability mechanism, now
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson * is the time to switch to minimal privs and change our user id.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * On traditional UNIX systems, this call will be a no-op, and we
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * will change the user ID after reading the config file the first
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * time. (We need to read the config file to know which possibly
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * privileged ports to bind() to.)
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_os_minprivs();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = ns_log_init(ISC_TF(ns_g_username != NULL));
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_main_earlyfatal("ns_log_init() failed: %s",
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_result_totext(result));
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 /*
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Now is the time to daemonize (if we're not running in the
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * foreground). We waited until now because we wanted to get
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * a valid logging context setup. We cannot daemonize any later,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * because calling create_managers() will create threads, which
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * would be lost after fork().
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (!ns_g_foreground)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_os_daemonize();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * We call isc_app_start() here as some versions of FreeBSD's fork()
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * destroys all the signal handling it sets up.
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 result = isc_app_start();
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_main_earlyfatal("isc_app_start() failed: %s",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_result_totext(result));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ISC_LOG_NOTICE, "starting BIND %s%s", ns_g_version,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 saved_command_line);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ISC_LOG_NOTICE, "built with %s", ns_g_configargs);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ISC_LOG_NOTICE,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "----------------------------------------------------");
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ISC_LOG_NOTICE,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "BIND 9 is maintained by Internet Systems Consortium,");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ISC_LOG_NOTICE,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "Inc. (ISC), a non-profit 501(c)(3) public-benefit ");
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ISC_LOG_NOTICE,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "corporation. Support and training for BIND 9 are ");
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ISC_LOG_NOTICE,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "available at https://www.isc.org/support");
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ISC_LOG_NOTICE,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "----------------------------------------------------");
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 dump_symboltable();
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 /*
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Get the initial resource limits.
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 (void)isc_resource_getlimit(isc_resource_stacksize,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 &ns_g_initstacksize);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 (void)isc_resource_getlimit(isc_resource_datasize,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 &ns_g_initdatasize);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 (void)isc_resource_getlimit(isc_resource_coresize,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 &ns_g_initcoresize);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 (void)isc_resource_getlimit(isc_resource_openfiles,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 &ns_g_initopenfiles);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 /*
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * System resources cannot effectively be tuned on some systems.
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 * Raise the limit in such cases for safety.
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 old_openfiles = ns_g_initopenfiles;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 ns_os_adjustnofile();
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 (void)isc_resource_getlimit(isc_resource_openfiles,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 &ns_g_initopenfiles);
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 if (old_openfiles != ns_g_initopenfiles) {
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 NS_LOGMODULE_MAIN, ISC_LOG_NOTICE,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "adjusted limit on open files from "
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "%" ISC_PRINT_QUADFORMAT "u to "
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "%" ISC_PRINT_QUADFORMAT "u",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 old_openfiles, ns_g_initopenfiles);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 }
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 /*
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * If the named configuration filename is relative, prepend the current
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * directory's name before possibly changing to another directory.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (! isc_file_isabsolute(ns_g_conffile)) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 result = isc_file_absolutepath(ns_g_conffile,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 absolute_conffile,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 sizeof(absolute_conffile));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ns_main_earlyfatal("could not construct absolute path "
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "of configuration file: %s",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_result_totext(result));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ns_g_conffile = absolute_conffile;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 }
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 /*
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * Record the server's startup time.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 result = isc_time_now(&ns_g_boottime);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ns_main_earlyfatal("isc_time_now() failed: %s",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_result_totext(result));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 result = create_managers();
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ns_main_earlyfatal("create_managers() failed: %s",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_result_totext(result));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ns_builtin_init();
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 /*
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * Add calls to register sdb drivers here.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 /* xxdb_init(); */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉#ifdef ISC_DLZ_DLOPEN
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 /*
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * Register the DLZ "dlopen" driver.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 result = dlz_dlopen_init(ns_g_mctx);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ns_main_earlyfatal("dlz_dlopen_init() failed: %s",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_result_totext(result));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉#endif
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉#if CONTRIB_DLZ
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 /*
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * Register any other contributed DLZ drivers.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 result = dlz_drivers_init();
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 ns_main_earlyfatal("dlz_drivers_init() failed: %s",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 isc_result_totext(result));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_server_create(ns_g_mctx, &ns_g_server);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonstatic void
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssoncleanup(void) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson destroy_managers();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_server_destroy(&ns_g_server);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_builtin_deinit();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Add calls to unregister sdb drivers here.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* xxdb_clear(); */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef CONTRIB_DLZ
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Unregister contributed DLZ drivers.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson dlz_drivers_clear();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef ISC_DLZ_DLOPEN
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Unregister "dlopen" DLZ driver.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson dlz_dlopen_clear();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson dns_name_destroy();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ISC_LOG_NOTICE, "exiting");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_log_shutdown();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉static char *memstats = NULL;
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉void
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉ns_main_setmemstats(const char *filename) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Caller has to ensure locking.
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 */
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (memstats != NULL) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 free(memstats);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 memstats = NULL;
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (filename == NULL)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson return;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson memstats = malloc(strlen(filename) + 1);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (memstats)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson strcpy(memstats, filename);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef HAVE_LIBSCF
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson/*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Get FMRI for the named process.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonisc_result_t
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonns_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson scf_handle_t *h = NULL;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson int namelen;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson char *instance;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 REQUIRE(ins_name != NULL && *ins_name == NULL);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (debug)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 UNEXPECTED_ERROR(__FILE__, __LINE__,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "scf_handle_create() failed: %s",
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 scf_strerror(scf_error()));
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 return (ISC_R_FAILURE);
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 }
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (scf_handle_bind(h) == -1) {
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 if (debug)
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 UNEXPECTED_ERROR(__FILE__, __LINE__,
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 "scf_handle_bind() failed: %s",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson scf_strerror(scf_error()));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson scf_handle_destroy(h);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson return (ISC_R_FAILURE);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((namelen = scf_myname(h, NULL, 0)) == -1) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (debug)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson UNEXPECTED_ERROR(__FILE__, __LINE__,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "scf_myname() failed: %s",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson scf_strerror(scf_error()));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson scf_handle_destroy(h);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson return (ISC_R_FAILURE);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if ((instance = isc_mem_allocate(mctx, namelen + 1)) == NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson UNEXPECTED_ERROR(__FILE__, __LINE__,
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "ns_smf_get_instance memory "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "allocation failed: %s",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_result_totext(ISC_R_NOMEMORY));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson scf_handle_destroy(h);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson return (ISC_R_FAILURE);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (scf_myname(h, instance, namelen + 1) == -1) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (debug)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson UNEXPECTED_ERROR(__FILE__, __LINE__,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "scf_myname() failed: %s",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson scf_strerror(scf_error()));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson scf_handle_destroy(h);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_mem_free(mctx, instance);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson return (ISC_R_FAILURE);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson scf_handle_destroy(h);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson *ins_name = instance;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson return (ISC_R_SUCCESS);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif /* HAVE_LIBSCF */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonint
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonmain(int argc, char *argv[]) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_result_t result;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef HAVE_LIBSCF
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson char *instance = NULL;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Record version in core image.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * strings named.core | grep "named version:"
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson strlcat(version,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#if defined(NO_VERSION_DATE) || !defined(__DATE__)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "named version: BIND " VERSION " <" SRCID ">",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#else
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "named version: BIND " VERSION " <" SRCID "> (" __DATE__ ")",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson sizeof(version));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = isc_file_progname(*argv, program_name, sizeof(program_name));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (result != ISC_R_SUCCESS)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("program name too long");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (strcmp(program_name, "lwresd") == 0)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_lwresdonly = ISC_TRUE;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (result != ISC_R_SUCCESS)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("failed to build internal symbol table");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_assertion_setcallback(assertion_failed);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_error_setfatal(library_fatal_error);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_error_setunexpected(library_unexpected_error);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_os_init(program_name);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson dns_result_register();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson dst_result_register();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isccc_result_register();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson parse_command_line(argc, argv);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
b89095ba15e9163f2bacc46239d8f69d1a2b9ad3Tatuya JINMEI 神明達哉 * Warn about common configuration error.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_chrootdir != NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson int len = strlen(ns_g_chrootdir);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson (ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlywarning("config filename (-c %s) contains "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "chroot path (-t %s)",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_g_conffile, ns_g_chrootdir);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = isc_mem_create(0, 0, &ns_g_mctx);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (result != ISC_R_SUCCESS)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_earlyfatal("isc_mem_create() failed: %s",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_result_totext(result));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_mem_setname(ns_g_mctx, "main", NULL);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson setup();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Start things running and then wait for a shutdown request
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * or reload.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson do {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = isc_app_run();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (result == ISC_R_RELOAD) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_server_reloadwanted(ns_g_server);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson } else if (result != ISC_R_SUCCESS) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson UNEXPECTED_ERROR(__FILE__, __LINE__,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "isc_app_run(): %s",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_result_totext(result));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /*
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Force exit.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = ISC_R_SUCCESS;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson } while (result != ISC_R_SUCCESS);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#ifdef HAVE_LIBSCF
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_smf_want_disable == 1) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = ns_smf_get_instance(&instance, 1, ns_g_mctx);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (result == ISC_R_SUCCESS && instance != NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (smf_disable_instance(instance, 0) != 0)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson UNEXPECTED_ERROR(__FILE__, __LINE__,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "smf_disable_instance() "
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "failed for %s : %s",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson instance,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson scf_strerror(scf_error()));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (instance != NULL)
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_mem_free(ns_g_mctx, instance);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#endif /* HAVE_LIBSCF */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson cleanup();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (want_stats) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_mem_stats(ns_g_mctx, stdout);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_mutex_stats(stdout);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ns_g_memstatistics && memstats != NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson FILE *fp = NULL;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = isc_stdio_open(memstats, "w", &fp);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (result == ISC_R_SUCCESS) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_mem_stats(ns_g_mctx, fp);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_mutex_stats(fp);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_stdio_close(fp);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson }
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_mem_destroy(&ns_g_mctx);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_mem_checkdestroyed(stderr);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_main_setmemstats(NULL);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson isc_app_finish();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_os_closedevnull();
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_os_shutdown();
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson return (0);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson}
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson