int pre_server_startup(void) { pvpgn_greeting(); if (oom_setup() < 0) { eventlog(eventlog_level_error, __FUNCTION__, "OOM init failed"); return STATUS_OOM_FAILURE; } if (storage_init(prefs_get_storage_path()) < 0) { eventlog(eventlog_level_error, "pre_server_startup", "storage init failed"); return STATUS_STORAGE_FAILURE; } if (psock_init() < 0) { eventlog(eventlog_level_error, __FUNCTION__, "could not initialize socket functions"); return STATUS_PSOCK_FAILURE; } if (support_check_files(prefs_get_supportfile()) < 0) { eventlog(eventlog_level_error, "pre_server_startup","some needed files are missing"); eventlog(eventlog_level_error, "pre_server_startup","please make sure you installed the supportfiles in %s",prefs_get_filedir()); return STATUS_SUPPORT_FAILURE; } if (anongame_maplists_create() < 0) { eventlog(eventlog_level_error, "pre_server_startup", "could not load maps"); return STATUS_MAPLISTS_FAILURE; } if (anongame_matchlists_create() < 0) { eventlog(eventlog_level_error, "pre_server_startup", "could not create matchlists"); return STATUS_MATCHLISTS_FAILURE; } if (fdwatch_init(prefs_get_max_connections())) { eventlog(eventlog_level_error, __FUNCTION__, "error initilizing fdwatch"); return STATUS_FDWATCH_FAILURE; } connlist_create(); gamelist_create(); timerlist_create(); server_set_hostname(); channellist_create(); if (helpfile_init(prefs_get_helpfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load helpfile"); ipbanlist_create(); if (ipbanlist_load(prefs_get_ipbanfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load IP ban list"); if (adbannerlist_create(prefs_get_adfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load adbanner list"); if (autoupdate_load(prefs_get_mpqfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load autoupdate list"); if (versioncheck_load(prefs_get_versioncheck_file())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load versioncheck list"); if (news_load(prefs_get_newsfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load news list"); watchlist_create(); output_init(); attrlayer_init(); accountlist_create(); if (ladder_createxptable(prefs_get_xplevel_file(),prefs_get_xpcalc_file())<0) { eventlog(eventlog_level_error, "pre_server_startup", "could not load WAR3 xp calc tables"); return STATUS_WAR3XPTABLES_FAILURE; } ladders_init(); ladders_load_accounts_to_ladderlists(); ladder_update_all_accounts(); if (characterlist_create("")<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load character list"); if (prefs_get_track()) /* setup the tracking mechanism */ tracker_set_servers(prefs_get_trackserv_addrs()); if (command_groups_load(prefs_get_command_groups_file())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load command_groups list"); aliasfile_load(prefs_get_aliasfile()); if (trans_load(prefs_get_transfile(),TRANS_BNETD)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load trans list"); tournament_init(prefs_get_tournament_file()); anongame_infos_load(prefs_get_anongame_infos_file()); clanlist_load(); teamlist_load(); if (realmlist_create(prefs_get_realmfile())<0) eventlog(eventlog_level_error,__FUNCTION__,"could not load realm list"); topiclist_load(prefs_get_topicfile()); return 0; }
/** * Main routine, start of the program execution. * \param argc the number of arguments * \param argv pointer to the arguments array * \return don't return on sucess, -1 on error * \see main_loop */ int main(int argc, char** argv) { /* configure by default logging to syslog */ int cfg_log_stderr = 0; FILE* cfg_stream; int c,r; char *tmp; int tmp_len; int port; int proto; char *options; int ret; unsigned int seed; int rfd; /*init*/ ret=-1; my_argc=argc; my_argv=argv; /* process pkg mem size from command line */ opterr=0; options="f:cCm:M:b:l:n:N:rRvdDFETSVhw:t:u:g:P:G:W:o:"; while((c=getopt(argc,argv,options))!=-1) { switch(c) { case 'M': pkg_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024; if (tmp &&(*tmp)) { LM_ERR("bad pkgmem size number: -m %s\n", optarg); goto error00; }; break; } } /*init pkg mallocs (before parsing cfg but after parsing cmd line !)*/ if (init_pkg_mallocs()==-1) goto error00; init_route_lists(); /* process command line (get port no, cfg. file path etc) */ /* first reset getopt */ optind = 1; while((c=getopt(argc,argv,options))!=-1) { switch(c) { case 'f': cfg_file=optarg; break; case 'C': config_check |= 2; case 'c': if (config_check==3) break; config_check |= 1; cfg_log_stderr=1; /* force stderr logging */ break; case 'm': shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024; if (tmp &&(*tmp)) { LM_ERR("bad shmem size number: -m %s\n", optarg); goto error00; }; break; case 'M': /* ignoring it, parsed previously */ break; case 'b': maxbuffer=strtol(optarg, &tmp, 10); if (tmp &&(*tmp)) { LM_ERR("bad max buffer size number: -b %s\n", optarg); goto error00; } break; case 'l': if (parse_phostport(optarg, strlen(optarg), &tmp, &tmp_len, &port, &proto)<0) { LM_ERR("bad -l address specifier: %s\n", optarg); goto error00; } tmp[tmp_len]=0; /* null terminate the host */ /* add a new addr. to our address list */ if (add_cmd_listener(tmp, port, proto)!=0) { LM_ERR("failed to add new listen address\n"); goto error00; } break; case 'n': children_no=strtol(optarg, &tmp, 10); if ((tmp==0) ||(*tmp)) { LM_ERR("bad process number: -n %s\n", optarg); goto error00; } break; case 'v': check_via=1; break; case 'r': received_dns|=DO_DNS; break; case 'R': received_dns|=DO_REV_DNS; case 'd': (*debug)++; break; case 'D': dont_fork=1; break; case 'F': no_daemon_mode=1; break; case 'E': cfg_log_stderr=1; break; case 'N': tcp_children_no=strtol(optarg, &tmp, 10); if ((tmp==0) ||(*tmp)) { LM_ERR("bad process number: -N %s\n", optarg); goto error00; } break; case 'W': io_poll_method=get_poll_type(optarg); if (io_poll_method==POLL_NONE) { LM_ERR("bad poll method name: -W %s\ntry " "one of %s.\n", optarg, poll_support); goto error00; } break; case 'V': printf("version: %s\n", version); printf("flags: %s\n", flags ); print_ct_constants(); printf("%s compiled on %s with %s\n", __FILE__, compiled, COMPILER ); exit(0); break; case 'h': printf("version: %s\n", version); printf("%s",help_msg); exit(0); break; case 'w': working_dir=optarg; break; case 't': chroot_dir=optarg; break; case 'u': user=optarg; break; case 'g': group=optarg; break; case 'P': pid_file=optarg; break; case 'G': pgid_file=optarg; break; case 'o': if (add_arg_var(optarg) < 0) LM_ERR("cannot add option %s\n", optarg); break; case '?': if (isprint(optopt)) LM_ERR("Unknown option `-%c`.\n", optopt); else LM_ERR("Unknown option character `\\x%x`.\n", optopt); goto error00; case ':': LM_ERR("Option `-%c` requires an argument.\n", optopt); goto error00; default: abort(); } } log_stderr = cfg_log_stderr; /* fill missing arguments with the default values*/ if (cfg_file==0) cfg_file=CFG_FILE; /* load config file or die */ cfg_stream=fopen (cfg_file, "r"); if (cfg_stream==0) { LM_ERR("loading config file(%s): %s\n", cfg_file, strerror(errno)); goto error00; } /* seed the prng, try to use /dev/urandom if possible */ /* no debugging information is logged, because the standard log level prior the config file parsing is L_NOTICE */ seed=0; if ((rfd=open("/dev/urandom", O_RDONLY))!=-1) { try_again: if (read(rfd, (void*)&seed, sizeof(seed))==-1) { if (errno==EINTR) goto try_again; /* interrupted by signal */ LM_WARN("could not read from /dev/urandom (%d)\n", errno); } LM_DBG("initialize the pseudo random generator from " "/dev/urandom\n"); LM_DBG("read %u from /dev/urandom\n", seed); close(rfd); } else { LM_WARN("could not open /dev/urandom (%d)\n", errno); LM_WARN("using a unsafe seed for the pseudo random number generator"); } seed+=getpid()+time(0); LM_DBG("seeding PRNG with %u\n", seed); srand(seed); LM_DBG("test random number %u\n", rand()); /*register builtin modules*/ register_builtin_modules(); if (preinit_black_lists()!=0) { LM_CRIT("failed to alloc black list's anchor\n"); goto error00; } /* init avps */ if (init_global_avps() != 0) { LM_ERR("error while initializing avps\n"); goto error; } /* used for parser debugging */ #ifdef DEBUG_PARSER yydebug = 1; #endif /* * initializes transport interfaces - we initialize them here because we * can have listening interfaces declared in the command line */ if (trans_init() < 0) { LM_ERR("cannot initialize transport interface\n"); goto error; } /* parse the config file, prior to this only default values e.g. for debugging settings will be used */ yyin=cfg_stream; if ((yyparse()!=0)||(cfg_errors)) { LM_ERR("bad config file (%d errors)\n", cfg_errors); goto error00; } if (config_check>1 && check_rls()!=0) { LM_ERR("bad function call in config file\n"); return ret; } #ifdef EXTRA_DEBUG print_rl(); #endif if (no_daemon_mode+dont_fork > 1) { LM_ERR("cannot use -D (fork=no) and -F together\n"); return ret; } /* init the resolver, before fixing the config */ resolv_init(); fix_poll_method( &io_poll_method ); /* fix temporary listeners added in the cmd line */ if (fix_cmd_listeners() < 0) { LM_ERR("cannot add temproray listeners\n"); return ret; } /* load transport protocols */ if (trans_load() < 0) { LM_ERR("cannot load transport protocols\n"); goto error; } /* fix parameters */ if (working_dir==0) working_dir="/"; /* get uid/gid */ if (user) { if (user2uid(&uid, &gid, user)<0) { LM_ERR("bad user name/uid number: -u %s\n", user); goto error00; } } if (group) { if (group2gid(&gid, group)<0) { LM_ERR("bad group name/gid number: -u %s\n", group); goto error00; } } if (fix_all_socket_lists()!=0) { LM_ERR("failed to initialize list addresses\n"); goto error00; } /* print all the listen addresses */ printf("Listening on \n"); print_all_socket_lists(); printf("Aliases: \n"); /*print_aliases();*/ print_aliases(); printf("\n"); if (dont_fork) { LM_WARN("no fork mode %s\n", (protos[PROTO_UDP].listeners)?( (protos[PROTO_UDP].listeners->next)?" and more than one listen" " address found(will use only the first one)":"" ):"and no udp listen address found" ); } if (config_check) { LM_NOTICE("config file ok, exiting...\n"); return 0; } time(&startup_time); /*init shm mallocs * this must be here * -to allow setting shm mem size from the command line * => if shm_mem should be settable from the cfg file move * everything after * -it must be also before init_timer and init_tcp * -it must be after we know uid (so that in the SYSV sems case, * the sems will have the correct euid) * --andrei */ if (init_shm_mallocs()==-1) goto error; /* Init statistics */ if (init_stats_collector()<0) { LM_ERR("failed to initialize statistics\n"); goto error; } init_shm_statistics(); /*init UDP networking layer*/ if (udp_init()<0) { LM_CRIT("could not initialize tcp, exiting...\n"); goto error; } /*init TCP networking layer*/ if (tcp_init()<0) { LM_CRIT("could not initialize tcp, exiting...\n"); goto error; } /* init_daemon? */ if (!dont_fork) { if ( daemonize((log_name==0)?argv[0]:log_name, &own_pgid) <0 ) goto error; } /* install signal handlers */ if (install_sigs() != 0) { LM_ERR("could not install the signal handlers\n"); goto error; } if (disable_core_dump) set_core_dump(0, 0); else set_core_dump(1, shm_mem_size+pkg_mem_size+4*1024*1024); if (open_files_limit>0) { if(increase_open_fds(open_files_limit)<0) { LM_ERR("ERROR: error could not increase file limits\n"); goto error; } } /* print OpenSIPS version to log for history tracking */ LM_NOTICE("version: %s\n", version); /* print some data about the configuration */ LM_INFO("using %ld Mb shared memory\n", ((shm_mem_size/1024)/1024)); LM_INFO("using %ld Mb private memory per process\n", ((pkg_mem_size/1024)/1024)); /* init timer */ if (init_timer()<0) { LM_CRIT("could not initialize timer, exiting...\n"); goto error; } /* init serial forking engine */ if (init_serialization()!=0) { LM_ERR("failed to initialize serialization\n"); goto error; } /* Init MI */ if (init_mi_core()<0) { LM_ERR("failed to initialize MI core\n"); goto error; } /* Register core events */ if (evi_register_core() != 0) { LM_ERR("failed register core events\n"); goto error; } /* init black list engine */ if (init_black_lists()!=0) { LM_CRIT("failed to init blacklists\n"); goto error; } /* init resolver's blacklist */ if (resolv_blacklist_init()!=0) { LM_CRIT("failed to create DNS blacklist\n"); goto error; } /* init modules */ if (init_modules() != 0) { LM_ERR("error while initializing modules\n"); goto error; } /* register route timers */ if(register_route_timers() < 0) { LM_ERR("Failed to register timer\n"); goto error; } /* check pv context list */ if(pv_contextlist_check() != 0) { LM_ERR("used pv context that was not defined\n"); goto error; } /* init query list now in shm * so all processes that will be forked from now on * will have access to it * * if it fails, give it a try and carry on */ if (init_ql_support() != 0) { LM_ERR("failed to initialise buffering query list\n"); query_buffer_size = 0; *query_list = NULL; } /* init multi processes support */ if (init_multi_proc_support()!=0) { LM_ERR("failed to init multi-proc support\n"); goto error; } #ifdef PKG_MALLOC /* init stats support for pkg mem */ if (init_pkg_stats(counted_processes)!=0) { LM_ERR("failed to init stats for pkg\n"); goto error; } #endif /* init avps */ if (init_extra_avps() != 0) { LM_ERR("error while initializing avps\n"); goto error; } /* fix routing lists */ if ( (r=fix_rls())!=0) { LM_ERR("failed to fix configuration with err code %d\n", r); goto error; }; ret=main_loop(); error: /*kill everything*/ kill_all_children(SIGTERM); /*clean-up*/ cleanup(0); error00: return ret; }
extern int trans_reload(char const * filename, int program) { trans_unload(); if (trans_load(filename, program) < 0) return -1; return 0; }