} mem_debug_flags[] = { { \ TYBS_MEM_DEBUGTRACE }, { \ { \ { \ { \ { NULL, 0 } };
static void
set_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(\ found: if (*end == '\\0') break; arg = end + 1; } }
static void
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, \ \ switch (ch) { case '4': if (disable4) ns_main_earlyfatal(\ if (tybs_net_probeipv4() != TYBS_R_SUCCESS) ns_main_earlyfatal(\ tybs_net_disableipv6(); disable6 = TYBS_TRUE; break;
6 / 61
case '6': if (disable6) ns_main_earlyfatal(\ if (tybs_net_probeipv6() != TYBS_R_SUCCESS) ns_main_earlyfatal(\ tybs_net_disableipv4(); disable4 = TYBS_TRUE; break; case 'c': ns_g_conffile = tybs_commandline_argument; lwresd_g_conffile = tybs_commandline_argument; if (lwresd_g_useresolvconf) ns_main_earlyfatal(\ ns_g_conf = TYBS_TRUE; break; case 'C': lwresd_g_resolvconffile = tybs_commandline_argument; if (ns_g_conf) ns_main_earlyfatal(\ lwresd_g_useresolvconf = TYBS_TRUE; break; case 'd': ns_g_debuglevel = parse_int(tybs_commandline_argument, \ break; case 'f': ns_g_foreground = TYBS_TRUE; break; case 'g': ns_g_foreground = TYBS_TRUE; ns_g_logstderr = TYBS_TRUE; break;
/* XXXBEW -i should be removed */ case 'i': lwresd_g_defaultpidfile = tybs_commandline_argument; break; case 'l': ns_g_lwresdonly = TYBS_TRUE; break; case 'm': set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging); break;
case 'N': /* Deprecated. */ case 'n': ns_g_cpus = parse_int(tybs_commandline_argument, \ if (ns_g_cpus == 0) ns_g_cpus = 1; break; case 'p':
7 / 61
}
port = parse_int(tybs_commandline_argument, \ if (port < 1 || port > 65535) ns_main_earlyfatal(\ tybs_commandline_argument); ns_g_port = port; break;
/* XXXBEW Should -P be removed? */ case 'P': port = parse_int(tybs_commandline_argument, \ if (port < 1 || port > 65535) ns_main_earlyfatal(\ tybs_commandline_argument); lwresd_g_listenport = port; break; case 's': want_stats = TYBS_TRUE; break; case 'S': maxsocks = parse_int(tybs_commandline_argument, \ break; case 't': ns_g_chrootdir = tybs_commandline_argument; break; case 'T': if (strcmp(tybs_commandline_argument, \ ns_g_clienttest = TYBS_TRUE; else fprintf(stderr, \ tybs_commandline_argument); break; case 'u': ns_g_username = tybs_commandline_argument; break; case 'v': printf(\ exit(0); case 'V': printf(\ ns_g_configargs); exit(0); case '?': usage(); if (tybs_commandline_option == '?') exit(0); ns_main_earlyfatal(\ tybs_commandline_option); default: ns_main_earlyfatal(\}
8 / 61
argc -= tybs_commandline_index; argv += tybs_commandline_index; if (argc > 0) { usage(); ns_main_earlyfatal(\ } }
static tybs_result_t
create_managers(void) { tybs_result_t result; unsigned int socks;
#ifdef TYBS_PLATFORM_USETHREADS unsigned int cpus_detected; #endif
#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_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, \ cpus_detected, cpus_detected == 1 ? \ ns_g_cpus, ns_g_cpus == 1 ? \#else ns_g_cpus = 1; #endif result = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr); if (result != TYBS_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, \ tybs_result_totext(result)); return (TYBS_R_UNEXPECTED); } result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr); if (result != TYBS_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, \ tybs_result_totext(result)); return (TYBS_R_UNEXPECTED); } result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks); if (result != TYBS_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, \ tybs_result_totext(result)); return (TYBS_R_UNEXPECTED); } result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks); if (result == TYBS_R_SUCCESS) { tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, \
9 / 61
} result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy); if (result != TYBS_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, \ tybs_result_totext(result)); return (TYBS_R_UNEXPECTED); } result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE); if (result != TYBS_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, \ tybs_result_totext(result)); return (TYBS_R_UNEXPECTED); } return (TYBS_R_SUCCESS); }
static void
destroy_managers(void) { ns_lwresd_shutdown(); tybs_entropy_detach(&ns_g_entropy); if (ns_g_fallbackentropy != NULL) tybs_entropy_detach(&ns_g_fallbackentropy); tybs_taskmgr_destroy(&ns_g_taskmgr); tybs_timermgr_destroy(&ns_g_timermgr); tybs_socketmgr_destroy(&ns_g_socketmgr); tybs_hash_destroy(); }
static void setup(void) { tybs_result_t result; #ifdef HAVE_LIBSCF char *instance = NULL; #endif ns_os_inituserinfo(ns_g_username); ns_os_tzset(); ns_os_opendevnull(); #ifdef HAVE_LIBSCF result = ns_smf_get_instance(&instance, 0, ns_g_mctx); if (result == TYBS_R_SUCCESS) ns_smf_got_instance = 1; else ns_smf_got_instance = 0; if (instance != NULL) tybs_mem_free(ns_g_mctx, instance); #endif /* HAVE_LIBSCF */ #ifdef PATH_RANDOMDEV if (ns_g_chrootdir != NULL) { result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy); if (result != TYBS_R_SUCCESS) ns_main_earlyfatal(\
10 / 61
软件著作权-源代码范本
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)