main.c revision 6979ebf549b9c0ccd115bbf8c0d905600086f292
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 2004-2014 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 1999-2003 Internet Software Consortium.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * Permission to use, copy, modify, and/or distribute this software for any
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * purpose with or without fee is hereby granted, provided that the above
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
15a44745412679c30a6d022733925af70a38b715David Lawrence * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15a44745412679c30a6d022733925af70a38b715David Lawrence * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15a44745412679c30a6d022733925af70a38b715David Lawrence * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15a44745412679c30a6d022733925af70a38b715David Lawrence * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PERFORMANCE OF THIS SOFTWARE.
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson * Defining NS_MAIN provides storage declarations (rather than extern)
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson * for variables in named/globals.h.
1e2749dba8aae3233b8962f1efe15385e92a77d9Brian Wellington#include <named/globals.h> /* Explicit, though named/log.h includes it. */
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson * Include header files for database drivers here.
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson/* #include "xxdb.h" */
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson * Include contributed DLZ drivers if appropriate.
4755b174df8221dff7e872f21d42b3572a74bf2fAndreas Gustafsson * The maximum number of stack frames to dump on assertion failure.
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafssonstatic isc_boolean_t want_stats = ISC_FALSE;
020ebf119089ef68070d6a0df2def3142f1eeff4Brian Wellingtonstatic char program_name[ISC_DIR_NAMEMAX] = "named";
020ebf119089ef68070d6a0df2def3142f1eeff4Brian Wellingtonstatic char absolute_conffile[ISC_DIR_PATHMAX];
020ebf119089ef68070d6a0df2def3142f1eeff4Brian Wellingtonstatic unsigned int maxsocks = 0;
020ebf119089ef68070d6a0df2def3142f1eeff4Brian Wellingtonstatic int maxudp = 0;
020ebf119089ef68070d6a0df2def3142f1eeff4Brian Wellingtonns_main_earlywarning(const char *format, ...) {
020ebf119089ef68070d6a0df2def3142f1eeff4Brian Wellington isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellingtonns_main_earlyfatal(const char *format, ...) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington "exiting (due to early fatal error)");
ff7b9eede951083d1f8a1ad919611659c3e20b34Brian Wellingtonassertion_failed(const char *file, int line, isc_assertiontype_t type,
ff7b9eede951083d1f8a1ad919611659c3e20b34Brian Wellington const char *cond) ISC_PLATFORM_NORETURN_POST;
ff7b9eede951083d1f8a1ad919611659c3e20b34Brian Wellingtonassertion_failed(const char *file, int line, isc_assertiontype_t type,
ff7b9eede951083d1f8a1ad919611659c3e20b34Brian Wellington * Handle assertion failures.
f2338a0d6aa0327372eb20ab5dc29502bc8c71efBrian Wellington * Reset the assertion callback in case it is the log
f2338a0d6aa0327372eb20ab5dc29502bc8c71efBrian Wellington * routines causing the assertion.
f2338a0d6aa0327372eb20ab5dc29502bc8c71efBrian Wellington result = isc_backtrace_gettrace(tracebuf, BACKTRACE_MAXFRAME,
f2338a0d6aa0327372eb20ab5dc29502bc8c71efBrian Wellington if (result == ISC_R_SUCCESS && nframes > 0)
f2338a0d6aa0327372eb20ab5dc29502bc8c71efBrian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington isc_assertion_typetotext(type), cond, logsuffix);
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington for (i = 0; i < nframes; i++) {
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington unsigned long offset;
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington result = isc_backtrace_getsymbol(tracebuf[i],
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "#%d %p in %s()+0x%lx", i,
49c8a96fba8d85810d470fdc7dd3388f0c767c9eBrian Wellington "#%d %p in ??", i,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington "exiting (due to assertion failure)");
ac335315cddc0a42b9235001197dcf719ae737b6Brian Wellington file, line, isc_assertion_typetotext(type), cond);
70d950d16e9623fec1bc89b158047de507071ce3Brian Wellingtonlibrary_fatal_error(const char *file, int line, const char *format,
26a5f97dd8770ced729025488091b77d8beb0ab6Brian WellingtonISC_FORMAT_PRINTF(3, 0) ISC_PLATFORM_NORETURN_POST;
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellingtonlibrary_fatal_error(const char *file, int line, const char *format,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * Handle isc_error_fatal() calls from our libraries.
f2338a0d6aa0327372eb20ab5dc29502bc8c71efBrian Wellington * Reset the error callback in case it is the log
f2338a0d6aa0327372eb20ab5dc29502bc8c71efBrian Wellington * routines causing the assertion.
ddbc279e7b6a2d6ba682e60ca12956406030054bBrian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
a00c5e2151cc03c06bae5cdd3b40a5de05664059Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
a00c5e2151cc03c06bae5cdd3b40a5de05664059Brian Wellington "exiting (due to fatal error in library)");
a00c5e2151cc03c06bae5cdd3b40a5de05664059Brian Wellington fprintf(stderr, "%s:%d: fatal error: ", file, line);
9d967288c374ad4988334cd575ba1cca2b69f70eBrian Wellingtonlibrary_unexpected_error(const char *file, int line, const char *format,
a00c5e2151cc03c06bae5cdd3b40a5de05664059Brian Wellingtonlibrary_unexpected_error(const char *file, int line, const char *format,
5c29047792191d6141f69b2684314d0b762fedebBrian Wellington * Handle isc_error_unexpected() calls from our libraries.
a00c5e2151cc03c06bae5cdd3b40a5de05664059Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
a00c5e2151cc03c06bae5cdd3b40a5de05664059Brian Wellington isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
a00c5e2151cc03c06bae5cdd3b40a5de05664059Brian Wellington fprintf(stderr, "%s:%d: fatal error: ", file, line);
af602636644fdfaabc331bd926b0aabb9432e152Brian Wellington "usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] "
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington "[-d debuglevel]\n"
af602636644fdfaabc331bd926b0aabb9432e152Brian Wellington " [-f|-g] [-n number_of_cpus] [-p port] "
af602636644fdfaabc331bd926b0aabb9432e152Brian Wellington "[-P listen-port] [-s]\n"
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington " [-t chrootdir] [-u username] [-i pidfile]\n"
af602636644fdfaabc331bd926b0aabb9432e152Brian Wellington " [-m {usage|trace|record|size|mctx}]\n");
af602636644fdfaabc331bd926b0aabb9432e152Brian Wellington "usage: named [-4|-6] [-c conffile] [-d debuglevel] "
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "[-E engine] [-f|-g]\n"
100d0d2ec64ab1a85f8c0d2da9b47ae411a10b21Brian Wellington " [-n number_of_cpus] [-p port] [-s] "
af602636644fdfaabc331bd926b0aabb9432e152Brian Wellington "[-t chrootdir] [-u username]\n"
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington " [-m {usage|trace|record|size|mctx}]\n");
100d0d2ec64ab1a85f8c0d2da9b47ae411a10b21Brian Wellington eob = saved_command_line + sizeof(saved_command_line);
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington * This won't perfectly produce a shell-independent
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington * pastable command line in all circumstances, but
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington * comes close, and for practical purposes will
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington * nearly always be fine.
1e2749dba8aae3233b8962f1efe15385e92a77d9Brian Wellington INSIST(sizeof(saved_command_line) >= sizeof(truncated));
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington strcpy(eob - sizeof(truncated), truncated);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);
a00c5e2151cc03c06bae5cdd3b40a5de05664059Brian Wellington ns_main_earlyfatal("%s '%s' out of range", desc, arg);
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellingtonstatic struct flag_def {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence unsigned int value;
7e8dd00fce7057d1da8158b65395a09ced43a892Brian Wellingtonset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {
7e8dd00fce7057d1da8158b65395a09ced43a892Brian Wellington for (def = defs; def->name != NULL; def++) {
7e8dd00fce7057d1da8158b65395a09ced43a892Brian Wellington ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);
1e2749dba8aae3233b8962f1efe15385e92a77d9Brian Wellington const char *p;
1e2749dba8aae3233b8962f1efe15385e92a77d9Brian Wellington /* PLEASE keep options synchronized when main is hooked! */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#define CMDLINE_FLAGS "46c:C:d:D:E:fFgi:lL:m:n:N:p:P:sS:t:T:U:u:vVx:"
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington ns_main_earlyfatal("cannot specify -4 and -6");
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence ns_main_earlyfatal("IPv4 not supported by OS");
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington ns_main_earlyfatal("cannot specify -4 and -6");
fe0e3c7707580da885bb6819e4f307986eb60cd0Brian Wellington ns_main_earlyfatal("IPv6 not supported by OS");
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington lwresd_g_conffile = isc_commandline_argument;
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington ns_main_earlyfatal("cannot specify -c and -C");
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington lwresd_g_resolvconffile = isc_commandline_argument;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence ns_main_earlyfatal("cannot specify -c and -C");
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington ns_g_debuglevel = parse_int(isc_commandline_argument,
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington "debug level");
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /* Descriptive comment for 'ps'. */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington /* XXXBEW -i should be removed */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lwresd_g_defaultpidfile = isc_commandline_argument;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington set_flags(isc_commandline_argument, mem_debug_flags,
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington ns_g_cpus = parse_int(isc_commandline_argument,
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence "number of cpus");
7e8dd00fce7057d1da8158b65395a09ced43a892Brian Wellington port = parse_int(isc_commandline_argument, "port");
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington ns_main_earlyfatal("port '%s' out of range",
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington /* XXXBEW Should -P be removed? */
0c70ab306505d89983186e9f8bb8647de55b5d04Mark Andrews port = parse_int(isc_commandline_argument, "port");
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington /* XXXRTH temporary syntax */
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence maxsocks = parse_int(isc_commandline_argument,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "max number of sockets");
7e8dd00fce7057d1da8158b65395a09ced43a892Brian Wellington /* XXXJAB should we make a copy? */
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington * force the server to behave (or misbehave) in
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * specified ways for testing purposes.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * clienttest: make clients single shot with their
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * own memory context.
7e8dd00fce7057d1da8158b65395a09ced43a892Brian Wellington * delay=xxxx: delay client responses by xxxx ms to
7e8dd00fce7057d1da8158b65395a09ced43a892Brian Wellington * simulate remote servers.
7e8dd00fce7057d1da8158b65395a09ced43a892Brian Wellington * dscp=x: check that dscp values are as
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington * expected and assert otherwise.
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington if (!strcmp(isc_commandline_argument, "clienttest"))
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington else if (!strcmp(isc_commandline_argument, "nosoa"))
81ab85fd39c3f6c781ecac725d830364a311479dBrian Wellington else if (!strcmp(isc_commandline_argument, "noaa"))
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington else if (!strcmp(isc_commandline_argument, "maxudp512"))
7e8dd00fce7057d1da8158b65395a09ced43a892Brian Wellington else if (!strcmp(isc_commandline_argument, "maxudp1460"))
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington else if (!strcmp(isc_commandline_argument, "dropedns"))
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington else if (!strcmp(isc_commandline_argument, "noedns"))
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington else if (!strncmp(isc_commandline_argument,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington maxudp = atoi(isc_commandline_argument + 7);
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington else if (!strncmp(isc_commandline_argument,
1e2749dba8aae3233b8962f1efe15385e92a77d9Brian Wellington ns_g_delay = atoi(isc_commandline_argument + 6);
7e8dd00fce7057d1da8158b65395a09ced43a892Brian Wellington else if (!strcmp(isc_commandline_argument, "nosyslog"))
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington else if (!strcmp(isc_commandline_argument, "nonearest"))
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington else if (!strncmp(isc_commandline_argument, "dscp=", 5))
7e8dd00fce7057d1da8158b65395a09ced43a892Brian Wellington ns_g_udpdisp = parse_int(isc_commandline_argument,
0dc4e6a6aef01175b8cdd71cb757f09ba1e69c49Brian Wellington "number of UDP listeners "
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington "per interface");
7e8dd00fce7057d1da8158b65395a09ced43a892Brian Wellington printf("%s %s", ns_g_product, ns_g_version);
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington printf("%s %s", ns_g_product, ns_g_version);
d1cbf714097e900ed1703529584d3e1a50e8a4a8Brian Wellington printf(" <id:%s> built by %s with %s\n", ns_g_srcid,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington printf("compiled by CLANG %s\n", __VERSION__);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#if defined(__ICC) || defined(__INTEL_COMPILER)
8c56932f9a3dc252ab13a529a75f75966468a7c1Andreas Gustafsson printf("compiled by ICC %s\n", __VERSION__);
0dc4e6a6aef01175b8cdd71cb757f09ba1e69c49Brian Wellington printf("compiled by GCC %s\n", __VERSION__);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington printf("compiled by Solaris Studio %x\n", __SUNPRO_C);
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington /* Reserved for FIPS mode */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington /* FALLTHROUGH */
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington p = strchr(CMDLINE_FLAGS, isc_commandline_option);
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington ns_main_earlyfatal("option '-%c' requires "
3b2efab212088496d5588ca5ed2d802c72d21a08Brian Wellington "an argument",
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington /* FALLTHROUGH */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington ns_main_earlyfatal("parsing options returned %d", ch);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington ns_main_earlyfatal("extra command line arguments");
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence ISC_LOG_INFO, "found %u CPU%s, using %u worker thread%s",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence ns_g_cpus_detected, ns_g_cpus_detected == 1 ? "" : "s",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington ISC_LOG_INFO, "using %u UDP listener%s per interface",
fe0e3c7707580da885bb6819e4f307986eb60cd0Brian Wellington ns_g_udpdisp, ns_g_udpdisp == 1 ? "" : "s");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = isc_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "isc_taskmgr_create() failed: %s",
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington result = isc_timermgr_create(ns_g_mctx, &ns_g_timermgr);
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington "isc_timermgr_create() failed: %s",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence result = isc_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "isc_socketmgr_create() failed: %s",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc__socketmgr_maxudp(ns_g_socketmgr, maxudp);
020ebf119089ef68070d6a0df2def3142f1eeff4Brian Wellington result = isc_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington ISC_LOG_INFO, "using up to %u sockets", socks);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence result = isc_entropy_create(ns_g_mctx, &ns_g_entropy);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "isc_entropy_create() failed: %s",
3b2efab212088496d5588ca5ed2d802c72d21a08Brian Wellington result = isc_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);
3b2efab212088496d5588ca5ed2d802c72d21a08Brian Wellington "isc_hash_create() failed: %s",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * isc_taskmgr_destroy() will block until all tasks have exited,
564c1b8f42d33a66c0f5c67d66bf0cd063c8b047Brian Wellington * isc_hash_destroy() cannot be called as long as a resolver may be
5ea0d11ca45bfd1ea9db8db07f18fbb02f500661Brian Wellington * running. Calling this after isc_taskmgr_destroy() ensures the
564c1b8f42d33a66c0f5c67d66bf0cd063c8b047Brian Wellington * call is safe.
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence if (!isc_log_wouldlog(ns_g_lctx, ISC_LOG_DEBUG(99)))
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington for (i = 0, result = ISC_R_SUCCESS; result == ISC_R_SUCCESS; i++) {
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington result = isc_backtrace_getsymbolfromindex(i, &addr, &fname);
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence unsigned int i;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington /* Make sure the lists are in sync */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington (sizeof(scmp_syscall_names) / sizeof(const char *)));
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "libseccomp activation failed");
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence for (i = 0 ; i < sizeof(scmp_syscalls)/sizeof(*(scmp_syscalls)); i++) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington ret = seccomp_rule_add(ctx, SCMP_ACT_ALLOW,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "libseccomp rule failed: %s",
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "added libseccomp rule: %s",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "libseccomp unable to load filter");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "libseccomp sandboxing active");
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence * Release filter in ctx. Filters already loaded are not
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#endif /* HAVE_LIBSECCOMP */
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington * Get the user and group information before changing the root
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington * directory, so the administrator does not need to keep a copy
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence * of the user and group databases in the chroot'ed environment.
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington * Initialize time conversion information
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington /* Check if named is under smf control, before chroot. */
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington result = ns_smf_get_instance(&instance, 0, ns_g_mctx);
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington /* We don't care about instance, just check if we got one. */
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington#endif /* HAVE_LIBSCF */
1e2749dba8aae3233b8962f1efe15385e92a77d9Brian Wellington * Initialize system's random device as fallback entropy source
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * if running chroot'ed.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = isc_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington ns_main_earlyfatal("isc_entropy_create() failed: %s",
5ea0d11ca45bfd1ea9db8db07f18fbb02f500661Brian Wellington result = isc_entropy_createfilesource(ns_g_fallbackentropy,
5ea0d11ca45bfd1ea9db8db07f18fbb02f500661Brian Wellington ns_main_earlywarning("could not open pre-chroot "
5ea0d11ca45bfd1ea9db8db07f18fbb02f500661Brian Wellington "entropy source %s: %s",
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington * Check for the number of cpu's before ns_os_chroot().
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * For operating systems which have a capability mechanism, now
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * is the time to switch to minimal privs and change our user id.
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * On traditional UNIX systems, this call will be a no-op, and we
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews * will change the user ID after reading the config file the first
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * time. (We need to read the config file to know which possibly
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * privileged ports to bind() to.)
ac335315cddc0a42b9235001197dcf719ae737b6Brian Wellington result = ns_log_init(ISC_TF(ns_g_username != NULL));
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington ns_main_earlyfatal("ns_log_init() failed: %s",
af602636644fdfaabc331bd926b0aabb9432e152Brian Wellington * Now is the time to daemonize (if we're not running in the
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * foreground). We waited until now because we wanted to get
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * a valid logging context setup. We cannot daemonize any later,
fe0e3c7707580da885bb6819e4f307986eb60cd0Brian Wellington * because calling create_managers() will create threads, which
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * would be lost after fork().
809fdfba224a83fcc5a8ae4394cf2a477d13dc91Brian Wellington * We call isc_app_start() here as some versions of FreeBSD's fork()
809fdfba224a83fcc5a8ae4394cf2a477d13dc91Brian Wellington * destroys all the signal handling it sets up.
809fdfba224a83fcc5a8ae4394cf2a477d13dc91Brian Wellington ns_main_earlyfatal("isc_app_start() failed: %s",
809fdfba224a83fcc5a8ae4394cf2a477d13dc91Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews ISC_LOG_NOTICE, "starting %s %s%s", ns_g_product,
809fdfba224a83fcc5a8ae4394cf2a477d13dc91Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
809fdfba224a83fcc5a8ae4394cf2a477d13dc91Brian Wellington ISC_LOG_NOTICE, "built with %s", ns_g_configargs);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington "----------------------------------------------------");
fe0e3c7707580da885bb6819e4f307986eb60cd0Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
809fdfba224a83fcc5a8ae4394cf2a477d13dc91Brian Wellington "BIND 9 is maintained by Internet Systems Consortium,");
fe0e3c7707580da885bb6819e4f307986eb60cd0Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington "Inc. (ISC), a non-profit 501(c)(3) public-benefit ");
809fdfba224a83fcc5a8ae4394cf2a477d13dc91Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "corporation. Support and training for BIND 9 are ");
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
af602636644fdfaabc331bd926b0aabb9432e152Brian Wellington "available at https://www.isc.org/support");
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington "----------------------------------------------------");
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * Get the initial resource limits.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (void)isc_resource_getlimit(isc_resource_stacksize,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (void)isc_resource_getlimit(isc_resource_datasize,
564c1b8f42d33a66c0f5c67d66bf0cd063c8b047Brian Wellington (void)isc_resource_getlimit(isc_resource_coresize,
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington (void)isc_resource_getlimit(isc_resource_openfiles,
564c1b8f42d33a66c0f5c67d66bf0cd063c8b047Brian Wellington * System resources cannot effectively be tuned on some systems.
564c1b8f42d33a66c0f5c67d66bf0cd063c8b047Brian Wellington * Raise the limit in such cases for safety.
564c1b8f42d33a66c0f5c67d66bf0cd063c8b047Brian Wellington (void)isc_resource_getlimit(isc_resource_openfiles,
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington "adjusted limit on open files from "
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * If the named configuration filename is relative, prepend the current
809fdfba224a83fcc5a8ae4394cf2a477d13dc91Brian Wellington * directory's name before possibly changing to another directory.
809fdfba224a83fcc5a8ae4394cf2a477d13dc91Brian Wellington if (! isc_file_isabsolute(ns_g_conffile)) {
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence result = isc_file_absolutepath(ns_g_conffile,
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington ns_main_earlyfatal("could not construct absolute path "
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington "of configuration file: %s",
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington * Record the server's startup time.
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington ns_main_earlyfatal("isc_time_now() failed: %s",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence ns_main_earlyfatal("create_managers() failed: %s",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Add calls to register sdb drivers here.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /* xxdb_init(); */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * Register the DLZ "dlopen" driver.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence ns_main_earlyfatal("dlz_dlopen_init() failed: %s",
dc3fc5830a90b170c0a2fbf2e8fe057aad209678Brian Wellington * Register any other contributed DLZ drivers.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence ns_main_earlyfatal("dlz_drivers_init() failed: %s",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#endif /* HAVE_LIBSECCOMP */
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Add calls to unregister sdb drivers here.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /* xxdb_clear(); */
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington * Unregister contributed DLZ drivers.
0f80bfec687db08a6e6ce945ef1d818da06c7ca9Brian Wellington * Unregister "dlopen" DLZ driver.
5ea0d11ca45bfd1ea9db8db07f18fbb02f500661Brian Wellington isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington * Caller has to ensure locking.
4fe8755480c108a1232b7189fd5434ab35a6b623Brian Wellington * Get FMRI for the named process.
809fdfba224a83fcc5a8ae4394cf2a477d13dc91Brian Wellingtonns_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington REQUIRE(ins_name != NULL && *ins_name == NULL);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "scf_handle_create() failed: %s",
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington "scf_handle_bind() failed: %s",
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington if ((namelen = scf_myname(h, NULL, 0)) == -1) {
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington "scf_myname() failed: %s",
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington if ((instance = isc_mem_allocate(mctx, namelen + 1)) == NULL) {
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington "ns_smf_get_instance memory "
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington "allocation failed: %s",
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington if (scf_myname(h, instance, namelen + 1) == -1) {
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington "scf_myname() failed: %s",
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington#endif /* HAVE_LIBSCF */
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington/* main entry point, possibly hooked */
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington * Record version in core image.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * strings named.core | grep "named version:"
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington#if defined(NO_VERSION_DATE) || !defined(__DATE__)
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence "named version: BIND " VERSION " <" SRCID ">",
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington "named version: BIND " VERSION " <" SRCID "> (" __DATE__ ")",
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington result = isc_file_progname(*argv, program_name, sizeof(program_name));
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington ns_main_earlyfatal("program name too long");
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington ns_main_earlyfatal("failed to build internal symbol table");
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington isc_assertion_setcallback(assertion_failed);
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington isc_error_setunexpected(library_unexpected_error);
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington * Warn about common configuration error.
a49acbf201a411a47e18d136b38bbea8cf283adaBrian Wellington if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington (ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))
setup();
#ifdef HAVE_LIBSCF
cleanup();
if (want_stats) {