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

📄 main.c

📁 非常好的dns解析软件
💻 C
📖 第 1 页 / 共 2 页
字号:
static isc_result_tcreate_managers(void) {	isc_result_t result;#ifdef ISC_PLATFORM_USETHREADS	unsigned int cpus_detected;#endif#ifdef ISC_PLATFORM_USETHREADS	cpus_detected = isc_os_ncpus();	if (ns_g_cpus == 0)		ns_g_cpus = cpus_detected;	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,		      ISC_LOG_INFO, "found %u CPU%s, using %u worker thread%s",		      cpus_detected, cpus_detected == 1 ? "" : "s",		      ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#else	ns_g_cpus = 1;#endif	result = isc_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);	if (result != ISC_R_SUCCESS) {		UNEXPECTED_ERROR(__FILE__, __LINE__,				 "isc_taskmgr_create() failed: %s",				 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__,				 "isc_timermgr_create() failed: %s",				 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__,				 "isc_socketmgr_create() failed: %s",				 isc_result_totext(result));		return (ISC_R_UNEXPECTED);	}	result = isc_entropy_create(ns_g_mctx, &ns_g_entropy);	if (result != ISC_R_SUCCESS) {		UNEXPECTED_ERROR(__FILE__, __LINE__,				 "isc_entropy_create() failed: %s",				 isc_result_totext(result));		return (ISC_R_UNEXPECTED);	}	result = isc_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);	if (result != ISC_R_SUCCESS) {		UNEXPECTED_ERROR(__FILE__, __LINE__,				 "isc_hash_create() failed: %s",				 isc_result_totext(result));		return (ISC_R_UNEXPECTED);	}	return (ISC_R_SUCCESS);}static voiddestroy_managers(void) {	ns_lwresd_shutdown();	isc_entropy_detach(&ns_g_entropy);	if (ns_g_fallbackentropy != NULL)		isc_entropy_detach(&ns_g_fallbackentropy);	/*	 * 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);	/*	 * isc_hash_destroy() cannot be called as long as a resolver may be	 * running.  Calling this after isc_taskmgr_destroy() ensures the	 * call is safe.	 */	isc_hash_destroy();}static voidsetup(void) {	isc_result_t result;#ifdef HAVE_LIBSCF	char *instance = NULL;#endif	/*	 * 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);	/*	 * Initialize time conversion information	 */	ns_os_tzset();	ns_os_opendevnull();#ifdef HAVE_LIBSCF	/* Check if named is under smf control, before chroot. */	result = ns_smf_get_instance(&instance, 0, ns_g_mctx);	/* We don't care about instance, just check if we got one. */	if (result == ISC_R_SUCCESS)		ns_smf_got_instance = 1;	else		ns_smf_got_instance = 0;	if (instance != NULL)		isc_mem_free(ns_g_mctx, instance);#endif /* HAVE_LIBSCF */#ifdef PATH_RANDOMDEV	/*	 * Initialize system's random device as fallback entropy source	 * if running chroot'ed.	 */	if (ns_g_chrootdir != NULL) {		result = isc_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);		if (result != ISC_R_SUCCESS)			ns_main_earlyfatal("isc_entropy_create() failed: %s",					   isc_result_totext(result));		result = isc_entropy_createfilesource(ns_g_fallbackentropy,						      PATH_RANDOMDEV);		if (result != ISC_R_SUCCESS) {			ns_main_earlywarning("could not open pre-chroot "					     "entropy source %s: %s",					     PATH_RANDOMDEV,					     isc_result_totext(result));			isc_entropy_detach(&ns_g_fallbackentropy);		}	}#endif	ns_os_chroot(ns_g_chrootdir);	/*	 * 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.)	 */	ns_os_minprivs();	result = ns_log_init(ISC_TF(ns_g_username != NULL));	if (result != ISC_R_SUCCESS)		ns_main_earlyfatal("ns_log_init() failed: %s",				   isc_result_totext(result));	/*	 * 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)		ns_os_daemonize();	/*	 * We call isc_app_start() here as some versions of FreeBSD's fork()	 * destroys all the signal handling it sets up.	 */	result = isc_app_start();	if (result != ISC_R_SUCCESS)		ns_main_earlyfatal("isc_app_start() failed: %s",				   isc_result_totext(result));	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,		      ISC_LOG_NOTICE, "starting BIND %s%s", ns_g_version,		      saved_command_line);	/*	 * Get the initial resource limits.	 */	(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);	/*	 * If the named configuration filename is relative, prepend the current	 * directory's name before possibly changing to another directory.	 */	if (! isc_file_isabsolute(ns_g_conffile)) {		result = isc_file_absolutepath(ns_g_conffile,					       absolute_conffile,					       sizeof(absolute_conffile));		if (result != ISC_R_SUCCESS)			ns_main_earlyfatal("could not construct absolute path of "					   "configuration file: %s", 					   isc_result_totext(result));		ns_g_conffile = absolute_conffile;	}	result = create_managers();	if (result != ISC_R_SUCCESS)		ns_main_earlyfatal("create_managers() failed: %s",				   isc_result_totext(result));	ns_builtin_init();	/*	 * Add calls to register sdb drivers here.	 */	/* xxdb_init(); */#ifdef DLZ	/*	 * Registyer any DLZ drivers.	 */	result = dlz_drivers_init();	if (result != ISC_R_SUCCESS)		ns_main_earlyfatal("dlz_drivers_init() failed: %s",				   isc_result_totext(result));#endif	ns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {	destroy_managers();	ns_server_destroy(&ns_g_server);	ns_builtin_deinit();	/*	 * Add calls to unregister sdb drivers here.	 */	/* xxdb_clear(); */#ifdef DLZ	/*	 * Unregister any DLZ drivers.	 */	dlz_drivers_clear();#endif	dns_name_destroy();	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,		      ISC_LOG_NOTICE, "exiting");	ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {	/*	 * Caller has to ensure locking.	 */	if (memstats != NULL) {		free(memstats);		memstats = NULL;	}	if (filename == NULL)		return;	memstats = malloc(strlen(filename) + 1);	if (memstats)		strcpy(memstats, filename);}#ifdef HAVE_LIBSCF/* * Get FMRI for the named process. */isc_result_tns_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx) {	scf_handle_t *h = NULL;	int namelen;	char *instance;	REQUIRE(ins_name != NULL && *ins_name == NULL);	if ((h = scf_handle_create(SCF_VERSION)) == NULL) {		if (debug)			UNEXPECTED_ERROR(__FILE__, __LINE__,					 "scf_handle_create() failed: %s",			 		 scf_strerror(scf_error()));		return (ISC_R_FAILURE);	}	if (scf_handle_bind(h) == -1) {		if (debug)			UNEXPECTED_ERROR(__FILE__, __LINE__,					 "scf_handle_bind() failed: %s",					 scf_strerror(scf_error()));		scf_handle_destroy(h);		return (ISC_R_FAILURE);	}	if ((namelen = scf_myname(h, NULL, 0)) == -1) {		if (debug)			UNEXPECTED_ERROR(__FILE__, __LINE__,					 "scf_myname() failed: %s",					 scf_strerror(scf_error()));		scf_handle_destroy(h);		return (ISC_R_FAILURE);	}	if ((instance = isc_mem_allocate(mctx, namelen + 1)) == NULL) {		UNEXPECTED_ERROR(__FILE__, __LINE__,				 "ns_smf_get_instance memory "				 "allocation failed: %s",				 isc_result_totext(ISC_R_NOMEMORY));		scf_handle_destroy(h);		return (ISC_R_FAILURE);	}	if (scf_myname(h, instance, namelen + 1) == -1) {		if (debug)			UNEXPECTED_ERROR(__FILE__, __LINE__,					 "scf_myname() failed: %s",					 scf_strerror(scf_error()));		scf_handle_destroy(h);		isc_mem_free(mctx, instance);		return (ISC_R_FAILURE);	}	scf_handle_destroy(h);	*ins_name = instance;	return (ISC_R_SUCCESS);}#endif /* HAVE_LIBSCF */intmain(int argc, char *argv[]) {	isc_result_t result;#ifdef HAVE_LIBSCF	char *instance = NULL;#endif	/*	 * Record version in core image.	 * strings named.core | grep "named version:"	 */	strlcat(version,#ifdef __DATE__		"named version: BIND " VERSION " (" __DATE__ ")",#else		"named version: BIND " VERSION,#endif		sizeof(version));	result = isc_file_progname(*argv, program_name, sizeof(program_name));	if (result != ISC_R_SUCCESS)		ns_main_earlyfatal("program name too long");	if (strcmp(program_name, "lwresd") == 0)		ns_g_lwresdonly = ISC_TRUE;	isc_assertion_setcallback(assertion_failed);	isc_error_setfatal(library_fatal_error);	isc_error_setunexpected(library_unexpected_error);	ns_os_init(program_name);	dns_result_register();	dst_result_register();	isccc_result_register();	parse_command_line(argc, argv);	/*	 * Warn about common configuration error.	 */	if (ns_g_chrootdir != NULL) {		int len = strlen(ns_g_chrootdir);		if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&		    (ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))			ns_main_earlywarning("config filename (-c %s) contains "					     "chroot path (-t %s)",					     ns_g_conffile, ns_g_chrootdir);	}	result = isc_mem_create(0, 0, &ns_g_mctx);	if (result != ISC_R_SUCCESS)		ns_main_earlyfatal("isc_mem_create() failed: %s",				   isc_result_totext(result));	setup();	/*	 * Start things running and then wait for a shutdown request	 * or reload.	 */	do {		result = isc_app_run();		if (result == ISC_R_RELOAD) {			ns_server_reloadwanted(ns_g_server);		} 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);#ifdef HAVE_LIBSCF	if (ns_smf_want_disable == 1) {		result = ns_smf_get_instance(&instance, 1, ns_g_mctx);		if (result == ISC_R_SUCCESS && instance != NULL) {			if (smf_disable_instance(instance, 0) != 0)				UNEXPECTED_ERROR(__FILE__, __LINE__,						 "smf_disable_instance() "						 "failed for %s : %s",						 instance,						 scf_strerror(scf_error()));		}		if (instance != NULL)			isc_mem_free(ns_g_mctx, instance);	}#endif /* HAVE_LIBSCF */	cleanup();	if (want_stats) {		isc_mem_stats(ns_g_mctx, stdout);		isc_mutex_stats(stdout);	}	if (memstats != NULL) {		FILE *fp = NULL;		result = isc_stdio_open(memstats, "w", &fp);		if (result == ISC_R_SUCCESS) {			isc_mem_stats(ns_g_mctx, fp);			isc_mutex_stats(fp);			isc_stdio_close(fp);		}	}	isc_mem_destroy(&ns_g_mctx);	isc_mem_checkdestroyed(stderr);	ns_main_setmemstats(NULL);	isc_app_finish();	ns_os_closedevnull();	ns_os_shutdown();	return (0);}

⌨️ 快捷键说明

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