⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 bind 9.3结合mysql数据库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC") * 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 ISC DISCLAIMS ALL WARRANTIES WITH * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS.  IN NO EVENT SHALL ISC 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.3.2.16 2004/09/01 07:16:35 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/stdio.h>#include <isc/string.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>#ifdef HAVE_LIBSCF#include <libscf.h>#endif/* * Defining NS_MAIN provides storage declarations (rather than extern) * for variables in named/globals.h. */#define NS_MAIN 1#include <named/builtin.h>#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" */#include "mysqldb.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];static char		version[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 [-4|-6] [-c conffile | -C resolvconffile] "		"[-d debuglevel]\n"		"              [-f|-g] [-n number_of_cpus] [-p port] "		"[-P listen-port] [-s]\n"		"              [-t chrootdir] [-u username] [-i pidfile]\n"		"              [-m {usage|trace|record}]\n");}static voidusage(void) {	if (ns_g_lwresdonly) {		lwresd_usage();		return;	}	fprintf(stderr,		"usage: named [-4|-6] [-c conffile] [-d debuglevel] "		"[-f|-g] [-n number_of_cpus]\n"		"             [-p port] [-s] [-t chrootdir] [-u username]\n"		"             [-m {usage|trace|record}]\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 struct flag_def {	const char *name;	unsigned int value;} mem_debug_flags[] = {	{ "trace",  ISC_MEM_DEBUGTRACE },	{ "record", ISC_MEM_DEBUGRECORD },	{ "usage", ISC_MEM_DEBUGUSAGE },	{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {	for (;;) {		const struct flag_def *def;		const char *end = strchr(arg, ',');		int arglen;		if (end == NULL)			end = arg + strlen(arg);		arglen = end - arg;		for (def = defs; def->name != NULL; def++) {			if (arglen == (int)strlen(def->name) &&			    memcmp(arg, def->name, arglen) == 0) {				*ret |= def->value;				goto found;			}		}		ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);	 found:		if (*end == '\0')			break;		arg = end + 1;	}}static voidparse_command_line(int argc, char *argv[]) {	int ch;	int port;	isc_boolean_t disable6 = ISC_FALSE;	isc_boolean_t disable4 = ISC_FALSE;	save_command_line(argc, argv);	isc_commandline_errprint = ISC_FALSE;	while ((ch = isc_commandline_parse(argc, argv,			           "46c:C:d:fgi:lm:n:N:p:P:st:u:vx:")) != -1) {		switch (ch) {		case '4':			if (disable4)				ns_main_earlyfatal("cannot specify -4 and -6");			if (isc_net_probeipv4() != ISC_R_SUCCESS)				ns_main_earlyfatal("IPv4 not supported by OS");			isc_net_disableipv6();			disable6 = ISC_TRUE;			break;		case '6':			if (disable6)				ns_main_earlyfatal("cannot specify -4 and -6");			if (isc_net_probeipv6() != ISC_R_SUCCESS)				ns_main_earlyfatal("IPv6 not supported by OS");			isc_net_disableipv4();			disable4 = ISC_TRUE;			break;		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;		case 'd':			ns_g_debuglevel = parse_int(isc_commandline_argument,						    "debug level");			break;		case 'f':			ns_g_foreground = ISC_TRUE;			break;		case 'g':			ns_g_foreground = ISC_TRUE;			ns_g_logstderr = ISC_TRUE;			break;		/* XXXBEW -i should be removed */		case 'i':			lwresd_g_defaultpidfile = isc_commandline_argument;			break;		case 'l':			ns_g_lwresdonly = ISC_TRUE;			break;		case 'm':			set_flags(isc_commandline_argument, mem_debug_flags,				  &isc_mem_debugging);			break;		case 'N': /* Deprecated. */		case 'n':			ns_g_cpus = parse_int(isc_commandline_argument,					      "number of cpus");			if (ns_g_cpus == 0)				ns_g_cpus = 1;			break;		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);			ns_g_port = port;			break;		/* 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;		case 's':			/* XXXRTH temporary syntax */			want_stats = ISC_TRUE;			break;		case 't':			/* XXXJAB should we make a copy? */			ns_g_chrootdir = isc_commandline_argument;			break;		case 'u':			ns_g_username = isc_commandline_argument;			break;		case 'v':			printf("BIND %s\n", ns_g_version);			exit(0);		case '?':			usage();			ns_main_earlyfatal("unknown option '-%c'",					   isc_commandline_option);		default:			ns_main_earlyfatal("parsing options returned %d", ch);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -