main.c revision c0d0a59d1b665423b8a0d1829d0f0da121cb3473
/*
* Copyright (C) 1999, 2000 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>
#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.
*/
/*
* Reset the assetion callback in case it is the log
* routines causing the assertion.
*/
"exiting (due assertion failure)");
} else {
}
if (ns_g_coreok)
abort();
exit(1);
}
static void
/*
* Handle isc_error_fatal() calls from our libraries.
*/
/*
* Reset the error callback in case it is the log
* routines causing the assertion.
*/
"exiting (due to fatal error in library)");
} else {
}
if (ns_g_coreok)
abort();
exit(1);
}
static void
/*
* Handle isc_error_unexpected() calls from our libraries.
*/
} else {
}
}
static void
usage(void) {
"usage: named [-c conffile] [-d debuglevel] [-f] [-N number_of_cpus]\n"
" [-p port] [-s] [-t chrootdir] [-u username]\n");
}
static void
int ch;
unsigned int port;
"c:d:fN:p:st:u:x:")) !=
-1) {
switch (ch) {
case 'c':
break;
case 'd':
break;
case 'f':
break;
case 'N':
if (ns_g_cpus == 0)
ns_g_cpus = 1;
break;
case 'p':
ns_main_earlyfatal("port \"%s\" out of range",
break;
case 's':
/* XXXRTH temporary syntax */
break;
case 't':
/* XXXJAB should we make a copy? */
break;
case 'u':
break;
case 'x':
/* XXXRTH temporary syntax */
break;
case '?':
usage();
ns_main_earlyfatal("unknown option `-%c'",
default:
}
}
if (argc > 0) {
usage();
ns_main_earlyfatal("extra command line arguments");
}
}
static isc_result_t
create_managers() {
if (result != ISC_R_SUCCESS) {
"ns_taskmgr_create() failed: %s",
return (ISC_R_UNEXPECTED);
}
if (result != ISC_R_SUCCESS) {
"ns_timermgr_create() failed: %s",
return (ISC_R_UNEXPECTED);
}
if (result != ISC_R_SUCCESS) {
"isc_socketmgr_create() failed: %s",
return (ISC_R_UNEXPECTED);
}
return (ISC_R_SUCCESS);
}
static void
destroy_managers(void) {
/*
* isc_taskmgr_destroy() will block until all tasks have exited,
*/
if (ns_g_omapimgr != NULL) {
}
}
static void
setup() {
result = ns_log_init();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("ns_log_init() failed: %s",
/*
* Now is the time to daemonize (if we're not running in the
* foreground). We waited until now because we wanted to get
* a valid logging context setup. We cannot daemonize any later,
* because calling create_managers() will create threads, which
* would be lost after fork().
*/
if (!ns_g_foreground)
result = create_managers();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("create_managers() failed: %s",
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("omapi_lib_init() failed: %s",
if (result == ISC_R_SUCCESS)
"OMAPI started");
else
"OMAPI failed to start: %s",
}
static void
cleanup() {
ISC_LOG_NOTICE, "exiting");
}
int
program_name = argv[0];
ns_os_init();
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);
}