main.c revision 95ff121ebd392ee9745d6ebfde4fc7fe4aea5208
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <config.h>
#include <errno.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stddef.h>
/* XXX this include will need to go. It's here for _SC_OPEN_MAX */
#include <unistd.h>
#include <isc/assertions.h>
#include <isc/commandline.h>
#define NS_MAIN 1
#include <named/interfacemgr.h>
static char * program_name = "named";
void
ns_main_earlyfatal(const char *format, ...) {
"exiting (due to early fatal error)");
} else {
}
exit(1);
}
static void
/*
* Handle assertion failures.
*/
"exiting (due assertion failure)");
} else {
}
if (ns_g_coreok)
abort();
exit(1);
}
static void
/*
* Handle isc_error_fatal() calls from our libraries.
*/
"exiting (due to fatal error in library)");
} else {
}
if (ns_g_coreok)
abort();
exit(1);
}
static void
usage(void) {
"usage: named [[-c cachefile] ...] [[-z zonefile] ...]\n");
" [-p port] [-s] [-N number of cpus]\n");
}
static void
int ch;
-1) {
switch (ch) {
case 'b':
case 'c':
break;
case 'd':
break;
case 'f':
break;
case 'N':
if (ns_g_cpus == 0)
ns_g_cpus = 1;
break;
case 'p':
break;
case 's':
/* XXXRTH temporary syntax */
break;
case 't':
/* XXXJAB should be make a copy? */
break;
case 'x':
/* XXXRTH temporary syntax */
break;
case '?':
ns_main_earlyfatal("unknown option `-%c'",
default:
}
}
if (argc > 1) {
usage();
ns_main_earlyfatal("extra command line arguments");
}
}
static isc_result_t
create_managers() {
if (result != ISC_R_SUCCESS) {
"ns_taskmgr_create() failed: %s\n",
return (ISC_R_UNEXPECTED);
}
if (result != ISC_R_SUCCESS) {
"ns_timermgr_create() failed: %s\n",
return (ISC_R_UNEXPECTED);
}
if (result != ISC_R_SUCCESS) {
"isc_socketmgr_create() failed: %s\n",
return (ISC_R_UNEXPECTED);
}
return (ISC_R_SUCCESS);
}
static void
destroy_managers(void) {
/*
* isc_taskmgr_destroy() will block until all tasks have exited,
*/
}
static void
setup() {
result = ns_log_init();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("ns_log_init() failed: %s",
result = create_managers();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("create_managers() failed: %s",
}
static void
cleanup() {
ISC_LOG_NOTICE, "exiting");
}
int
program_name = argv[0];
result = ns_os_init();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("ns_os_init() failed: %s",
result = isc_app_start();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("isc_app_start() failed: %s",
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("isc_mem_create() failed: %s",
setup();
/*
* Start things running and then wait for a shutdown request
* or reload.
*/
do {
result = isc_app_run();
if (result == ISC_R_RELOAD) {
} else if (result != ISC_R_SUCCESS) {
"isc_app_run(): %s",
/*
* Force exit.
*/
}
} while (result != ISC_R_SUCCESS);
cleanup();
if (want_stats)
return (0);
}