1、dst/result.h#define NS_MAIN 1named/ns_smf_globals.h#endif#ifdef DLZdlz/dlz_drivers.hstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_nameTYBS_DIR_NAMEMAX = named;static char absolute_conffileTYBS_DIR_PATHMAX;static char saved_command_line512;static char version512;static unsigned in
2、t maxsocks = 0;voidns_main_earlywarning(const char *format, .) va_list args;va_start(args, format);if (ns_g_lctx != NULL) tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_WARNING, format, args); else fprintf(stderr, %s: , program_name);vfprintf(stderr, format, args);n);
3、fflush(stderr);va_end(args);Void ns_main_earlyfatal(const char *format, .) tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL, format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL, exiting (due to early fatal error)
4、exit(1);static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond)tybs_assertion_setcallback(NULL);%d: %s(%s) failed, file, line, tybs_assertion_typetotext(type), cond);exiting (due to assertion failure) %s(%s) failedn,file, line, tybs_assertion_typetotext(ty
5、pe), cond);if (ns_g_coreok)abort();library_fatal_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);library_fatal_error(const char *file, int line, const char *format,va_list args)tybs_error_setfatal(NULL); fatal error:, file, line);exiting (due to fatal err
6、or in library)library_unexpected_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);library_unexpected_error(const char *file, int line, const char *format, va_list args)tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_ERROR, une
7、xpected error:tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_ERROR, format, args);lwresd_usage(void) fprintf(stderr,usage: lwresd -4|-6 -c conffile | -C resolvconffile -d debugleveln -f|-g -n number_of_cpus -p port -P listen-port -sn -t chrootdir -u username -i pidfil
8、en -m usage|trace|record|size|mctxnusage(void) if (ns_g_lwresdonly) lwresd_usage();return; named -4|-6 -c conffile -d debuglevel -f|-g -n number_of_cpusn -p port -s -t chrootdir -u usernamenstatic void save_command_line(int argc, char *argv) int i;char *src;char *dst;char *eob; const char truncated
9、= . tybs_boolean_t quoted = TYBS_FALSE; dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line); for (i = 1; i argc & dst = sizeof(truncated); if (dst = eob)strcpy(eob - sizeof(truncated), truncated); else*dst = static int parse_int(char *arg, const char *desc) char *endp;int
10、tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp !)ns_main_earlyfatal(%s %s must be numeric, desc, arg); if (tmp name != NULL; def+) if (arglen = (int)strlen(def-name) & memcmp(arg, def-name, arglen) = 0) *ret |= def-value; goto found;unrecognized flag %.*s, arglen, arg); f
11、ound:if (*end = break;arg = end + 1;parse_command_line(int argc, char *argv) int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE; save_command_line(argc, argv); tybs_commandline_errprint = TYBS_FALSE;while (ch = tybs_commandline_parse(argc, argv, 46c:C:d:fgi:lm:
12、n:N:p:P:sS:t:T:u:vVx:) != -1) switch (ch) case 4:if (disable4) ns_main_earlyfatal(cannot specify -4 and -6if (tybs_net_probeipv4() != TYBS_R_SUCCESS) ns_main_earlyfatal(IPv4 not supported by OStybs_net_disableipv6(); disable6 = TYBS_TRUE; break;case 6if (disable6) if (tybs_net_probeipv6() !IPv6 not
13、supported by OS tybs_net_disableipv4(); disable4 = TYBS_TRUE;cns_g_conffile = tybs_commandline_argument; lwresd_g_conffile = tybs_commandline_argument; if (lwresd_g_useresolvconf)cannot specify -c and -C ns_g_conffileset = TYBS_TRUE;C lwresd_g_resolvconffile = tybs_commandline_argument; if (ns_g_con
14、ffileset) lwresd_g_useresolvconf = TYBS_TRUE;dns_g_debuglevel = parse_int(tybs_commandline_argument,debug levelf ns_g_foreground = TYBS_TRUE;g ns_g_logstderr = TYBS_TRUE;/* XXXBEW -i should be removed */ilwresd_g_defaultpidfile = tybs_commandline_argument;lns_g_lwresdonly = TYBS_TRUE;mset_flags(tybs
15、_commandline_argument, mem_debug_flags, &tybs_mem_debugging);N /* Deprecated. */nns_g_cpus = parse_int(tybs_commandline_argument, number of cpusif (ns_g_cpus = 0)ns_g_cpus = 1;pport = parse_int(tybs_commandline_argument, portif (port 65535) ns_main_earlyfatal(port , tybs_commandline_argument);ns_g_p
16、ort = port;/* XXXBEW Should -P be removed? */Plwresd_g_listenport = port;swant_stats = TYBS_TRUE;Smaxsocks = parse_int(tybs_commandline_argument, max number of socketstns_g_chrootdir = tybs_commandline_argument;Tif (strcmp(tybs_commandline_argument, clienttest) = 0) ns_g_clienttest = TYBS_TRUE;else
17、fprintf(stderr, unknown -T flag %snuns_g_username = tybs_commandline_argument;vprintf(BIND %sn, ns_g_version);exit(0);VBIND %s built with %sn, ns_g_version, ns_g_configargs);?usage();if (tybs_commandline_option = unknown option -%c, tybs_commandline_option);default:parsing options returned %d, ch);a
18、rgc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc 0) ns_main_earlyfatal(extra command line argumentsstatic tybs_result_tcreate_managers(void) tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#ifdef TYBS_PLATFORM_USETHREADS cpus_detected = tybs_os_ncpus(); if (ns_g_cpus = 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1