main.c revision 0818d0a7646cde4ecee39e69cbe711d4b6727ea3
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff/*
ca41b452ede6feaa9d8739ec3cae19389a7b0d03Bob Halley * Copyright (C) 1999 Internet Software Consortium.
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff *
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * Permission to use, copy, modify, and distribute this software for any
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * purpose with or without fee is hereby granted, provided that the above
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * copyright notice and this permission notice appear in all copies.
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff *
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * SOFTWARE.
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff */
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <config.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff#include <string.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <stdarg.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <stdlib.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <stddef.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <unistd.h> /* XXXRTH Naughty. Needed for getopt(). */
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#include <isc/app.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#include <isc/error.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#include <isc/boolean.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#include <isc/task.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#include <isc/timer.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <dns/dbtable.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <dns/result.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <dst/result.h>
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#define NS_MAIN 1
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff#include <named/globals.h>
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff#include <named/client.h>
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff#include <named/interfacemgr.h>
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff#include <named/server.h>
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffstatic isc_boolean_t want_stats = ISC_FALSE;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffstatic void
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffearly_fatal(char *format, ...) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff va_list args;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff va_start(args, format);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff vfprintf(stderr, format, args);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff va_end(args);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff fprintf(stderr, "\n");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff exit(1);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff}
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffstatic void
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffusage(void) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff fprintf(stderr,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff "usage: named [[-c cachefile] ...] [[-z zonefile] ...]\n");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff fprintf(stderr,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff " [-s] [-N number of cpus]\n");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff}
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffstatic void
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffparse_command_line(int argc, char *argv[]) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff char *argtext, *mastertext, *origintext;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff int ch;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ns_dbinfo_t *dbi;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff /*+ XXXRTH we need a veneered getopt() */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff while ((ch = getopt(argc, argv, "c:N:sz:")) != -1) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff switch (ch) {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff case 'c':
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff /* XXXRTH temporary syntax */
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff dbi = isc_mem_get(ns_g_mctx, sizeof *dbi);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff if (dbi == NULL)
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff early_fatal("creating cache info failed");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dbi->path = isc_mem_strdup(ns_g_mctx, optarg);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (dbi->path == NULL)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff early_fatal("out of memory");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dbi->origin = isc_mem_strdup(ns_g_mctx, ".");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (dbi->origin == NULL)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff early_fatal("out of memory");
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff dbi->master = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dbi->iscache = ISC_TRUE;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dbi->isslave = ISC_FALSE;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dbi->view = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dbi->db = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ISC_LINK_INIT(dbi, link);
62e4837585f2d48ce9ef3ad6880d8fb75a578e58Andreas Gustafsson ISC_LIST_APPEND(ns_g_dbs, dbi, link);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff break;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff case 'N':
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ns_g_cpus = atoi(optarg);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (ns_g_cpus == 0)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ns_g_cpus = 1;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff break;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff case 's':
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff /* XXXRTH temporary syntax */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff want_stats = ISC_TRUE;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff break;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff case 'z':
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff /* XXXRTH temporary syntax */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dbi = isc_mem_get(ns_g_mctx, sizeof *dbi);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (dbi == NULL)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff early_fatal("creating zone info failed");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff argtext = isc_mem_strdup(ns_g_mctx, optarg);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (argtext == NULL)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff early_fatal("out of memory");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff mastertext = strrchr(argtext, '@');
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (mastertext == NULL) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dbi->master = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dbi->isslave = ISC_FALSE;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff } else {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff *mastertext++ = '\0';
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff dbi->master = isc_mem_strdup(ns_g_mctx,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff mastertext);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (dbi->master == NULL)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff early_fatal("out of memory");
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff RUNTIME_CHECK(dbi->master != NULL);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff dbi->isslave = ISC_TRUE;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff }
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff origintext = strrchr(argtext, '/');
62e4837585f2d48ce9ef3ad6880d8fb75a578e58Andreas Gustafsson if (origintext == NULL)
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff origintext = argtext;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff else
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff origintext++; /* Skip '/'. */
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff dbi->path = isc_mem_strdup(ns_g_mctx, argtext);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff if (dbi->path == NULL)
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff early_fatal("out of memory");
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff dbi->origin = isc_mem_strdup(ns_g_mctx, origintext);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff if (dbi->origin == NULL)
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff early_fatal("out of memory");
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff dbi->view = NULL;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff dbi->db = NULL;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff dbi->iscache = ISC_FALSE;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff isc_mem_free(ns_g_mctx, argtext);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff ISC_LINK_INIT(dbi, link);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff ISC_LIST_APPEND(ns_g_dbs, dbi, link);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff break;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff case '?':
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff usage();
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff early_fatal("unknown command line argument");
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff break;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff default:
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff early_fatal("getopt() returned %d", ch);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff }
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff }
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff argc -= optind;
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff argv += optind;
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff if (argc > 1) {
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff usage();
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff early_fatal("extra command line arguments");
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff }
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff}
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graffstatic isc_result_t
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffcreate_managers() {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff isc_result_t result;
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff result = isc_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff if (result != ISC_R_SUCCESS) {
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff UNEXPECTED_ERROR(__FILE__, __LINE__,
4e675038a097065ff13944232cd7c89ac5961984Michael Graff "ns_taskmgr_create() failed: %s\n",
4e675038a097065ff13944232cd7c89ac5961984Michael Graff isc_result_totext(result));
4e675038a097065ff13944232cd7c89ac5961984Michael Graff return (ISC_R_UNEXPECTED);
4e675038a097065ff13944232cd7c89ac5961984Michael Graff }
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
4e675038a097065ff13944232cd7c89ac5961984Michael Graff result = isc_timermgr_create(ns_g_mctx, &ns_g_timermgr);
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff if (result != ISC_R_SUCCESS) {
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff UNEXPECTED_ERROR(__FILE__, __LINE__,
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff "ns_timermgr_create() failed: %s\n",
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff isc_result_totext(result));
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff return (ISC_R_UNEXPECTED);
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff }
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff result = isc_socketmgr_create(ns_g_mctx, &ns_g_socketmgr);
e24f605ad64182532640dc6721070456b13112d5Michael Graff if (result != ISC_R_SUCCESS) {
e24f605ad64182532640dc6721070456b13112d5Michael Graff UNEXPECTED_ERROR(__FILE__, __LINE__,
e24f605ad64182532640dc6721070456b13112d5Michael Graff "isc_socketmgr_create() failed: %s\n",
e24f605ad64182532640dc6721070456b13112d5Michael Graff isc_result_totext(result));
e24f605ad64182532640dc6721070456b13112d5Michael Graff return (ISC_R_UNEXPECTED);
e24f605ad64182532640dc6721070456b13112d5Michael Graff }
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff result = ns_clientmgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff &ns_g_clientmgr);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff if (result != ISC_R_SUCCESS) {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff UNEXPECTED_ERROR(__FILE__, __LINE__,
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff "ns_clientmgr_create() failed: %s\n",
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff isc_result_totext(result));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff return (ISC_R_UNEXPECTED);
e24f605ad64182532640dc6721070456b13112d5Michael Graff }
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff result = ns_interfacemgr_create(ns_g_mctx, ns_g_taskmgr,
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff ns_g_socketmgr, ns_g_clientmgr,
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff &ns_g_interfacemgr);
e24f605ad64182532640dc6721070456b13112d5Michael Graff if (result != ISC_R_SUCCESS) {
e24f605ad64182532640dc6721070456b13112d5Michael Graff UNEXPECTED_ERROR(__FILE__, __LINE__,
e24f605ad64182532640dc6721070456b13112d5Michael Graff "ns_interfacemgr_create() failed: %s\n",
e24f605ad64182532640dc6721070456b13112d5Michael Graff isc_result_totext(result));
e24f605ad64182532640dc6721070456b13112d5Michael Graff return (ISC_R_UNEXPECTED);
e24f605ad64182532640dc6721070456b13112d5Michael Graff }
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff return (ISC_R_SUCCESS);
e24f605ad64182532640dc6721070456b13112d5Michael Graff}
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graffstatic void
e24f605ad64182532640dc6721070456b13112d5Michael Graffdestroy_managers(void) {
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff /*
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff * The interface manager owns tasks, so we have to destroy it before
e24f605ad64182532640dc6721070456b13112d5Michael Graff * we destroy the task manager.
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff */
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff ns_interfacemgr_destroy(&ns_g_interfacemgr);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff /*
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff * isc_taskmgr_destroy() will block until all tasks have exited,
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff */
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_taskmgr_destroy(&ns_g_taskmgr);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_timermgr_destroy(&ns_g_timermgr);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_socketmgr_destroy(&ns_g_socketmgr);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff ns_clientmgr_destroy(&ns_g_clientmgr);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff}
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffstatic void
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffsetup() {
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff isc_result_t result;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff ISC_LIST_INIT(ns_g_viewlist);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff result = isc_rwlock_init(&ns_g_viewlock, 0, 0);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff if (result != ISC_R_SUCCESS)
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff early_fatal("isc_rwlock_init() failed: %s",
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_result_totext(result));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff result = create_managers();
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff if (result != ISC_R_SUCCESS)
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff early_fatal("create_managers() failed: %s",
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_result_totext(result));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff result = ns_server_init();
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff if (result != ISC_R_SUCCESS)
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff early_fatal("ns_server_init() failed: %s",
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff isc_result_totext(result));
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff result = dns_tsig_init(ns_g_mctx);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff if (result != ISC_R_SUCCESS)
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff early_fatal("dns_tsig_init() failed: %s",
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_result_totext(result));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff}
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffstatic void
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffcleanup() {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff destroy_managers();
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff dns_tsig_destroy();
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#if 0
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_rwlock_destroy(&ns_g_viewlock);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#endif
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff}
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffint
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffmain(int argc, char *argv[]) {
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff isc_result_t result;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff result = isc_app_start();
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff if (result != ISC_R_SUCCESS)
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff early_fatal("isc_app_start() failed: %s",
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff isc_result_totext(result));
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff result = isc_mem_create(0, 0, &ns_g_mctx);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff if (result != ISC_R_SUCCESS)
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff early_fatal("isc_mem_create() failed: %s",
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff isc_result_totext(result));
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff dns_result_register();
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff dst_result_register();
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff parse_command_line(argc, argv);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff setup();
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff /*
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff * Start things running and then wait for a shutdown request.
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff */
e24f605ad64182532640dc6721070456b13112d5Michael Graff result = isc_app_run();
4e675038a097065ff13944232cd7c89ac5961984Michael Graff if (result != ISC_R_SUCCESS)
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_app_run(): %s",
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff isc_result_totext(result));
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff cleanup();
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff if (want_stats)
e24f605ad64182532640dc6721070456b13112d5Michael Graff isc_mem_stats(ns_g_mctx, stdout);
e24f605ad64182532640dc6721070456b13112d5Michael Graff isc_mem_destroy(&ns_g_mctx);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff isc_app_finish();
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff return (0);
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff}
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff