1999-07-24 01:17:44 +00:00
|
|
|
/*
|
2000-02-03 22:29:57 +00:00
|
|
|
* Copyright (C) 1999, 2000 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
1999-07-24 01:17:44 +00:00
|
|
|
* 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.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2000-07-27 09:55:03 +00:00
|
|
|
* 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.
|
1999-07-24 01:17:44 +00:00
|
|
|
*/
|
|
|
|
|
2000-12-29 22:31:04 +00:00
|
|
|
/* $Id: main.c,v 1.101 2000/12/29 22:31:04 bwelling Exp $ */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-08-09 03:44:42 +00:00
|
|
|
#include <ctype.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
#include <stdlib.h>
|
2000-06-19 18:55:46 +00:00
|
|
|
#include <string.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
|
|
|
|
#include <isc/app.h>
|
1999-10-06 19:59:29 +00:00
|
|
|
#include <isc/commandline.h>
|
2000-06-21 22:12:02 +00:00
|
|
|
#include <isc/entropy.h>
|
2000-06-22 01:09:14 +00:00
|
|
|
#include <isc/os.h>
|
2000-12-29 22:31:04 +00:00
|
|
|
#include <isc/platform.h>
|
2000-11-14 23:59:21 +00:00
|
|
|
#include <isc/resource.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
#include <isc/task.h>
|
|
|
|
#include <isc/timer.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2000-05-10 21:34:50 +00:00
|
|
|
#include <dns/dispatch.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
#include <dst/result.h>
|
2000-06-16 03:26:55 +00:00
|
|
|
#include <dns/view.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
2000-11-14 23:59:21 +00:00
|
|
|
* Defining NS_MAIN provides storage declarations (rather than extern)
|
2000-05-08 14:38:29 +00:00
|
|
|
* for variables in named/globals.h.
|
|
|
|
*/
|
2000-08-01 01:33:37 +00:00
|
|
|
#define NS_MAIN 1
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <named/globals.h> /* Explicit, though named/log.h includes it. */
|
1999-07-24 01:17:44 +00:00
|
|
|
#include <named/interfacemgr.h>
|
1999-10-22 19:35:19 +00:00
|
|
|
#include <named/log.h>
|
2000-01-31 15:23:10 +00:00
|
|
|
#include <named/omapi.h>
|
1999-10-23 01:07:22 +00:00
|
|
|
#include <named/os.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
#include <named/server.h>
|
2000-06-16 01:39:02 +00:00
|
|
|
#include <named/lwresd.h>
|
1999-10-23 01:07:22 +00:00
|
|
|
#include <named/main.h>
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2000-11-27 19:12:23 +00:00
|
|
|
/*
|
|
|
|
* Include header files for database drivers here.
|
|
|
|
*/
|
2000-12-06 01:04:45 +00:00
|
|
|
/* #include "xxdb.h" */
|
2000-11-27 19:12:23 +00:00
|
|
|
|
2000-06-01 18:49:22 +00:00
|
|
|
static isc_boolean_t want_stats = ISC_FALSE;
|
|
|
|
static const char * program_name = "named";
|
2000-08-09 03:44:42 +00:00
|
|
|
static char saved_command_line[512];
|
1999-07-24 01:17:44 +00:00
|
|
|
|
1999-10-23 01:07:22 +00:00
|
|
|
void
|
|
|
|
ns_main_earlyfatal(const char *format, ...) {
|
1999-07-24 01:17:44 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
1999-10-22 19:35:19 +00:00
|
|
|
if (ns_g_lctx != NULL) {
|
|
|
|
isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
|
|
|
format, args);
|
1999-10-23 00:02:23 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
|
|
|
"exiting (due to early fatal error)");
|
1999-10-22 19:35:19 +00:00
|
|
|
} else {
|
1999-10-25 18:58:43 +00:00
|
|
|
fprintf(stderr, "%s: ", program_name);
|
1999-10-22 19:35:19 +00:00
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
fprintf(stderr, "\n");
|
1999-10-23 00:33:04 +00:00
|
|
|
fflush(stderr);
|
1999-10-22 19:35:19 +00:00
|
|
|
}
|
1999-07-24 01:17:44 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1999-10-23 00:33:04 +00:00
|
|
|
static void
|
2000-06-01 18:49:22 +00:00
|
|
|
assertion_failed(const char *file, int line, isc_assertiontype_t type,
|
|
|
|
const char *cond)
|
|
|
|
{
|
1999-10-23 00:33:04 +00:00
|
|
|
/*
|
|
|
|
* Handle assertion failures.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ns_g_lctx != NULL) {
|
2000-01-31 15:23:10 +00:00
|
|
|
/*
|
|
|
|
* Reset the assetion callback in case it is the log
|
|
|
|
* routines causing the assertion.
|
|
|
|
*/
|
|
|
|
isc_assertion_setcallback(NULL);
|
|
|
|
|
1999-10-23 00:33:04 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
|
|
|
"%s:%d: %s(%s) failed", file, line,
|
|
|
|
isc_assertion_typetotext(type), cond);
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
2000-08-09 03:44:42 +00:00
|
|
|
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
2000-08-17 01:30:31 +00:00
|
|
|
"exiting (due to assertion failure)");
|
1999-10-23 00:33:04 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%s:%d: %s(%s) failed\n",
|
|
|
|
file, line, isc_assertion_typetotext(type), cond);
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ns_g_coreok)
|
|
|
|
abort();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-06-01 18:49:22 +00:00
|
|
|
library_fatal_error(const char *file, int line, const char *format,
|
|
|
|
va_list args)
|
|
|
|
{
|
1999-10-23 00:33:04 +00:00
|
|
|
/*
|
|
|
|
* Handle isc_error_fatal() calls from our libraries.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ns_g_lctx != NULL) {
|
2000-01-31 15:23:10 +00:00
|
|
|
/*
|
|
|
|
* Reset the error callback in case it is the log
|
|
|
|
* routines causing the assertion.
|
|
|
|
*/
|
|
|
|
isc_error_setfatal(NULL);
|
|
|
|
|
1999-10-23 00:33:04 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
2000-02-14 19:40:36 +00:00
|
|
|
"%s:%d: fatal error:", file, line);
|
1999-10-23 00:33:04 +00:00
|
|
|
isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
|
|
|
format, args);
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
|
|
|
"exiting (due to fatal error in library)");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%s:%d: fatal error: ", file, line);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ns_g_coreok)
|
|
|
|
abort();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2000-02-14 19:40:36 +00:00
|
|
|
static void
|
2000-06-01 18:49:22 +00:00
|
|
|
library_unexpected_error(const char *file, int line, const char *format,
|
|
|
|
va_list args)
|
|
|
|
{
|
2000-02-14 19:40:36 +00:00
|
|
|
/*
|
|
|
|
* Handle isc_error_unexpected() calls from our libraries.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ns_g_lctx != NULL) {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_MAIN, ISC_LOG_ERROR,
|
|
|
|
"%s:%d: unexpected error:", file, line);
|
|
|
|
isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_MAIN, ISC_LOG_ERROR,
|
|
|
|
format, args);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%s:%d: fatal error: ", file, line);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-21 01:16:27 +00:00
|
|
|
static void
|
|
|
|
lwresd_usage(void) {
|
|
|
|
fprintf(stderr,
|
2000-11-01 20:59:22 +00:00
|
|
|
"usage: lwresd [-c conffile | -C resolvconffile] "
|
2000-11-14 20:04:54 +00:00
|
|
|
"[-d debuglevel] [-f|-g]\n"
|
|
|
|
" [-n number_of_cpus] [-p port]"
|
|
|
|
"[-P listen-port] [-s]\n"
|
|
|
|
" [-t chrootdir] [-u username] [-i pidfile]\n");
|
2000-06-21 01:16:27 +00:00
|
|
|
}
|
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
static void
|
|
|
|
usage(void) {
|
2000-10-04 23:19:01 +00:00
|
|
|
if (ns_g_lwresdonly) {
|
|
|
|
lwresd_usage();
|
|
|
|
return;
|
|
|
|
}
|
1999-07-24 01:17:44 +00:00
|
|
|
fprintf(stderr,
|
2000-03-01 18:50:58 +00:00
|
|
|
"usage: named [-c conffile] [-d debuglevel] "
|
|
|
|
"[-f|-g] [-n number_of_cpus]\n"
|
2000-02-17 19:22:15 +00:00
|
|
|
" [-p port] [-s] [-t chrootdir] [-u username]\n");
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
|
2000-08-09 03:44:42 +00:00
|
|
|
static void
|
|
|
|
save_command_line(int argc, char *argv[]) {
|
|
|
|
int i;
|
|
|
|
char *src;
|
|
|
|
char *dst;
|
|
|
|
char *eob;
|
|
|
|
const char truncated[] = "...";
|
|
|
|
isc_boolean_t quoted = ISC_FALSE;
|
|
|
|
|
|
|
|
dst = saved_command_line;
|
|
|
|
eob = saved_command_line + sizeof(saved_command_line);
|
|
|
|
|
|
|
|
for (i = 1; i < argc && dst < eob; i++) {
|
|
|
|
*dst++ = ' ';
|
|
|
|
|
|
|
|
src = argv[i];
|
|
|
|
while (*src != '\0' && dst < eob) {
|
|
|
|
/*
|
|
|
|
* This won't perfectly produce a shell-independent
|
|
|
|
* pastable command line in all circumstances, but
|
|
|
|
* comes close, and for practical purposes will
|
|
|
|
* nearly always be fine.
|
|
|
|
*/
|
|
|
|
if (quoted || isalnum(*src & 0xff) ||
|
|
|
|
*src == '-' || *src == '_' ||
|
|
|
|
*src == '.' || *src == '/') {
|
|
|
|
*dst++ = *src++;
|
|
|
|
quoted = ISC_FALSE;
|
|
|
|
} else {
|
|
|
|
*dst++ = '\\';
|
|
|
|
quoted = ISC_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INSIST(sizeof(saved_command_line) >= sizeof(truncated));
|
|
|
|
|
|
|
|
if (dst == eob)
|
|
|
|
strcpy(eob - sizeof(truncated), truncated);
|
|
|
|
else
|
|
|
|
*dst = '\0';
|
|
|
|
}
|
|
|
|
|
2000-09-28 21:09:51 +00:00
|
|
|
static int
|
|
|
|
parse_int(char *arg, const char *desc) {
|
|
|
|
char *endp;
|
|
|
|
int tmp;
|
|
|
|
long int ltmp;
|
|
|
|
|
2000-09-28 21:21:31 +00:00
|
|
|
ltmp = strtol(arg, &endp, 10);
|
2000-09-28 21:09:51 +00:00
|
|
|
tmp = (int) ltmp;
|
|
|
|
if (*endp != '\0')
|
|
|
|
ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);
|
|
|
|
if (tmp < 0 || tmp != ltmp)
|
|
|
|
ns_main_earlyfatal("%s '%s' out of range", desc, arg);
|
|
|
|
return (tmp);
|
|
|
|
}
|
|
|
|
|
2000-08-01 01:33:37 +00:00
|
|
|
static void
|
1999-07-24 01:17:44 +00:00
|
|
|
parse_command_line(int argc, char *argv[]) {
|
|
|
|
int ch;
|
2000-09-28 21:09:51 +00:00
|
|
|
int port;
|
2000-06-19 18:55:46 +00:00
|
|
|
char *s;
|
|
|
|
|
2000-08-09 03:44:42 +00:00
|
|
|
save_command_line(argc, argv);
|
|
|
|
|
2000-09-16 01:42:06 +00:00
|
|
|
/*
|
|
|
|
* See if we should run as lwresd.
|
|
|
|
*/
|
2000-06-19 18:55:46 +00:00
|
|
|
s = strrchr(argv[0], '/');
|
|
|
|
if (s == NULL)
|
|
|
|
s = argv[0];
|
|
|
|
else
|
|
|
|
s++;
|
2000-10-04 23:19:01 +00:00
|
|
|
if (strcmp(s, "lwresd") == 0)
|
|
|
|
ns_g_lwresdonly = ISC_TRUE;
|
2000-09-16 01:42:06 +00:00
|
|
|
|
1999-10-25 18:58:43 +00:00
|
|
|
isc_commandline_errprint = ISC_FALSE;
|
2000-01-28 20:10:26 +00:00
|
|
|
while ((ch = isc_commandline_parse(argc, argv,
|
2000-10-04 23:19:01 +00:00
|
|
|
"c:C:d:fgi:ln:N:p:P:st:u:vx:")) !=
|
1999-10-23 00:02:23 +00:00
|
|
|
-1) {
|
1999-07-24 01:17:44 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'c':
|
1999-10-15 01:48:29 +00:00
|
|
|
ns_g_conffile = isc_commandline_argument;
|
2000-10-04 23:19:01 +00:00
|
|
|
lwresd_g_conffile = isc_commandline_argument;
|
2000-11-01 20:59:22 +00:00
|
|
|
if (lwresd_g_useresolvconf)
|
|
|
|
ns_main_earlyfatal("cannot specify -c and -C");
|
|
|
|
ns_g_conffileset = ISC_TRUE;
|
2000-10-04 23:19:01 +00:00
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
lwresd_g_resolvconffile = isc_commandline_argument;
|
2000-11-01 20:59:22 +00:00
|
|
|
if (ns_g_conffileset)
|
|
|
|
ns_main_earlyfatal("cannot specify -c and -C");
|
2000-10-13 22:35:46 +00:00
|
|
|
lwresd_g_useresolvconf = ISC_TRUE;
|
1999-07-24 01:17:44 +00:00
|
|
|
break;
|
1999-10-23 00:02:23 +00:00
|
|
|
case 'd':
|
2000-09-28 21:09:51 +00:00
|
|
|
ns_g_debuglevel = parse_int(isc_commandline_argument,
|
|
|
|
"debug level");
|
1999-10-23 00:02:23 +00:00
|
|
|
break;
|
2000-01-26 17:35:16 +00:00
|
|
|
case 'f':
|
|
|
|
ns_g_foreground = ISC_TRUE;
|
|
|
|
break;
|
2000-02-29 18:37:14 +00:00
|
|
|
case 'g':
|
|
|
|
ns_g_foreground = ISC_TRUE;
|
|
|
|
ns_g_logstderr = ISC_TRUE;
|
|
|
|
break;
|
2000-10-04 23:19:01 +00:00
|
|
|
/* XXXBEW -i should be removed */
|
|
|
|
case 'i':
|
|
|
|
lwresd_g_defaultpidfile = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
ns_g_lwresdonly = ISC_TRUE;
|
|
|
|
break;
|
2000-02-28 22:19:47 +00:00
|
|
|
case 'N': /* Deprecated. */
|
|
|
|
case 'n':
|
2000-09-28 21:09:51 +00:00
|
|
|
ns_g_cpus = parse_int(isc_commandline_argument,
|
|
|
|
"number of cpus");
|
1999-07-24 01:17:44 +00:00
|
|
|
if (ns_g_cpus == 0)
|
|
|
|
ns_g_cpus = 1;
|
|
|
|
break;
|
1999-09-09 02:19:11 +00:00
|
|
|
case 'p':
|
2000-09-28 21:09:51 +00:00
|
|
|
port = parse_int(isc_commandline_argument, "port");
|
2000-01-31 15:23:10 +00:00
|
|
|
if (port < 1 || port > 65535)
|
2000-03-01 22:41:59 +00:00
|
|
|
ns_main_earlyfatal("port '%s' out of range",
|
2000-01-31 15:23:10 +00:00
|
|
|
isc_commandline_argument);
|
|
|
|
ns_g_port = port;
|
1999-09-09 02:19:11 +00:00
|
|
|
break;
|
2000-10-04 23:19:01 +00:00
|
|
|
/* XXXBEW Should -P be removed? */
|
|
|
|
case 'P':
|
|
|
|
port = parse_int(isc_commandline_argument, "port");
|
|
|
|
if (port < 1 || port > 65535)
|
|
|
|
ns_main_earlyfatal("port '%s' out of range",
|
|
|
|
isc_commandline_argument);
|
|
|
|
lwresd_g_listenport = port;
|
|
|
|
break;
|
1999-07-24 01:17:44 +00:00
|
|
|
case 's':
|
|
|
|
/* XXXRTH temporary syntax */
|
|
|
|
want_stats = ISC_TRUE;
|
|
|
|
break;
|
2000-01-26 17:35:16 +00:00
|
|
|
case 't':
|
2000-01-28 20:10:26 +00:00
|
|
|
/* XXXJAB should we make a copy? */
|
2000-01-26 17:35:16 +00:00
|
|
|
ns_g_chrootdir = isc_commandline_argument;
|
|
|
|
break;
|
2000-01-28 20:10:26 +00:00
|
|
|
case 'u':
|
|
|
|
ns_g_username = isc_commandline_argument;
|
|
|
|
break;
|
2000-08-30 20:40:04 +00:00
|
|
|
case 'v':
|
|
|
|
printf("BIND %s\n", ns_g_version);
|
|
|
|
exit(0);
|
1999-10-25 18:58:43 +00:00
|
|
|
case '?':
|
2000-02-17 19:21:00 +00:00
|
|
|
usage();
|
2000-03-01 22:41:59 +00:00
|
|
|
ns_main_earlyfatal("unknown option '-%c'",
|
1999-10-25 18:58:43 +00:00
|
|
|
isc_commandline_option);
|
1999-07-24 01:17:44 +00:00
|
|
|
default:
|
1999-10-23 01:07:22 +00:00
|
|
|
ns_main_earlyfatal("parsing options returned %d", ch);
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-06 19:59:29 +00:00
|
|
|
argc -= isc_commandline_index;
|
|
|
|
argv += isc_commandline_index;
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2000-02-17 19:21:00 +00:00
|
|
|
if (argc > 0) {
|
1999-07-24 01:17:44 +00:00
|
|
|
usage();
|
1999-10-23 01:07:22 +00:00
|
|
|
ns_main_earlyfatal("extra command line arguments");
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2000-05-14 13:47:17 +00:00
|
|
|
create_managers(void) {
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2000-12-29 22:31:04 +00:00
|
|
|
#ifdef ISC_PLATFORM_USETHREADS
|
2000-06-22 01:09:14 +00:00
|
|
|
if (ns_g_cpus == 0)
|
|
|
|
ns_g_cpus = isc_os_ncpus();
|
2000-12-29 22:31:04 +00:00
|
|
|
#else
|
|
|
|
ns_g_cpus = 1;
|
|
|
|
#endif
|
2000-09-28 21:18:07 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
|
|
|
|
ISC_LOG_INFO, "using %u CPU%s",
|
|
|
|
ns_g_cpus, ns_g_cpus == 1 ? "" : "s");
|
1999-07-24 01:17:44 +00:00
|
|
|
result = isc_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
2000-02-17 19:58:59 +00:00
|
|
|
"ns_taskmgr_create() failed: %s",
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = isc_timermgr_create(ns_g_mctx, &ns_g_timermgr);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
2000-02-17 19:58:59 +00:00
|
|
|
"ns_timermgr_create() failed: %s",
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = isc_socketmgr_create(ns_g_mctx, &ns_g_socketmgr);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
2000-02-17 19:58:59 +00:00
|
|
|
"isc_socketmgr_create() failed: %s",
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
2000-06-21 22:12:02 +00:00
|
|
|
result = isc_entropy_create(ns_g_mctx, &ns_g_entropy);
|
2000-06-16 01:39:02 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
2000-06-21 22:12:02 +00:00
|
|
|
"isc_entropy_create() failed: %s",
|
2000-06-16 01:39:02 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
2000-08-17 19:17:57 +00:00
|
|
|
#ifdef PATH_RANDOMDEV
|
|
|
|
(void)isc_entropy_createfilesource(ns_g_entropy, PATH_RANDOMDEV);
|
2000-08-17 18:56:49 +00:00
|
|
|
#endif
|
2000-06-21 22:12:02 +00:00
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_managers(void) {
|
2000-10-04 23:19:01 +00:00
|
|
|
if (!ns_g_lwresdonly)
|
2000-07-10 11:35:02 +00:00
|
|
|
/*
|
|
|
|
* The omapi listeners need to be stopped here so that
|
|
|
|
* isc_taskmgr_destroy() won't block on the omapi task.
|
|
|
|
*/
|
|
|
|
ns_omapi_shutdown(ISC_TRUE);
|
2000-03-18 02:52:10 +00:00
|
|
|
|
2000-10-04 23:19:01 +00:00
|
|
|
ns_lwresd_shutdown();
|
|
|
|
|
2000-06-21 22:12:02 +00:00
|
|
|
isc_entropy_detach(&ns_g_entropy);
|
1999-07-24 01:17:44 +00:00
|
|
|
/*
|
|
|
|
* isc_taskmgr_destroy() will block until all tasks have exited,
|
|
|
|
*/
|
|
|
|
isc_taskmgr_destroy(&ns_g_taskmgr);
|
|
|
|
isc_timermgr_destroy(&ns_g_timermgr);
|
|
|
|
isc_socketmgr_destroy(&ns_g_socketmgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-05-14 13:47:17 +00:00
|
|
|
setup(void) {
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2000-07-01 00:48:06 +00:00
|
|
|
/*
|
|
|
|
* Get the user and group information before changing the root
|
|
|
|
* directory, so the administrator does not need to keep a copy
|
|
|
|
* of the user and group databases in the chroot'ed environment.
|
|
|
|
*/
|
|
|
|
ns_os_inituserinfo(ns_g_username);
|
|
|
|
|
2000-01-28 20:10:26 +00:00
|
|
|
ns_os_chroot(ns_g_chrootdir);
|
|
|
|
|
2000-04-11 18:51:19 +00:00
|
|
|
/*
|
|
|
|
* For operating systems which have a capability mechanism, now
|
|
|
|
* is the time to switch to minimal privs and change our user id.
|
|
|
|
* On traditional UNIX systems, this call will be a no-op, and we
|
|
|
|
* will change the user ID after reading the config file the first
|
|
|
|
* time. (We need to read the config file to know which possibly
|
|
|
|
* privileged ports to bind() to.)
|
|
|
|
*/
|
2000-07-01 00:48:06 +00:00
|
|
|
ns_os_minprivs();
|
2000-04-11 18:51:19 +00:00
|
|
|
|
2000-05-02 18:45:08 +00:00
|
|
|
result = ns_log_init(ISC_TF(ns_g_username != NULL));
|
1999-10-22 19:35:19 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-10-23 01:07:22 +00:00
|
|
|
ns_main_earlyfatal("ns_log_init() failed: %s",
|
|
|
|
isc_result_totext(result));
|
1999-10-22 19:35:19 +00:00
|
|
|
|
2000-01-26 21:13:19 +00:00
|
|
|
/*
|
|
|
|
* 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().
|
|
|
|
*/
|
2000-01-28 20:10:26 +00:00
|
|
|
if (!ns_g_foreground)
|
|
|
|
ns_os_daemonize();
|
2000-01-26 21:13:19 +00:00
|
|
|
|
1999-10-22 19:35:19 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
|
2000-08-09 03:44:42 +00:00
|
|
|
ISC_LOG_NOTICE, "starting BIND %s%s", ns_g_version,
|
|
|
|
saved_command_line);
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2000-11-14 23:59:21 +00:00
|
|
|
/*
|
|
|
|
* Get the initial resource limits.
|
|
|
|
*/
|
2000-11-15 02:11:50 +00:00
|
|
|
(void)isc_resource_getlimit(isc_resource_stacksize,
|
|
|
|
&ns_g_initstacksize);
|
|
|
|
(void)isc_resource_getlimit(isc_resource_datasize,
|
|
|
|
&ns_g_initdatasize);
|
|
|
|
(void)isc_resource_getlimit(isc_resource_coresize,
|
|
|
|
&ns_g_initcoresize);
|
|
|
|
(void)isc_resource_getlimit(isc_resource_openfiles,
|
|
|
|
&ns_g_initopenfiles);
|
2000-11-14 23:59:21 +00:00
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
result = create_managers();
|
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-10-23 01:07:22 +00:00
|
|
|
ns_main_earlyfatal("create_managers() failed: %s",
|
|
|
|
isc_result_totext(result));
|
1999-07-24 01:17:44 +00:00
|
|
|
|
2000-11-17 22:09:19 +00:00
|
|
|
/*
|
|
|
|
* Add calls to register sdb drivers here.
|
|
|
|
*/
|
2000-11-27 19:12:23 +00:00
|
|
|
/* xxdb_init(); */
|
2000-11-17 22:09:19 +00:00
|
|
|
|
2000-10-04 23:19:01 +00:00
|
|
|
ns_server_create(ns_g_mctx, &ns_g_server);
|
2000-01-31 15:23:10 +00:00
|
|
|
|
2000-10-04 23:19:01 +00:00
|
|
|
if (!ns_g_lwresdonly) {
|
2000-06-19 22:29:09 +00:00
|
|
|
result = ns_omapi_init();
|
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-07-10 11:35:02 +00:00
|
|
|
ns_main_earlyfatal("ns_omapi_init() failed: %s",
|
2000-06-19 22:29:09 +00:00
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-05-14 13:47:17 +00:00
|
|
|
cleanup(void) {
|
1999-07-24 01:17:44 +00:00
|
|
|
destroy_managers();
|
2000-07-10 11:35:02 +00:00
|
|
|
|
2000-10-04 23:19:01 +00:00
|
|
|
ns_server_destroy(&ns_g_server);
|
2000-07-10 11:35:02 +00:00
|
|
|
|
2000-11-17 22:09:19 +00:00
|
|
|
/*
|
|
|
|
* Add calls to unregister sdb drivers here.
|
|
|
|
*/
|
2000-11-27 19:12:23 +00:00
|
|
|
/* xxdb_clear(); */
|
2000-11-17 22:09:19 +00:00
|
|
|
|
1999-10-22 19:35:19 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
|
1999-10-23 00:02:23 +00:00
|
|
|
ISC_LOG_NOTICE, "exiting");
|
1999-10-22 19:35:19 +00:00
|
|
|
ns_log_shutdown();
|
1999-07-24 01:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[]) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
1999-10-25 18:58:43 +00:00
|
|
|
program_name = argv[0];
|
1999-10-23 00:33:04 +00:00
|
|
|
isc_assertion_setcallback(assertion_failed);
|
|
|
|
isc_error_setfatal(library_fatal_error);
|
2000-02-14 19:40:36 +00:00
|
|
|
isc_error_setunexpected(library_unexpected_error);
|
1999-10-23 00:33:04 +00:00
|
|
|
|
2000-07-18 17:50:02 +00:00
|
|
|
ns_os_init(program_name);
|
1999-10-23 01:07:22 +00:00
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
result = isc_app_start();
|
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-10-23 01:07:22 +00:00
|
|
|
ns_main_earlyfatal("isc_app_start() failed: %s",
|
|
|
|
isc_result_totext(result));
|
1999-07-24 01:17:44 +00:00
|
|
|
|
|
|
|
result = isc_mem_create(0, 0, &ns_g_mctx);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-10-23 01:07:22 +00:00
|
|
|
ns_main_earlyfatal("isc_mem_create() failed: %s",
|
|
|
|
isc_result_totext(result));
|
1999-07-24 01:17:44 +00:00
|
|
|
|
|
|
|
dns_result_register();
|
|
|
|
dst_result_register();
|
|
|
|
|
|
|
|
parse_command_line(argc, argv);
|
|
|
|
|
|
|
|
setup();
|
|
|
|
|
|
|
|
/*
|
2000-01-22 01:40:10 +00:00
|
|
|
* Start things running and then wait for a shutdown request
|
|
|
|
* or reload.
|
1999-07-24 01:17:44 +00:00
|
|
|
*/
|
2000-01-22 01:40:10 +00:00
|
|
|
do {
|
|
|
|
result = isc_app_run();
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-01-22 01:40:10 +00:00
|
|
|
if (result == ISC_R_RELOAD) {
|
2000-01-24 22:21:47 +00:00
|
|
|
ns_server_reloadwanted(ns_g_server);
|
2000-01-22 01:40:10 +00:00
|
|
|
} else if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"isc_app_run(): %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
/*
|
|
|
|
* Force exit.
|
|
|
|
*/
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
} while (result != ISC_R_SUCCESS);
|
1999-07-24 01:17:44 +00:00
|
|
|
|
|
|
|
cleanup();
|
|
|
|
|
2000-12-29 01:29:56 +00:00
|
|
|
if (want_stats) {
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_mem_stats(ns_g_mctx, stdout);
|
2000-12-29 01:29:56 +00:00
|
|
|
isc_mutex_stats(stdout);
|
|
|
|
}
|
1999-07-24 01:17:44 +00:00
|
|
|
isc_mem_destroy(&ns_g_mctx);
|
|
|
|
|
|
|
|
isc_app_finish();
|
|
|
|
|
1999-10-23 01:07:22 +00:00
|
|
|
ns_os_shutdown();
|
|
|
|
|
1999-07-24 01:17:44 +00:00
|
|
|
return (0);
|
|
|
|
}
|