main.c revision bcf966e6146943ebcac1603a52468f5292612b18
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * Copyright (C) 2004-2012 Internet Systems Consortium, Inc. ("ISC")
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * Copyright (C) 1999-2003 Internet Software Consortium.
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * Permission to use, copy, modify, and/or distribute this software for any
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * purpose with or without fee is hereby granted, provided that the above
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * copyright notice and this permission notice appear in all copies.
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
8cbf3b6fc35091abde426930f2eadb8f53476c98Evan Hunt * PERFORMANCE OF THIS SOFTWARE.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews/* $Id: main.c,v 1.187 2012/02/06 23:46:44 tbox Exp $ */
914eeb33149a0008e26741d9e7d89dcd6f8b6d0bMark Andrews * Defining NS_MAIN provides storage declarations (rather than extern)
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff * for variables in named/globals.h.
3d776d762914d1b675b4fd49728ce353ccf6f77eBrian Wellington#include <named/globals.h> /* Explicit, though named/log.h includes it. */
1c1290afabb3c8f4dd498170ac9592e5be450161Mark Andrews * Include header files for database drivers here.
b123b265e3a3d9b72a14230b6517e0f6fdb5c5b5Mark Andrews/* #include "xxdb.h" */
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews * Include contributed DLZ drivers if appropriate.
1c1290afabb3c8f4dd498170ac9592e5be450161Mark Andrews * The maximum number of stack frames to dump on assertion failure.
1831311ac6179951c8fcca75aa29dc2f5c0218b9Francis Dupontstatic char program_name[ISC_DIR_NAMEMAX] = "named";
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntstatic unsigned int maxsocks = 0;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntstatic int maxudp = 0;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt "exiting (due to early fatal error)");
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntassertion_failed(const char *file, int line, isc_assertiontype_t type,
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntassertion_failed(const char *file, int line, isc_assertiontype_t type,
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt const char *cond)
323a9f3430abf186f8f84d795549391a8ed7f274Francis Dupont * Handle assertion failures.
75a4dd0d377dca2f85cea44e28bf110314c1fe8cDavid Lawrence * Reset the assertion callback in case it is the log
75a4dd0d377dca2f85cea44e28bf110314c1fe8cDavid Lawrence * routines causing the assertion.
91306d962f9d147d94b82fb14edb28f8d907cae7Andreas Gustafsson result = isc_backtrace_gettrace(tracebuf, BACKTRACE_MAXFRAME,
91306d962f9d147d94b82fb14edb28f8d907cae7Andreas Gustafsson if (result == ISC_R_SUCCESS && nframes > 0)
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence isc_assertion_typetotext(type), cond, logsuffix);
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence for (i = 0; i < nframes; i++) {
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence unsigned long offset;
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence result = isc_backtrace_getsymbol(tracebuf[i],
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley "#%d %p in %s()+0x%lx", i,
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley "#%d %p in ??", i,
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉 "exiting (due to assertion failure)");
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson fprintf(stderr, "%s:%d: %s(%s) failed\n",
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson file, line, isc_assertion_typetotext(type), cond);
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrewslibrary_fatal_error(const char *file, int line, const char *format,
523f3d630243211ddfda852f5224f7eff681d3a5Evan HuntISC_FORMAT_PRINTF(3, 0) ISC_PLATFORM_NORETURN_POST;
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrewslibrary_fatal_error(const char *file, int line, const char *format,
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews * Handle isc_error_fatal() calls from our libraries.
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt * Reset the error callback in case it is the log
1f27b7873c640771df00a47ee3be188c4079479cFrancis Dupont * routines causing the assertion.
1f27b7873c640771df00a47ee3be188c4079479cFrancis Dupont "exiting (due to fatal error in library)");
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt fprintf(stderr, "%s:%d: fatal error: ", file, line);
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrewslibrary_unexpected_error(const char *file, int line, const char *format,
523f3d630243211ddfda852f5224f7eff681d3a5Evan Huntlibrary_unexpected_error(const char *file, int line, const char *format,
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt * Handle isc_error_unexpected() calls from our libraries.
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews fprintf(stderr, "%s:%d: fatal error: ", file, line);
831f59eb43b56642b00f82e07722836d2f9593abEvan Hunt "usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] "
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews "[-d debuglevel]\n"
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews " [-f|-g] [-n number_of_cpus] [-p port] "
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence "[-P listen-port] [-s]\n"
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence " [-t chrootdir] [-u username] [-i pidfile]\n"
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence " [-m {usage|trace|record|size|mctx}]\n");
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence "usage: named [-4|-6] [-c conffile] [-d debuglevel] "
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence "[-E engine] [-f|-g]\n"
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence " [-n number_of_cpus] [-p port] [-s] "
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence "[-t chrootdir] [-u username]\n"
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence " [-m {usage|trace|record|size|mctx}]\n");
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews eob = saved_command_line + sizeof(saved_command_line);
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence * This won't perfectly produce a shell-independent
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence * pastable command line in all circumstances, but
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence * comes close, and for practical purposes will
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence * nearly always be fine.
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews INSIST(sizeof(saved_command_line) >= sizeof(truncated));
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff ns_main_earlyfatal("%s '%s' out of range", desc, arg);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsstatic struct flag_def {
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews const char *name;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews unsigned int value;
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrenceset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);
323a9f3430abf186f8f84d795549391a8ed7f274Francis Dupont "46c:C:d:E:fFgi:lm:n:N:p:P:"
9fe28a624c659e380d47dbf45527637dab03b998Mark Andrews ns_main_earlyfatal("cannot specify -4 and -6");
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews ns_main_earlyfatal("IPv4 not supported by OS");
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews ns_main_earlyfatal("cannot specify -4 and -6");
774c3a62d9adca187b44fe90919bb409a43a2f2aMark Andrews ns_main_earlyfatal("IPv6 not supported by OS");
d7896edb4e93c4785a9281ea86afba86b758e813Mark Andrews ns_main_earlyfatal("cannot specify -c and -C");
ab3aeba682460fd39deb7901aa69f976583c9f47Michael Graff lwresd_g_resolvconffile = isc_commandline_argument;
ab3aeba682460fd39deb7901aa69f976583c9f47Michael Graff ns_main_earlyfatal("cannot specify -c and -C");
ab3aeba682460fd39deb7901aa69f976583c9f47Michael Graff ns_g_debuglevel = parse_int(isc_commandline_argument,
9fe28a624c659e380d47dbf45527637dab03b998Mark Andrews "debug level");
6342df69b05f2f62d060fd4affdf536e51504084Mark Andrews /* XXXBEW -i should be removed */
6342df69b05f2f62d060fd4affdf536e51504084Mark Andrews lwresd_g_defaultpidfile = isc_commandline_argument;
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson set_flags(isc_commandline_argument, mem_debug_flags,
5b02fc32d693bb811199308a40143df0adf818c1Mark Andrews ns_g_cpus = parse_int(isc_commandline_argument,
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson "number of cpus");
5506903c9215faf42586307c2288942fd804c579Evan Hunt port = parse_int(isc_commandline_argument, "port");
38cd4d14cc341c2663e574035074788bb6f0fce2Evan Hunt /* XXXBEW Should -P be removed? */
d8f2dd46cba3a16c2433e85657a5b15543013ca6Mark Andrews port = parse_int(isc_commandline_argument, "port");
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson ns_main_earlyfatal("port '%s' out of range",
cd63e943104ab4f7f8b37da8d49738e91a8db1ddEvan Hunt /* XXXRTH temporary syntax */
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington maxsocks = parse_int(isc_commandline_argument,
47fd46791da765e3dbedd987e9b263b3bee25986Brian Wellington "max number of sockets");
cd63e943104ab4f7f8b37da8d49738e91a8db1ddEvan Hunt /* XXXJAB should we make a copy? */
6fcb2f0faad67a6d2cb2e30ec57157d75fbfe58fAndreas Gustafsson ns_g_chrootdir = isc_commandline_argument;
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson * clienttest: make clients single shot with their
8f3dd8f8e73e4465221a5297819db70e6b383138Mark Andrews * own memory context.
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews * delay=xxxx: delay client responses by xxxx ms to
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews * simulate remote servers.
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews if (!strcmp(isc_commandline_argument, "clienttest"))
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews else if (!strcmp(isc_commandline_argument, "nosoa"))
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews else if (!strcmp(isc_commandline_argument, "noaa"))
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews else if (!strcmp(isc_commandline_argument, "maxudp512"))
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews else if (!strcmp(isc_commandline_argument, "maxudp1460"))
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews else if (!strcmp(isc_commandline_argument, "dropedns"))
43fe2897fc80bbec2115310ca79d432a252f3ea4Mark Andrews else if (!strcmp(isc_commandline_argument, "noedns"))
754cca729dd82ae8363917dc00ad44f9d900635bMark Andrews ns_g_delay = atoi(isc_commandline_argument + 6);
debd489a44363870f96f75818e89ec27d3cab736Francis Dupont ns_g_udpdisp = parse_int(isc_commandline_argument,
debd489a44363870f96f75818e89ec27d3cab736Francis Dupont "number of UDP listeners "
debd489a44363870f96f75818e89ec27d3cab736Francis Dupont "per interface");
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews /* Reserved for FIPS mode */
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews /* FALLTHROUGH */
40dd9cb8cc240c33d820fe79f176ed51e4c06a1aMark Andrews /* FALLTHROUGH */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_main_earlyfatal("parsing options returned %d", ch);
3dfa202e4fea6b985bcf8761e2d11c176baa40d1Mark Andrews ns_main_earlyfatal("extra command line arguments");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ISC_LOG_INFO, "found %u CPU%s, using %u worker thread%s",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_g_cpus_detected, ns_g_cpus_detected == 1 ? "" : "s",
ddb35cf2f301ae1c3fa601792034f6d349efc8c5Mark Andrews if (ns_g_udpdisp == 0 || ns_g_udpdisp > ns_g_cpus)
3dfa202e4fea6b985bcf8761e2d11c176baa40d1Mark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
3dfa202e4fea6b985bcf8761e2d11c176baa40d1Mark Andrews ISC_LOG_INFO, "using %u UDP listener%s per interface",
3dfa202e4fea6b985bcf8761e2d11c176baa40d1Mark Andrews result = isc_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);
3dfa202e4fea6b985bcf8761e2d11c176baa40d1Mark Andrews "isc_taskmgr_create() failed: %s",
3dfa202e4fea6b985bcf8761e2d11c176baa40d1Mark Andrews result = isc_timermgr_create(ns_g_mctx, &ns_g_timermgr);
ddb35cf2f301ae1c3fa601792034f6d349efc8c5Mark Andrews "isc_timermgr_create() failed: %s",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = isc_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "isc_socketmgr_create() failed: %s",
3dfa202e4fea6b985bcf8761e2d11c176baa40d1Mark Andrews result = isc_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);
3dfa202e4fea6b985bcf8761e2d11c176baa40d1Mark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
3dfa202e4fea6b985bcf8761e2d11c176baa40d1Mark Andrews ISC_LOG_INFO, "using up to %u sockets", socks);
3dfa202e4fea6b985bcf8761e2d11c176baa40d1Mark Andrews result = isc_entropy_create(ns_g_mctx, &ns_g_entropy);
3dfa202e4fea6b985bcf8761e2d11c176baa40d1Mark Andrews "isc_entropy_create() failed: %s",
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson result = isc_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson "isc_hash_create() failed: %s",
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson isc_entropy_detach(&ns_g_fallbackentropy);
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson * isc_taskmgr_destroy() will block until all tasks have exited,
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson * isc_hash_destroy() cannot be called as long as a resolver may be
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * running. Calling this after isc_taskmgr_destroy() ensures the
5ff133b82082d82f0ba89b7c999c6b62b6298e46Andreas Gustafsson * call is safe.
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff if (!isc_log_wouldlog(ns_g_lctx, ISC_LOG_DEBUG(99)))
13faa8b6a2d0d45e0659049983928366252ab3faMichael Graff isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt for (i = 0, result = ISC_R_SUCCESS; result == ISC_R_SUCCESS; i++) {
13faa8b6a2d0d45e0659049983928366252ab3faMichael Graff result = isc_backtrace_getsymbolfromindex(i, &addr, &fname);
a53259c4cc558f86dd008eccc60cc89b6734a03cMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
5f9e583552f53de12062bfff12e47250abce378fBrian Wellington * Get the user and group information before changing the root
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * directory, so the administrator does not need to keep a copy
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews * of the user and group databases in the chroot'ed environment.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Initialize time conversion information
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Check if named is under smf control, before chroot. */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = ns_smf_get_instance(&instance, 0, ns_g_mctx);
c5826852e6c789f59b301f8197e65a1dd4e09a44Mark Andrews /* We don't care about instance, just check if we got one. */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#endif /* HAVE_LIBSCF */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Initialize system's random device as fallback entropy source
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * if running chroot'ed.
5989aea4bbe79e09290792f04aeb557e2b2da02eAndreas Gustafsson result = isc_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ns_main_earlyfatal("isc_entropy_create() failed: %s",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = isc_entropy_createfilesource(ns_g_fallbackentropy,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "entropy source %s: %s",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Check for the number of cpu's before ns_os_chroot().
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * For operating systems which have a capability mechanism, now
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * is the time to switch to minimal privs and change our user id.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * On traditional UNIX systems, this call will be a no-op, and we
d7729155dff87d3c7a2b9103bf6e5164ea4d7dd7Mark Andrews * will change the user ID after reading the config file the first
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * time. (We need to read the config file to know which possibly
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * privileged ports to bind() to.)
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = ns_log_init(ISC_TF(ns_g_username != NULL));
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Now is the time to daemonize (if we're not running in the
aaaf8d4f4873d21e55c3ffb4f656203d08339865Mark Andrews * foreground). We waited until now because we wanted to get
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * a valid logging context setup. We cannot daemonize any later,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * because calling create_managers() will create threads, which
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * would be lost after fork().
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * We call isc_app_start() here as some versions of FreeBSD's fork()
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * destroys all the signal handling it sets up.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ISC_LOG_NOTICE, "starting BIND %s%s", ns_g_version,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
d7729155dff87d3c7a2b9103bf6e5164ea4d7dd7Mark Andrews ISC_LOG_NOTICE, "built with %s", ns_g_configargs);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "----------------------------------------------------");
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "BIND 9 is maintained by Internet Systems Consortium,");
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "Inc. (ISC), a non-profit 501(c)(3) public-benefit ");
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
b123b265e3a3d9b72a14230b6517e0f6fdb5c5b5Mark Andrews "corporation. Support and training for BIND 9 are ");
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "----------------------------------------------------");
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Get the initial resource limits.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt (void)isc_resource_getlimit(isc_resource_stacksize,
f0e9d6e905235482ff9b4be770ee35018fcd8234Evan Hunt (void)isc_resource_getlimit(isc_resource_datasize,
37dee1ff94960a61243f611c0f87f8c316815c53Mark Andrews (void)isc_resource_getlimit(isc_resource_coresize,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt (void)isc_resource_getlimit(isc_resource_openfiles,
f0e9d6e905235482ff9b4be770ee35018fcd8234Evan Hunt * System resources cannot effectively be tuned on some systems.
f0e9d6e905235482ff9b4be770ee35018fcd8234Evan Hunt * Raise the limit in such cases for safety.
f0e9d6e905235482ff9b4be770ee35018fcd8234Evan Hunt (void)isc_resource_getlimit(isc_resource_openfiles,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "adjusted limit on open files from "
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * If the named configuration filename is relative, prepend the current
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * directory's name before possibly changing to another directory.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ns_main_earlyfatal("could not construct absolute path "
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "of configuration file: %s",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Record the server's startup time.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ns_main_earlyfatal("create_managers() failed: %s",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Add calls to register sdb drivers here.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* xxdb_init(); */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Register the DLZ "dlopen" driver.
f0e9d6e905235482ff9b4be770ee35018fcd8234Evan Hunt ns_main_earlyfatal("dlz_dlopen_init() failed: %s",
0277def3cf21a0b52bdb50a9b449c37b2139b321Mark Andrews * Register any other contributed DLZ drivers.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ns_main_earlyfatal("dlz_drivers_init() failed: %s",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Add calls to unregister sdb drivers here.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* xxdb_clear(); */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Unregister contributed DLZ drivers.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Unregister "dlopen" DLZ driver.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Caller has to ensure locking.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Get FMRI for the named process.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntns_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx) {
08a768e82ad64ede97f640c88e02984b59122753Michael Graff if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont "scf_handle_create() failed: %s",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "scf_handle_bind() failed: %s",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "scf_myname() failed: %s",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if ((instance = isc_mem_allocate(mctx, namelen + 1)) == NULL) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "ns_smf_get_instance memory "
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "allocation failed: %s",
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont if (scf_myname(h, instance, namelen + 1) == -1) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "scf_myname() failed: %s",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#endif /* HAVE_LIBSCF */
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont * Record version in core image.
1ea6e09c376b1351c614474a88675b1a9bda6571Evan Hunt * strings named.core | grep "named version:"
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "named version: BIND " VERSION " <" SRCID "> (" __DATE__ ")",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = isc_file_progname(*argv, program_name, sizeof(program_name));
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ns_main_earlyfatal("failed to build internal symbol table");
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_error_setunexpected(library_unexpected_error);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Warn about common configuration error.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt (ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ns_main_earlywarning("config filename (-c %s) contains "
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "chroot path (-t %s)",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Start things running and then wait for a shutdown request
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * or reload.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "isc_app_run(): %s",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Force exit.
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont result = ns_smf_get_instance(&instance, 1, ns_g_mctx);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (result == ISC_R_SUCCESS && instance != NULL) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "smf_disable_instance() "
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "failed for %s : %s",
8cbf3b6fc35091abde426930f2eadb8f53476c98Evan Hunt#endif /* HAVE_LIBSCF */