static void init_everything(void) { log_init("rtpengine"); log_format(rtpe_config.log_format); recording_fs_init(rtpe_config.spooldir, rtpe_config.rec_method, rtpe_config.rec_format); rtpe_ssl_init(); #if !GLIB_CHECK_VERSION(2,32,0) g_thread_init(NULL); #endif #if !(GLIB_CHECK_VERSION(2,36,0)) g_type_init(); #endif signals(); resources(); sdp_init(); dtls_init(); ice_init(); crypto_init_main(); interfaces_init(&rtpe_config.interfaces); iptables_init(); control_ng_init(); if (call_interfaces_init()) abort(); statistics_init(); codeclib_init(0); media_player_init(); }
static void init_everything() { struct timespec ts; socket_init(); log_init(); clock_gettime(CLOCK_REALTIME, &ts); srandom(ts.tv_sec ^ ts.tv_nsec); SSL_library_init(); SSL_load_error_strings(); make_OpenSSL_thread_safe(); #if !GLIB_CHECK_VERSION(2,32,0) g_thread_init(NULL); #endif if (!_log_stderr) openlog("rtpengine", LOG_PID | LOG_NDELAY, _log_facility); signals(); resources(); sdp_init(); dtls_init(); ice_init(); interfaces_init(&interfaces); }
/* * Use global *tty_tmp and term_parent */ int main( int argc, char **argv ) { struct cl_args *cl_args; struct term_node *tty_node = NULL; pid_t pid; pid_t parent_id; #if defined(HAVE_PTHREAD_SETCONCURRENCY) && !defined(LINUX) int concurrent; #endif handle_signals_parent(); tcgetattr(0, &term_parent); parent_id = getpid(); if ((pid = fork()) < 0) { exit(1); } else { if (pid != 0) { wait(NULL); tcsetattr(0, TCSANOW, &term_parent); exit(0); } } fatal_error = 4; /* Disable all signals while initializing data...*/ handle_signals(); setvbuf(stdout, NULL, _IONBF, 0); tty_tmp = (struct term_tty *)calloc(1,sizeof(struct term_tty)); if (tty_tmp == NULL) { printf("Out of memory on calloc tty_tmp\n"); clean_exit(); } tty_tmp->term = (struct termios *)calloc(1,sizeof(struct termios)); if (tty_tmp->term == NULL) { printf("Out of memory on calloc tty_tmp->term\n"); clean_exit(); } /* default values */ tty_tmp->interactive = 0; tty_tmp->gtk = 0; tty_tmp->attack = -1; tty_tmp->mac_spoofing = -1; tty_tmp->splash = -1; strncpy(tty_tmp->username, VTY_USER, MAX_USERNAME); strncpy(tty_tmp->password, VTY_PASS, MAX_PASSWORD); strncpy(tty_tmp->e_password, VTY_ENABLE, MAX_PASSWORD); tty_tmp->port = VTY_PORT; tty_tmp->ip_filter = NULL; #ifdef HAVE_GTK tty_tmp->buffer_log = NULL; #endif cl_args = (struct cl_args *)calloc(1,sizeof(struct cl_args)); if (cl_args == NULL) { printf("Out of memory on calloc cl_args\n"); clean_exit(); } if ( argc == 1 ) { printf("GNU %s %s %s\n", PACKAGE, VERSION, "$Date: 2006/03/23 08:40:14 $"); printf("Try '%s -h' to display the help.\n",PACKAGE); clean_exit(); } if (getuid() != 0) { printf("You must be root to run %s %s\n", PACKAGE, VERSION); clean_exit(); } if (term_init() < 0) g00dbye(); /* Register all the protocols */ protocol_init(); cl_args->proto_index = -1; if (parser_initial(tty_tmp, cl_args, argc, argv) < 0) { clean_exit(); } init_log(); #if defined(HAVE_PTHREAD_SETCONCURRENCY) && !defined(LINUX) /* concurrent = pthread_getconcurrency();*/ concurrent = 15;/*(MAX_TERMS*MAX_PROTOCOLS*MAX_THREAD_ATTACK*2)+3;*/ if (pthread_setconcurrency(concurrent) != 0) { thread_error("init pthread_setconcurrency()",errno); g00dbye(); } #endif if (interfaces_init(&terms->pcap_listen_th) < 0 ) g00dbye(); /* Establish TERM signal handler...*/ posix_signal(SIGTERM, final); #ifdef HAVE_REMOTE_ADMIN if (tty_tmp->daemonize) { if (admin_init(tty_tmp) < 0) g00dbye(); } #endif if (thread_create(&terms->uptime_th.id, &th_uptime, (void *)NULL) < 0) g00dbye(); /* Command line and ncurses cannot be choosed simultaneously...*/ if ((!tty_tmp->interactive) && (!tty_tmp->gtk) && (cl_args->proto_index != -1)) { terms->work_state = INITIAL; tty_node = term_type[TERM_TTY].list; if (thread_create(&tty_node[0].thread.id, &th_tty_peer, (void *)cl_args) < 0) g00dbye(); while(terms->work_state != STOPPED) thread_usleep(100000); } #ifdef HAS_CURSES if (tty_tmp->interactive) { terms->work_state = INITIAL; if (thread_create(&terms->gui_th.id, &ncurses_gui, NULL) < 0 ) g00dbye(); /* Wait until the ncurses GUI is over */ while(terms->work_state != STOPPED) thread_usleep(100000); } else { #endif #ifdef HAVE_GTK if (tty_tmp->gtk) { terms->work_state = INITIAL; if (thread_create(&terms->gui_gtk_th.id, >k_gui, NULL) < 0 ) g00dbye(); /* Wait until the GTK GUI is over */ while(terms->work_state != STOPPED) thread_usleep(100000); } #endif #ifdef HAS_CURSES } #endif #ifdef HAVE_REMOTE_ADMIN if (tty_tmp->daemonize) { /* Ok, now that console (ncurses) is finished * we can become a true daemon... */ become_daemon(parent_id); /* Wait until some important thread exits due to fatal_error...*/ while (fatal_error == 4) thread_usleep(100000); } #endif g00dbye(); exit(1); }