📄 main.c
字号:
/* * Copyright (C) 1999-2003 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. *//* $Id: main.c,v 1.119.2.5 2003/10/09 07:32:33 marka Exp $ */#include <config.h>#include <ctype.h>#include <stdlib.h>#include <string.h>#include <isc/app.h>#include <isc/commandline.h>#include <isc/dir.h>#include <isc/entropy.h>#include <isc/file.h>#include <isc/hash.h>#include <isc/os.h>#include <isc/platform.h>#include <isc/resource.h>#include <isc/task.h>#include <isc/timer.h>#include <isc/util.h>#include <isccc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>/* * Defining NS_MAIN provides storage declarations (rather than extern) * for variables in named/globals.h. */#define NS_MAIN 1#include <named/control.h>#include <named/globals.h> /* Explicit, though named/log.h includes it. */#include <named/interfacemgr.h>#include <named/log.h>#include <named/os.h>#include <named/server.h>#include <named/lwresd.h>#include <named/main.h>/* * Include header files for database drivers here. *//* #include "xxdb.h" */static isc_boolean_t want_stats = ISC_FALSE;static char program_name[ISC_DIR_NAMEMAX] = "named";static char absolute_conffile[ISC_DIR_PATHMAX];static char saved_command_line[512];voidns_main_earlywarning(const char *format, ...) { va_list args; va_start(args, format); if (ns_g_lctx != NULL) { isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, ISC_LOG_WARNING, format, args); } else { fprintf(stderr, "%s: ", program_name); vfprintf(stderr, format, args); fprintf(stderr, "\n"); fflush(stderr); } va_end(args);}voidns_main_earlyfatal(const char *format, ...) { va_list args; va_start(args, format); if (ns_g_lctx != NULL) { 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 early fatal error)"); } else { fprintf(stderr, "%s: ", program_name); vfprintf(stderr, format, args); fprintf(stderr, "\n"); fflush(stderr); } va_end(args); exit(1);}static voidassertion_failed(const char *file, int line, isc_assertiontype_t type, const char *cond){ /* * Handle assertion failures. */ if (ns_g_lctx != NULL) { /* * Reset the assetion callback in case it is the log * routines causing the assertion. */ isc_assertion_setcallback(NULL); 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, NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL, "exiting (due to assertion failure)"); } 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 voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args) ISC_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args){ /* * Handle isc_error_fatal() calls from our libraries. */ if (ns_g_lctx != NULL) { /* * Reset the error callback in case it is the log * routines causing the assertion. */ isc_error_setfatal(NULL); isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL, "%s:%d: fatal error:", file, line); 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);}static voidlibrary_unexpected_error(const char *file, int line, const char *format, va_list args) ISC_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format, va_list args){ /* * 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); }}static voidlwresd_usage(void) { fprintf(stderr, "usage: lwresd [-c conffile | -C resolvconffile] " "[-d debuglevel] [-f|-g]\n" " [-n number_of_cpus] [-p port]" "[-P listen-port] [-s]\n" " [-t chrootdir] [-u username] [-i pidfile]\n");}static voidusage(void) { if (ns_g_lwresdonly) { lwresd_usage(); return; } fprintf(stderr, "usage: named [-c conffile] [-d debuglevel] " "[-f|-g] [-n number_of_cpus]\n" " [-p port] [-s] [-t chrootdir] [-u username]\n");}static voidsave_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';}static intparse_int(char *arg, const char *desc) { char *endp; int tmp; long int ltmp; ltmp = strtol(arg, &endp, 10); 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);}static voidparse_command_line(int argc, char *argv[]) { int ch; int port; save_command_line(argc, argv); isc_commandline_errprint = ISC_FALSE; while ((ch = isc_commandline_parse(argc, argv, "c:C:d:fgi:ln:N:p:P:st:u:vx:")) != -1) { switch (ch) { case 'c': ns_g_conffile = isc_commandline_argument; lwresd_g_conffile = isc_commandline_argument; if (lwresd_g_useresolvconf) ns_main_earlyfatal("cannot specify -c and -C"); ns_g_conffileset = ISC_TRUE; break; case 'C': lwresd_g_resolvconffile = isc_commandline_argument; if (ns_g_conffileset) ns_main_earlyfatal("cannot specify -c and -C"); lwresd_g_useresolvconf = ISC_TRUE; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -